deep cleanup, probably broken
This commit is contained in:
		| @@ -297,7 +297,6 @@ class SecondaryMonitor(Thread): | |||||||
|         with self._dictLock: |         with self._dictLock: | ||||||
|             return self._dict.copy() |             return self._dict.copy() | ||||||
|  |  | ||||||
|  |  | ||||||
|     def getJointData(self, wait=False): |     def getJointData(self, wait=False): | ||||||
|         if wait: |         if wait: | ||||||
|             self.wait() |             self.wait() | ||||||
|   | |||||||
							
								
								
									
										180
									
								
								urx/urx.py
									
									
									
									
									
								
							
							
						
						
									
										180
									
								
								urx/urx.py
									
									
									
									
									
								
							| @@ -40,7 +40,7 @@ class URRobot(object): | |||||||
|     programs are send to port 3002 |     programs are send to port 3002 | ||||||
|     data is read from secondary interface(10Hz?) and real-time interface(125Hz) (called Matlab interface in documentation) |     data is read from secondary interface(10Hz?) and real-time interface(125Hz) (called Matlab interface in documentation) | ||||||
|     Since parsing the RT interface uses som CPU, and does not support all robots versions, it is disabled by default |     Since parsing the RT interface uses som CPU, and does not support all robots versions, it is disabled by default | ||||||
|     The RT interfaces is only used for the getForce related methods |     The RT interfaces is only used for the get_force related methods | ||||||
|     Rmq: A program sent to the robot i executed immendiatly and any running program is stopped |     Rmq: A program sent to the robot i executed immendiatly and any running program is stopped | ||||||
|     """ |     """ | ||||||
|     def __init__(self, host, useRTInterface=False, logLevel=logging.WARN): |     def __init__(self, host, useRTInterface=False, logLevel=logging.WARN): | ||||||
| @@ -75,28 +75,28 @@ class URRobot(object): | |||||||
|     def __str__(self): |     def __str__(self): | ||||||
|         return self.__repr__() |         return self.__repr__() | ||||||
|  |  | ||||||
|     def isRunning(self): # legacy |     def is_running(self): # legacy | ||||||
|         return self.secmon.running |         return self.secmon.running | ||||||
|  |  | ||||||
|     def isProgramRunning(self): |     def is_program_running(self): | ||||||
|         return self.secmon.isProgramRunning() |         return self.secmon.is_program_running() | ||||||
|  |  | ||||||
|     def sendProgram(self, prog): |     def send_program(self, prog): | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def getTCPForce(self, wait=True): |     def get_tcp_force(self, wait=True): | ||||||
|         """ |         """ | ||||||
|         return measured force in TCP |         return measured force in TCP | ||||||
|         if wait==True, waits for next packet before returning |         if wait==True, waits for next packet before returning | ||||||
|         """ |         """ | ||||||
|         return self.rtmon.getTCFForce(wait) |         return self.rtmon.getTCFForce(wait) | ||||||
|  |  | ||||||
|     def getForce(self, wait=True): |     def get_force(self, wait=True): | ||||||
|         """ |         """ | ||||||
|         length of force vector returned by getTCPForce |         length of force vector returned by get_tcp_force | ||||||
|         if wait==True, waits for next packet before returning |         if wait==True, waits for next packet before returning | ||||||
|         """ |         """ | ||||||
|         tcpf = self.getTCPForce( wait) |         tcpf = self.get_tcp_force( wait) | ||||||
|         force = 0 |         force = 0 | ||||||
|         for i in tcpf: |         for i in tcpf: | ||||||
|             force += i**2 |             force += i**2 | ||||||
| @@ -108,7 +108,7 @@ class URRobot(object): | |||||||
|         """ |         """ | ||||||
|         self.movej(self.start_pose) |         self.movej(self.start_pose) | ||||||
|  |  | ||||||
|     def setTcp(self, x=0, y=0, z=0, a=0, b=0, c=0): |     def set_tcp(self, x=0, y=0, z=0, a=0, b=0, c=0): | ||||||
|         """ |         """ | ||||||
|         """ |         """ | ||||||
|         if type(x) in (list, tuple): |         if type(x) in (list, tuple): | ||||||
| @@ -119,30 +119,30 @@ class URRobot(object): | |||||||
|         else: |         else: | ||||||
|             arg = (x, y, z, a, b, c) |             arg = (x, y, z, a, b, c) | ||||||
|         prog = "set_tcp(p[%s, %s, %s, %s, %s, %s])" % arg |         prog = "set_tcp(p[%s, %s, %s, %s, %s, %s])" % arg | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def setPayload(self, weight): |     def set_payload(self, weight): | ||||||
|         """ |         """ | ||||||
|         set payload in Kg |         set payload in Kg | ||||||
|         """ |         """ | ||||||
|         prog = "set_payload(%s)" % weight  |         prog = "set_payload(%s)" % weight  | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def setGravity(self, vector): |     def set_gravity(self, vector): | ||||||
|         """ |         """ | ||||||
|         set direction of gravity |         set direction of gravity | ||||||
|         """ |         """ | ||||||
|         prog = "set_gravity(%s)" % list(vector)  |         prog = "set_gravity(%s)" % list(vector)  | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def sendMessage(self, msg): |     def send_message(self, msg): | ||||||
|         """ |         """ | ||||||
|         send message to the GUI log tab on the robot controller |         send message to the GUI log tab on the robot controller | ||||||
|         """ |         """ | ||||||
|         prog = "textmsg(%s)" % msg  |         prog = "textmsg(%s)" % msg  | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def setDigitalOut(self, output, val): |     def set_digital_out(self, output, val): | ||||||
|         """ |         """ | ||||||
|         set digital output. val is a bool |         set digital output. val is a bool | ||||||
|         """ |         """ | ||||||
| @@ -150,9 +150,9 @@ class URRobot(object): | |||||||
|             val = "True" |             val = "True" | ||||||
|         else: |         else: | ||||||
|             val = "False" |             val = "False" | ||||||
|         self.secmon.sendProgram('digital_out[%s]=%s' % (output, val)) |         self.secmon.send_program('digital_out[%s]=%s' % (output, val)) | ||||||
|  |  | ||||||
|     def getAnalogInputs(self): |     def get_analog_inputs(self): | ||||||
|         """ |         """ | ||||||
|         get analog input  |         get analog input  | ||||||
|         """ |         """ | ||||||
| @@ -160,21 +160,21 @@ class URRobot(object): | |||||||
|         return data["MasterBoardData"]["analogInput0"], data["MasterBoardData"]["analogInput1"] |         return data["MasterBoardData"]["analogInput0"], data["MasterBoardData"]["analogInput1"] | ||||||
|  |  | ||||||
|  |  | ||||||
|     def getAnalogInput(self, nb): |     def get_analog_in(self, nb): | ||||||
|         """ |         """ | ||||||
|         get analog input  |         get analog input  | ||||||
|         """ |         """ | ||||||
|         data = self.secmon.getAllData() |         data = self.secmon.getAllData() | ||||||
|         return data["MasterBoardData"]["analogInput" + str(nb)] |         return data["MasterBoardData"]["analogInput" + str(nb)] | ||||||
|  |  | ||||||
|     def getDigitalInputBits(self): |     def get_digital_inBits(self): | ||||||
|         """ |         """ | ||||||
|         get digital output |         get digital output | ||||||
|         """ |         """ | ||||||
|         data = self.secmon.getAllData() |         data = self.secmon.getAllData() | ||||||
|         return data["MasterBoardData"]["digitalInputBits"] |         return data["MasterBoardData"]["digitalInputBits"] | ||||||
|  |  | ||||||
|     def getDigitalInput(self, nb): |     def get_digital_in(self, nb): | ||||||
|         """ |         """ | ||||||
|         get digital output |         get digital output | ||||||
|         """ |         """ | ||||||
| @@ -203,20 +203,14 @@ class URRobot(object): | |||||||
|         set analog output, val is a float |         set analog output, val is a float | ||||||
|         """ |         """ | ||||||
|         prog = "set_analog_output(%s, %s)" % (output, val)  |         prog = "set_analog_output(%s, %s)" % (output, val)  | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def setToolVoltage(self, val): |     def setToolVoltage(self, val): | ||||||
|         """ |         """ | ||||||
|         set voltage to be delivered to the tool, val is 0, 12 or 24 |         set voltage to be delivered to the tool, val is 0, 12 or 24 | ||||||
|         """ |         """ | ||||||
|         prog = "set_tool_voltage(%s)" % (val)  |         prog = "set_tool_voltage(%s)" % (val)  | ||||||
|         self.secmon.sendProgram(prog) |         self.secmon.send_program(prog) | ||||||
|  |  | ||||||
|     def movejrel(self, joints, acc=0.1, vel=0.05, wait=True): |  | ||||||
|         """ |  | ||||||
|         relative joint move |  | ||||||
|         """ |  | ||||||
|         self.movej(joints, acc, vel, wait, relative=True) |  | ||||||
|  |  | ||||||
|     def movej(self, joints, acc=0.1, vel=0.05, wait=True, relative=False): |     def movej(self, joints, acc=0.1, vel=0.05, wait=True, relative=False): | ||||||
|         """ |         """ | ||||||
| @@ -226,17 +220,26 @@ class URRobot(object): | |||||||
|             l = self.getj() |             l = self.getj() | ||||||
|             joints = [v + l[i] for i, v in enumerate(joints)] |             joints = [v + l[i] for i, v in enumerate(joints)] | ||||||
|         prog = "movej(%s, a=%s, v=%s)" % (list(joints), acc, vel) |         prog = "movej(%s, a=%s, v=%s)" % (list(joints), acc, vel) | ||||||
|         self.sendProgram(prog) |         self.send_program(prog) | ||||||
|         if not wait: |         if not wait: | ||||||
|             return None |             return None | ||||||
|         else: |         else: | ||||||
|             time.sleep(0.05)# it is important to sleep since robot may takes a while to get into running state |             self.wait_for_move() | ||||||
|             while True: |             return self.getj() | ||||||
|                 if not self.isRunning(): |  | ||||||
|                     raise RobotException("Robot stopped") |     def wait_for_move(self): | ||||||
|                 currentjoints = self.getj(wait=True) |         time.sleep(0.05)# it is important to sleep since robot may takes a while to get into running state | ||||||
|                 if self._eq(currentjoints, joints) and not self.secmon.isProgramRunning():  |         while True: | ||||||
|                     return currentjoints |             if not self.is_running(): | ||||||
|  |                 raise RobotException("Robot stopped") | ||||||
|  |             jts = self.secmon.getJointData(wait=True) | ||||||
|  |             finished = True | ||||||
|  |             for i in range(0, 6): | ||||||
|  |                 if abs(jts["q_actual%s"%i] - jts["q_targets%s"%i]) > self.radialEpsilon: | ||||||
|  |                     finished = False | ||||||
|  |                     break | ||||||
|  |                 if finished and not self.secmon.is_program_running(): | ||||||
|  |                     return | ||||||
|   |   | ||||||
|     def getj(self, wait=False): |     def getj(self, wait=False): | ||||||
|         """ |         """ | ||||||
| @@ -245,13 +248,6 @@ class URRobot(object): | |||||||
|         jts = self.secmon.getJointData(wait) |         jts = self.secmon.getJointData(wait) | ||||||
|         return [jts["q_actual0"], jts["q_actual1"], jts["q_actual2"], jts["q_actual3"], jts["q_actual4"], jts["q_actual5"]] |         return [jts["q_actual0"], jts["q_actual1"], jts["q_actual2"], jts["q_actual3"], jts["q_actual4"], jts["q_actual5"]] | ||||||
|  |  | ||||||
|      |  | ||||||
|     def movelrel(self, tpose, acc=0.01, vel=0.01, wait=True): |  | ||||||
|         """ |  | ||||||
|         relative linear move  |  | ||||||
|         """ |  | ||||||
|         return self.movel(tpose, acc, vel, wait, relative=True) |  | ||||||
|  |  | ||||||
|     def movel(self, tpose, acc=0.01, vel=0.01, wait=True, relative=False): |     def movel(self, tpose, acc=0.01, vel=0.01, wait=True, relative=False): | ||||||
|         """ |         """ | ||||||
|         linear move  |         linear move  | ||||||
| @@ -261,17 +257,12 @@ class URRobot(object): | |||||||
|             tpose = [v + l[i] for i, v in enumerate(tpose)] |             tpose = [v + l[i] for i, v in enumerate(tpose)] | ||||||
|         tpose = [round(i, 2) for i in tpose] |         tpose = [round(i, 2) for i in tpose] | ||||||
|         prog = "movel(p%s, a=%s, v=%s)" % (tpose, acc, vel) |         prog = "movel(p%s, a=%s, v=%s)" % (tpose, acc, vel) | ||||||
|         self.sendProgram(prog) |         self.send_program(prog) | ||||||
|         if not wait: |         if not wait: | ||||||
|             return None |             return None | ||||||
|         else: |         else: | ||||||
|             time.sleep(0.05)# it is important to sleep since robot may takes a while to get into running state |             self.wait_for_move() | ||||||
|             while True: |             return self.getl() | ||||||
|                 if not self.isRunning(): |  | ||||||
|                     raise RobotException("Robot stopped") |  | ||||||
|                 pose = self.getl(wait=True) |  | ||||||
|                 if self._eqpose(pose, tpose) and not self.secmon.isProgramRunning():  |  | ||||||
|                     return pose |  | ||||||
|  |  | ||||||
|     def getl(self, wait=False): |     def getl(self, wait=False): | ||||||
|         """ |         """ | ||||||
| @@ -292,10 +283,10 @@ class URRobot(object): | |||||||
|         raise NotImplementedError |         raise NotImplementedError | ||||||
|      |      | ||||||
|     def stopl(self, acc = 0.5): |     def stopl(self, acc = 0.5): | ||||||
|         self.sendProgram("stopl(%s)" % acc) |         self.send_program("stopl(%s)" % acc) | ||||||
|  |  | ||||||
|     def stopj(self, acc = 1.5): |     def stopj(self, acc = 1.5): | ||||||
|         self.sendProgram("stopj(%s)" % acc) |         self.send_program("stopj(%s)" % acc) | ||||||
|  |  | ||||||
|     def stop(self): |     def stop(self): | ||||||
|         self.stopj() |         self.stopj() | ||||||
| @@ -333,31 +324,26 @@ class URRobot(object): | |||||||
|  |  | ||||||
|     def set_freedrive(self, val): |     def set_freedrive(self, val): | ||||||
|         if val: |         if val: | ||||||
|             self.sendProgram("set robotmode freedrive") |             self.send_program("set robotmode freedrive") | ||||||
|         else: |         else: | ||||||
|             self.sendProgram("set robotmode run") |             self.send_program("set robotmode run") | ||||||
|  |  | ||||||
|     def set_simulation(self, val): |     def set_simulation(self, val): | ||||||
|         if val: |         if val: | ||||||
|             self.sendProgram("set sim") |             self.send_program("set sim") | ||||||
|         else: |         else: | ||||||
|             self.sendProgram("set real") |             self.send_program("set real") | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class Robot(object): | class Robot(URRobot): | ||||||
|     """ |     """ | ||||||
|     Generic Python interface to an industrial robot. |     Generic Python interface to an industrial robot. | ||||||
|     Compare to the URRobot class, this class adds the possibilty to work directly with matrices |     Compare to the URRobot class, this class adds the possibilty to work directly with matrices | ||||||
|     and includes support for calibrating the robot coordinate system |     and includes support for calibrating the robot coordinate system | ||||||
|     and style portet to PEP 8  |  | ||||||
|     """ |     """ | ||||||
|     def __init__(self, host, useRTInterface=False, logLevel = logging.WARN): |     def __init__(self, host, useRTInterface=False, logLevel = logging.WARN): | ||||||
|         self.robot = URRobot(host, useRTInterface, logLevel=logLevel) |         URRobot.__init__(self, host, useRTInterface, logLevel=logLevel) | ||||||
|         self.logger = logging.getLogger(self.__class__.__name__) |  | ||||||
|         if len(logging.root.handlers) == 0: #dirty hack |  | ||||||
|             logging.basicConfig() |  | ||||||
|         self.logger.setLevel(logLevel) |  | ||||||
|         self.default_linear_acceleration = 0.01 |         self.default_linear_acceleration = 0.01 | ||||||
|         self.default_linear_velocity = 0.01 |         self.default_linear_velocity = 0.01 | ||||||
|  |  | ||||||
| @@ -365,10 +351,10 @@ class Robot(object): | |||||||
|         self.inverse = self.calibration.inverse() |         self.inverse = self.calibration.inverse() | ||||||
|         self.tracker = None |         self.tracker = None | ||||||
|  |  | ||||||
|     def set_tcp(self, tcp): |     def set_tcp(self, x=0, y=0, z=0, a=0, b=0, c=0): | ||||||
|         if type(tcp) == math3d.Transform: |         if type(x) == math3d.Transform: | ||||||
|             tcp = tcp.pose_vector |             x = x.pose_vector | ||||||
|         self.robot.setTcp(tcp) |         URRobot.set_tcp(self, x, y, z, a, b, c) | ||||||
|  |  | ||||||
|     def set_calibration_matrix(self, matrix): |     def set_calibration_matrix(self, matrix): | ||||||
|         self.calibration = matrix |         self.calibration = matrix | ||||||
| @@ -393,16 +379,13 @@ class Robot(object): | |||||||
|         trans = math3d.Transform(self.get_orientation(), math3d.Vector(vect)) |         trans = math3d.Transform(self.get_orientation(), math3d.Vector(vect)) | ||||||
|         return self.apply_transform(trans, acc, vel, wait) |         return self.apply_transform(trans, acc, vel, wait) | ||||||
|  |  | ||||||
|     def stop(self): |  | ||||||
|         self.robot.stop() |  | ||||||
|  |  | ||||||
|     def apply_transform(self, trans, acc=None, vel=None, wait=True): |     def apply_transform(self, trans, acc=None, vel=None, wait=True): | ||||||
|         if not acc:  |         if not acc:  | ||||||
|             acc = self.default_linear_acceleration |             acc = self.default_linear_acceleration | ||||||
|         if not vel:  |         if not vel:  | ||||||
|             vel = self.default_linear_velocity |             vel = self.default_linear_velocity | ||||||
|         t = self.calibration * trans |         t = self.calibration * trans | ||||||
|         pose = self.robot.movel(t.pose_vector, acc, vel, wait) |         pose = URRobot.movel(self, t.pose_vector, acc, vel, wait) | ||||||
|         if pose: #movel does not return anything when wait is False |         if pose: #movel does not return anything when wait is False | ||||||
|             return self.inverse * math3d.Transform(pose) |             return self.inverse * math3d.Transform(pose) | ||||||
|  |  | ||||||
| @@ -421,7 +404,7 @@ class Robot(object): | |||||||
|         return self.apply_transform(pose * trans, acc, vel, wait) |         return self.apply_transform(pose * trans, acc, vel, wait) | ||||||
|  |  | ||||||
|     def get_transform(self, wait=False): |     def get_transform(self, wait=False): | ||||||
|         pose = self.robot.getl(wait) |         pose = URRobot.getl(self, wait) | ||||||
|         trans = self.inverse * math3d.Transform(pose)  |         trans = self.inverse * math3d.Transform(pose)  | ||||||
|         return trans |         return trans | ||||||
|  |  | ||||||
| @@ -454,55 +437,16 @@ class Robot(object): | |||||||
|         t = self.get_transform(wait) |         t = self.get_transform(wait) | ||||||
|         return t.pose_vector |         return t.pose_vector | ||||||
|  |  | ||||||
|     def is_running(self): |  | ||||||
|         return self.robot.isRunning() |  | ||||||
|  |  | ||||||
|     def is_program_running(self): |  | ||||||
|         return self.robot.isProgramRunning() |  | ||||||
|  |  | ||||||
|     def set_payload(self, weight): |  | ||||||
|         return self.robot.setPayload(weight) |  | ||||||
|  |  | ||||||
|     def set_gravity(self, vector): |     def set_gravity(self, vector): | ||||||
|         if type(vector) == math3d.Vector: |         if type(vector) == math3d.Vector: | ||||||
|             vector = vector.list |             vector = vector.list | ||||||
|         return self.robot.setGravity(vector) |         return URRobot.set_gravity(self, vector) | ||||||
|  |  | ||||||
|     def set_digital_out(self, output, val): |  | ||||||
|         return self.robot.setDigitalOut(output, val) |  | ||||||
|  |  | ||||||
|     def get_digital_out(self, nb): |  | ||||||
|         self.robot.getDigitalOutput(nb) |  | ||||||
|  |  | ||||||
|     def get_digital_in(self, nb): |  | ||||||
|         return self.robot.getDigitalInput(nb) |  | ||||||
|  |  | ||||||
|     def get_analog_in(self, nb): |  | ||||||
|         return self.robot.getAnalogInput(nb) |  | ||||||
|  |  | ||||||
|     def set_freedrive(self, val): |  | ||||||
|         self.robot.set_freedrive(val) |  | ||||||
|  |  | ||||||
|     def set_simulation(self, val): |  | ||||||
|         self.robot.set_simulation(val) |  | ||||||
|   |  | ||||||
|     def movej(self, joints, acc=0.1, vel=0.05, wait=True, relative=False): |  | ||||||
|         """ |  | ||||||
|         wrapper around the movej command in URRobot |  | ||||||
|         """ |  | ||||||
|         self.robot.movej(joints, acc, vel, wait, relative) |  | ||||||
|  |  | ||||||
|     def getj(self, wait=False): |  | ||||||
|         return self.robot.getj(wait) |  | ||||||
|  |  | ||||||
|     def cleanup(self): |  | ||||||
|         self.robot.cleanup() |  | ||||||
|  |  | ||||||
|     def get_tracker(self): |     def get_tracker(self): | ||||||
|         """ |         """ | ||||||
|         return an object able to track robot move for logging |         return an object able to track robot move for logging | ||||||
|         """ |         """ | ||||||
|         t = tracker.Tracker(self.robot.host) |         t = tracker.Tracker(self.host) | ||||||
|         t.set_calibration_matrix(self.calibration) |         t.set_calibration_matrix(self.calibration) | ||||||
|         return t |         return t | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user