Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool I/O functions are added. #115

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ build
.idea/
.history/
*.pyc
dist/*.egg
urx.egg-info/dependency_links.txt
urx.egg-info/PKG-INFO
urx.egg-info/requires.txt
urx.egg-info/SOURCES.txt
urx.egg-info/top_level.txt
5 changes: 4 additions & 1 deletion urx/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ def getl(self, wait=False, _log=True):
return current transformation from tcp to current csys
"""
t = self.get_pose(wait, _log)
return t.pose_vector.tolist()
try:
return t.pose_vector.array.tolist()
except:
return t.pose_vector.tolist()

def set_gravity(self, vector):
if isinstance(vector, m3d.Vector):
Expand Down
36 changes: 36 additions & 0 deletions urx/urrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,25 @@ def set_tool_voltage(self, val):
"""
set voltage to be delivered to the tool, val is 0, 12 or 24
"""
assert(val in [0, 12, 24])
prog = "set_tool_voltage(%s)" % (val)
self.send_program(prog)

def set_tool_digital_out(self, input_id, signal_level):
"""
set tool digital output
"""
assert(input_id in [0, 1])
prog = "set_tool_digital_out(%s, %s)" % (input_id, signal_level)
self.send_program(prog)

def set_tool_communication(self, enabled=True, baud_rate=9600, parity=0, stop_bits=1, rx_idle_chars=1.0, tx_idle_chars=3.5):
"""
set tool RS485 communication protocol.
"""
prog = "set_tool_communication(%s, %s, %s, %s, %s, %s)" % (enabled, baud_rate, parity, stop_bits, rx_idle_chars, tx_idle_chars)
self.send_program(prog)

def _wait_for_move(self, target, threshold=None, timeout=5, joints=False):
"""
wait for a move to complete. Unfortunately there is no good way to know when a move has finished
Expand Down Expand Up @@ -338,18 +354,30 @@ def movel(self, tpose, acc=0.01, vel=0.01, wait=True, relative=False, threshold=
"""
Send a movel command to the robot. See URScript documentation.
"""
try:
tpose = tpose.array
except:
pass
return self.movex("movel", tpose, acc=acc, vel=vel, wait=wait, relative=relative, threshold=threshold)

def movep(self, tpose, acc=0.01, vel=0.01, wait=True, relative=False, threshold=None):
"""
Send a movep command to the robot. See URScript documentation.
"""
try:
tpose = tpose.array
except:
pass
return self.movex("movep", tpose, acc=acc, vel=vel, wait=wait, relative=relative, threshold=threshold)

def servoc(self, tpose, acc=0.01, vel=0.01, wait=True, relative=False, threshold=None):
"""
Send a servoc command to the robot. See URScript documentation.
"""
try:
tpose = tpose.array
except:
pass
return self.movex("servoc", tpose, acc=acc, vel=vel, wait=wait, relative=relative, threshold=threshold)

def servoj(self, tjoints, acc=0.01, vel=0.01, t=0.1, lookahead_time=0.2, gain=100, wait=True, relative=False, threshold=None):
Expand All @@ -375,6 +403,10 @@ def _format_servo(self, command, tjoints, acc=0.01, vel=0.01, t=0.1, lookahead_t
return "{}({}[{},{},{},{},{},{}], a={}, v={}, t={}, lookahead_time={}, gain={})".format(command, prefix, *tjoints)

def _format_move(self, command, tpose, acc, vel, radius=0, prefix=""):
try:
tpose = tpose.array
except:
pass
tpose = [round(i, self.max_float_length) for i in tpose]
tpose.append(acc)
tpose.append(vel)
Expand All @@ -386,6 +418,10 @@ def movex(self, command, tpose, acc=0.01, vel=0.01, wait=True, relative=False, t
Send a move command to the robot. since UR robotene have several methods this one
sends whatever is defined in 'command' string
"""
try:
tpose = tpose.array
except:
pass
if relative:
l = self.getl()
tpose = [v + l[i] for i, v in enumerate(tpose)]
Expand Down
24 changes: 24 additions & 0 deletions urx/urscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ def _socket_send_byte(self, byte, socket_name):
msg = "socket_send_byte(\"{}\",\"{}\")".format(str(byte), socket_name) # noqa
self.add_line_to_program(msg)
self._sync()

def _get_tool_digital_in(self, input_id):
assert(input_id in [0, 1])
msg = "get_standard_digital_in({})".format(input_id)
self.add_line_to_program(msg)

def _set_tool_digital_out(self, input_id, signal_level):
assert(input_id in [0, 1])
assert(signal_level in [True, False])
msg = "set_standard_digital_out({}, {})".format(input_id, signal_level)
self.add_line_to_program(msg)

def _set_tool_communication(self, enabled=True, baud_rate=9600, parity=0, stop_bits=1, rx_idle_chars=1.5, tx_idle_chars=3.5):
# stop_bits:Thenumberofstopbits(int).Validvalues:1,2.
# rx_idle_chars:AmountofcharstheRXunitinthetoolshouldwaitbeforemarkingamessage asover/sendingittothePC(float).Validvalues:min=1.0max=40.0.
# tx_idle_chars:
# set_tool_communication(True,115200,1,2,1.0,3.5)
# :9600,19200,38400,57600,115200, 1000000,2000000,5000000
assert(baud_rate in [9600,19200,38400,57600,115200, 1000000,2000000,5000000])
assert(parity in [0, 1, 2])
assert(stop_bits in [1, 2])
assert(enabled in [True, False])
msg = "set_tool_communication({}, {}, {}, {}, {}, {})".format(enabled, baud_rate, parity, stop_bits, rx_idle_chars, tx_idle_chars)
self.add_line_to_program(msg)

def _sync(self):
msg = "sync()"
Expand Down