diff --git a/.gitignore b/.gitignore index ef5a5a9..ff7ce8d 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/urx/robot.py b/urx/robot.py index 160c03a..2e241a6 100644 --- a/urx/robot.py +++ b/urx/robot.py @@ -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): diff --git a/urx/urrobot.py b/urx/urrobot.py index 3086fe7..9124322 100644 --- a/urx/urrobot.py +++ b/urx/urrobot.py @@ -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 @@ -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): @@ -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) @@ -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)] diff --git a/urx/urscript.py b/urx/urscript.py index 2382cb3..40b40ad 100755 --- a/urx/urscript.py +++ b/urx/urscript.py @@ -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()"