|
a |
|
b/URBasic/robotModel.py |
|
|
1 |
''' |
|
|
2 |
Python 3.x library to control an UR robot through its TCP/IP interfaces |
|
|
3 |
Copyright (C) 2017 Martin Huus Bjerge, Rope Robotics ApS, Denmark |
|
|
4 |
|
|
|
5 |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
|
|
6 |
and associated documentation files (the "Software"), to deal in the Software without restriction, |
|
|
7 |
including without limitation the rights to use, copy, modify, merge, publish, distribute, |
|
|
8 |
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software |
|
|
9 |
is furnished to do so, subject to the following conditions: |
|
|
10 |
|
|
|
11 |
The above copyright notice and this permission notice shall be included in all copies |
|
|
12 |
or substantial portions of the Software. |
|
|
13 |
|
|
|
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
|
|
15 |
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
|
|
16 |
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL "Rope Robotics ApS" BE LIABLE FOR ANY CLAIM, |
|
|
17 |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
|
18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|
19 |
|
|
|
20 |
Except as contained in this notice, the name of "Rope Robotics ApS" shall not be used |
|
|
21 |
in advertising or otherwise to promote the sale, use or other dealings in this Software |
|
|
22 |
without prior written authorization from "Rope Robotics ApS". |
|
|
23 |
''' |
|
|
24 |
__author__ = "Martin Huus Bjerge" |
|
|
25 |
__copyright__ = "Copyright 2017, Rope Robotics ApS, Denmark" |
|
|
26 |
__license__ = "MIT License" |
|
|
27 |
|
|
|
28 |
import URBasic |
|
|
29 |
|
|
|
30 |
class RobotModel(object): |
|
|
31 |
''' |
|
|
32 |
Data class holding all data and states |
|
|
33 |
|
|
|
34 |
Input parameters: |
|
|
35 |
|
|
|
36 |
''' |
|
|
37 |
|
|
|
38 |
|
|
|
39 |
def __init__(self, log_path="ur_log/", log_config_path=None): |
|
|
40 |
''' |
|
|
41 |
Constructor see class description for more info. |
|
|
42 |
''' |
|
|
43 |
logger = URBasic.dataLogging.DataLogging(path=log_path, config=log_config_path) |
|
|
44 |
name = logger.AddEventLogging(__name__) |
|
|
45 |
self.__logger = logger.__dict__[name] |
|
|
46 |
self.__logger.info('Init done') |
|
|
47 |
|
|
|
48 |
#Universal Robot Model content |
|
|
49 |
self.password = None |
|
|
50 |
self.ipAddress = None |
|
|
51 |
|
|
|
52 |
self.dataDir = {'timestamp':None, |
|
|
53 |
'target_q':None, |
|
|
54 |
'target_q':None, |
|
|
55 |
'target_qd':None, |
|
|
56 |
'target_qdd':None, |
|
|
57 |
'target_current':None, |
|
|
58 |
'target_moment':None, |
|
|
59 |
'actual_q':None, |
|
|
60 |
'actual_qd':None, |
|
|
61 |
'actual_current':None, |
|
|
62 |
'joint_control_output':None, |
|
|
63 |
'actual_TCP_pose':None, |
|
|
64 |
'actual_TCP_speed':None, |
|
|
65 |
'actual_TCP_force':None, |
|
|
66 |
'target_TCP_pose':None, |
|
|
67 |
'target_TCP_speed':None, |
|
|
68 |
'actual_digital_input_bits':None, |
|
|
69 |
'joint_temperatures':None, |
|
|
70 |
'actual_execution_time':None, |
|
|
71 |
'robot_mode':None, |
|
|
72 |
'joint_mode':None, |
|
|
73 |
'safety_mode':None, |
|
|
74 |
'actual_tool_accelerometer':None, |
|
|
75 |
'speed_scaling':None, |
|
|
76 |
'target_speed_fraction':None, |
|
|
77 |
'actual_momentum':None, |
|
|
78 |
'actual_main_voltage':None, |
|
|
79 |
'actual_robot_voltage':None, |
|
|
80 |
'actual_robot_current':None, |
|
|
81 |
'actual_joint_voltage':None, |
|
|
82 |
'actual_digital_output_bits':None, |
|
|
83 |
'runtime_state':None, |
|
|
84 |
'robot_status_bits':None, |
|
|
85 |
'safety_status_bits':None, |
|
|
86 |
'analog_io_types':None, |
|
|
87 |
'standard_analog_input0':None, |
|
|
88 |
'standard_analog_input1':None, |
|
|
89 |
'standard_analog_output0':None, |
|
|
90 |
'standard_analog_output1':None, |
|
|
91 |
'io_current':None, |
|
|
92 |
'euromap67_input_bits':None, |
|
|
93 |
'euromap67_output_bits':None, |
|
|
94 |
'euromap67_24V_voltage':None, |
|
|
95 |
'euromap67_24V_current':None, |
|
|
96 |
'tool_mode':None, |
|
|
97 |
'tool_analog_input_types':None, |
|
|
98 |
'tool_analog_input0':None, |
|
|
99 |
'tool_analog_input1':None, |
|
|
100 |
'tool_output_voltage':None, |
|
|
101 |
'tool_output_current':None, |
|
|
102 |
'tcp_force_scalar':None, |
|
|
103 |
'output_bit_registers0_to_31':None, |
|
|
104 |
'output_bit_registers32_to_63':None, |
|
|
105 |
'output_int_register_0':None, |
|
|
106 |
'output_int_register_1':None, |
|
|
107 |
'output_int_register_2':None, |
|
|
108 |
'output_int_register_3':None, |
|
|
109 |
'output_int_register_4':None, |
|
|
110 |
'output_int_register_5':None, |
|
|
111 |
'output_int_register_6':None, |
|
|
112 |
'output_int_register_7':None, |
|
|
113 |
'output_int_register_8':None, |
|
|
114 |
'output_int_register_9':None, |
|
|
115 |
'output_int_register_10':None, |
|
|
116 |
'output_int_register_11':None, |
|
|
117 |
'output_int_register_12':None, |
|
|
118 |
'output_int_register_13':None, |
|
|
119 |
'output_int_register_14':None, |
|
|
120 |
'output_int_register_15':None, |
|
|
121 |
'output_int_register_16':None, |
|
|
122 |
'output_int_register_17':None, |
|
|
123 |
'output_int_register_18':None, |
|
|
124 |
'output_int_register_19':None, |
|
|
125 |
'output_int_register_20':None, |
|
|
126 |
'output_int_register_21':None, |
|
|
127 |
'output_int_register_22':None, |
|
|
128 |
'output_int_register_23':None, |
|
|
129 |
'output_double_register_0':None, |
|
|
130 |
'output_double_register_1':None, |
|
|
131 |
'output_double_register_2':None, |
|
|
132 |
'output_double_register_3':None, |
|
|
133 |
'output_double_register_4':None, |
|
|
134 |
'output_double_register_5':None, |
|
|
135 |
'output_double_register_6':None, |
|
|
136 |
'output_double_register_7':None, |
|
|
137 |
'output_double_register_8':None, |
|
|
138 |
'output_double_register_9':None, |
|
|
139 |
'output_double_register_10':None, |
|
|
140 |
'output_double_register_11':None, |
|
|
141 |
'output_double_register_12':None, |
|
|
142 |
'output_double_register_13':None, |
|
|
143 |
'output_double_register_14':None, |
|
|
144 |
'output_double_register_15':None, |
|
|
145 |
'output_double_register_16':None, |
|
|
146 |
'output_double_register_17':None, |
|
|
147 |
'output_double_register_18':None, |
|
|
148 |
'output_double_register_19':None, |
|
|
149 |
'output_double_register_20':None, |
|
|
150 |
'output_double_register_21':None, |
|
|
151 |
'output_double_register_22':None, |
|
|
152 |
'output_double_register_23':None, |
|
|
153 |
'urPlus_force_torque_sensor':None, |
|
|
154 |
'urPlus_totalMovedVerticalDistance':None |
|
|
155 |
} |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
self.rtcConnectionState = None |
|
|
159 |
self.rtcProgramRunning = False |
|
|
160 |
self.rtcProgramExecutionError = False |
|
|
161 |
self.stopRunningFlag = False |
|
|
162 |
self.forceRemoteActiveFlag = False |
|
|
163 |
self.realtimeControlFlag = False |
|
|
164 |
|
|
|
165 |
# UR plus content |
|
|
166 |
self.hasForceTorqueSensor = False |
|
|
167 |
self.forceTourqe = None |
|
|
168 |
|
|
|
169 |
def RobotTimestamp(self):return self.dataDir['timestamp'] |
|
|
170 |
def LastUpdateTimestamp(self):raise NotImplementedError('Function Not yet implemented') |
|
|
171 |
def RTDEConnectionState(self):raise NotImplementedError('Function Not yet implemented') |
|
|
172 |
def RuntimeState(self): return self.rtcProgramRunning |
|
|
173 |
def StopRunningFlag(self): return self.stopRunningFlag |
|
|
174 |
def DigitalInputbits(self,n): |
|
|
175 |
if n>=0 & n<8: |
|
|
176 |
n = pow(2,n) |
|
|
177 |
return n&self.dataDir['actual_digital_input_bits']==n |
|
|
178 |
else: |
|
|
179 |
return None |
|
|
180 |
|
|
|
181 |
def ConfigurableInputBits(self,n): |
|
|
182 |
if n>=8 & n<16: |
|
|
183 |
n = pow(2,n+8) |
|
|
184 |
return n&self.dataDir['actual_digital_input_bits']==n |
|
|
185 |
else: |
|
|
186 |
return None |
|
|
187 |
|
|
|
188 |
def DigitalOutputBits(self,n): |
|
|
189 |
if n>=0 & n<8: |
|
|
190 |
n = pow(2,n) |
|
|
191 |
return n&self.dataDir['actual_digital_output_bits']==n |
|
|
192 |
else: |
|
|
193 |
return None |
|
|
194 |
|
|
|
195 |
def ConfigurableOutputBits(self,n): |
|
|
196 |
if n>=8 & n<16: |
|
|
197 |
n = pow(2,n+8) |
|
|
198 |
return n&self.dataDir['actual_digital_output_bits']==n |
|
|
199 |
else: |
|
|
200 |
return None |
|
|
201 |
|
|
|
202 |
def RTDEProtocolVersion(self):raise NotImplementedError('Function Not yet implemented') |
|
|
203 |
def ActualTCPPose(self):return self.dataDir['actual_TCP_pose'] |
|
|
204 |
def RobotModee(self):raise NotImplementedError('Function Not yet implemented') |
|
|
205 |
def SafetyMode(self):raise NotImplementedError('Function Not yet implemented') |
|
|
206 |
def TargetQ(self):raise NotImplementedError('Function Not yet implemented') |
|
|
207 |
def TargetQD(self):raise NotImplementedError('Function Not yet implemented') |
|
|
208 |
def TargetQDD(self):raise NotImplementedError('Function Not yet implemented') |
|
|
209 |
def TargetCurrent(self):raise NotImplementedError('Function Not yet implemented') |
|
|
210 |
def TargetMoment(self):raise NotImplementedError('Function Not yet implemented') |
|
|
211 |
def ActualQ(self):return self.dataDir['actual_q'] |
|
|
212 |
def ActualQD(self):raise NotImplementedError('Function Not yet implemented') |
|
|
213 |
def ActualCurrent(self):raise NotImplementedError('Function Not yet implemented') |
|
|
214 |
def JointControlOutput(self):raise NotImplementedError('Function Not yet implemented') |
|
|
215 |
def ActualTCPSpeed(self):return self.dataDir["actual_TCP_speed"] |
|
|
216 |
def ActualTCPForce(self):return self.dataDir['actual_TCP_force'] |
|
|
217 |
def TargetTCPPose(self):raise NotImplementedError('Function Not yet implemented') |
|
|
218 |
def TargetTCPSpeed(self):raise NotImplementedError('Function Not yet implemented') |
|
|
219 |
def JointTemperatures(self):raise NotImplementedError('Function Not yet implemented') |
|
|
220 |
def ActualExecutionTime(self):raise NotImplementedError('Function Not yet implemented') |
|
|
221 |
def JointMode(self):raise NotImplementedError('Function Not yet implemented') |
|
|
222 |
def ActualToolAccelerometer(self):raise NotImplementedError('Function Not yet implemented') |
|
|
223 |
def SpeedScaling(self):raise NotImplementedError('Function Not yet implemented') |
|
|
224 |
def TargetSpeedFraction(self):raise NotImplementedError('Function Not yet implemented') |
|
|
225 |
def ActualMomentum(self):raise NotImplementedError('Function Not yet implemented') |
|
|
226 |
def ActualMainVoltage(self):raise NotImplementedError('Function Not yet implemented') |
|
|
227 |
def ActualRobotVoltage(self):raise NotImplementedError('Function Not yet implemented') |
|
|
228 |
def ActualRobotCurrent(self):raise NotImplementedError('Function Not yet implemented') |
|
|
229 |
def ActualJointVoltage(self):raise NotImplementedError('Function Not yet implemented') |
|
|
230 |
def RunTimeState(self):raise NotImplementedError('Function Not yet implemented') |
|
|
231 |
def IoCurrent(self):raise NotImplementedError('Function Not yet implemented') |
|
|
232 |
def ToolAnalogInput0(self):raise NotImplementedError('Function Not yet implemented') |
|
|
233 |
def ToolAnalogInput1(self):raise NotImplementedError('Function Not yet implemented') |
|
|
234 |
def ToolOutputCurrent(self):raise NotImplementedError('Function Not yet implemented') |
|
|
235 |
def ToolOutputVoltage(self):raise NotImplementedError('Function Not yet implemented') |
|
|
236 |
def StandardAnalogInput(self,n): |
|
|
237 |
if n == 0: |
|
|
238 |
return self.dataDir['standard_analog_input0'] |
|
|
239 |
elif n == 1: |
|
|
240 |
return self.dataDir['standard_analog_input1'] |
|
|
241 |
else: |
|
|
242 |
raise KeyError('Index out of range') |
|
|
243 |
|
|
|
244 |
def StandardAnalogOutput(self):raise NotImplementedError('Function Not yet implemented') |
|
|
245 |
|
|
|
246 |
def RobotStatus(self): |
|
|
247 |
''' |
|
|
248 |
SafetyStatusBit class defined in the bottom of this file |
|
|
249 |
''' |
|
|
250 |
result = RobotStatusBit() |
|
|
251 |
result.PowerOn = 1&self.dataDir['robot_status_bits']==1 |
|
|
252 |
result.ProgramRunning = 2&self.dataDir['robot_status_bits']==2 |
|
|
253 |
result.TeachButtonPressed = 4&self.dataDir['robot_status_bits']==4 |
|
|
254 |
result.PowerButtonPressed = 8&self.dataDir['robot_status_bits']==8 |
|
|
255 |
return result |
|
|
256 |
|
|
|
257 |
def SafetyStatus(self): |
|
|
258 |
''' |
|
|
259 |
SafetyStatusBit class defined in the bottom of this file |
|
|
260 |
''' |
|
|
261 |
result = SafetyStatusBit() |
|
|
262 |
result.NormalMode = 1&self.dataDir['safety_status_bits']==1 |
|
|
263 |
result.ReducedMode = 2&self.dataDir['safety_status_bits']==2 |
|
|
264 |
result.ProtectiveStopped = 4&self.dataDir['safety_status_bits']==4 |
|
|
265 |
result.RecoveryMode = 8&self.dataDir['safety_status_bits']==8 |
|
|
266 |
result.SafeguardStopped = 16&self.dataDir['safety_status_bits']==16 |
|
|
267 |
result.SystemEmergencyStopped = 32&self.dataDir['safety_status_bits']==32 |
|
|
268 |
result.RobotEmergencyStopped = 64&self.dataDir['safety_status_bits']==64 |
|
|
269 |
result.EmergencyStopped = 128&self.dataDir['safety_status_bits']==128 |
|
|
270 |
result.Violation = 256&self.dataDir['safety_status_bits']==256 |
|
|
271 |
result.Fault = 512&self.dataDir['safety_status_bits']==512 |
|
|
272 |
result.StoppedDueToSafety = 1024&self.dataDir['safety_status_bits']==1024 |
|
|
273 |
return result |
|
|
274 |
|
|
|
275 |
def TcpForceScalar(self): return self.dataDir['tcp_force_scalar'] |
|
|
276 |
|
|
|
277 |
def OutputBitRegister(self): |
|
|
278 |
result = [None]*64 |
|
|
279 |
for ii in range(64): |
|
|
280 |
if ii<32 and self.dataDir['output_bit_registers0_to_31'] is not None: |
|
|
281 |
result[ii] = 2**(ii)&self.dataDir['output_bit_registers0_to_31']==2**(ii) |
|
|
282 |
elif ii>31 and self.dataDir['output_bit_registers32_to_63'] is not None: |
|
|
283 |
result[ii] = 2**(ii-32)&self.dataDir['output_bit_registers32_to_63']==2**(ii-32) |
|
|
284 |
return result |
|
|
285 |
|
|
|
286 |
def OutputDoubleRegister(self, n): |
|
|
287 |
return self.dataDir["output_double_register_" + str(n)] |
|
|
288 |
|
|
|
289 |
def UrControlVersion(self):raise NotImplementedError('Function Not yet implemented') |
|
|
290 |
def ClearToSend(self):raise NotImplementedError('Function Not yet implemented') |
|
|
291 |
|
|
|
292 |
|
|
|
293 |
class RobotStatusBit(object): |
|
|
294 |
PowerOn = None |
|
|
295 |
ProgramRunning = None |
|
|
296 |
TeachButtonPressed = None |
|
|
297 |
PowerButtonPressed = None |
|
|
298 |
|
|
|
299 |
class SafetyStatusBit(object): |
|
|
300 |
NormalMode = None |
|
|
301 |
ReducedMode = None |
|
|
302 |
ProtectiveStopped = None |
|
|
303 |
RecoveryMode = None |
|
|
304 |
SafeguardStopped = None |
|
|
305 |
SystemEmergencyStopped = None |
|
|
306 |
RobotEmergencyStopped = None |
|
|
307 |
EmergencyStopped = None |
|
|
308 |
Violation = None |
|
|
309 |
Fault = None |
|
|
310 |
StoppedDueToSafety = None |