00001 import struct
00002 import copy
00003
00004
00005 class RobotStateRT(object):
00006 @staticmethod
00007 def unpack(buf):
00008 rs = RobotStateRT()
00009 (plen, ptype) = struct.unpack_from("!IB", buf)
00010 if plen == 812:
00011 return RobotStateRT_V18.unpack(buf)
00012 elif plen == 1044:
00013 return RobotStateRT_V30.unpack(buf)
00014 else:
00015 print "RobotStateRT has wrong length: " + str(plen)
00016 return rs
00017
00018
00019 class RobotStateRT_V18(object):
00020 __slots__ = ['time',
00021 'q_target', 'qd_target', 'qdd_target', 'i_target', 'm_target',
00022 'q_actual', 'qd_actual', 'i_actual', 'tool_acc_values',
00023 'unused',
00024 'tcp_force', 'tool_vector', 'tcp_speed',
00025 'digital_input_bits', 'motor_temperatures', 'controller_timer',
00026 'test_value',
00027 'robot_mode', 'joint_modes']
00028
00029 @staticmethod
00030 def unpack(buf):
00031 offset = 0
00032 message_size = struct.unpack_from("!i", buf, offset)[0]
00033 offset+=4
00034 if message_size != len(buf):
00035 print("MessageSize: ", message_size, "; BufferSize: ", len(buf))
00036 raise Exception("Could not unpack RobotStateRT packet: length field is incorrect")
00037
00038 rs = RobotStateRT_V18()
00039
00040 rs.time = struct.unpack_from("!d",buf, offset)[0]
00041 offset+=8
00042
00043
00044 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00045 offset+=6*8
00046 rs.q_target = copy.deepcopy(all_values)
00047
00048
00049 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00050 offset+=6*8
00051 rs.qd_target = copy.deepcopy(all_values)
00052
00053
00054 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00055 offset+=6*8
00056 rs.qdd_target = copy.deepcopy(all_values)
00057
00058
00059 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00060 offset+=6*8
00061 rs.i_target = copy.deepcopy(all_values)
00062
00063
00064 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00065 offset+=6*8
00066 rs.m_target = copy.deepcopy(all_values)
00067
00068
00069 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00070 offset+=6*8
00071 rs.q_actual = copy.deepcopy(all_values)
00072
00073
00074 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00075 offset+=6*8
00076 rs.qd_actual = copy.deepcopy(all_values)
00077
00078
00079 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00080 offset+=6*8
00081 rs.i_actual = copy.deepcopy(all_values)
00082
00083
00084 all_values = list(struct.unpack_from("!ddd",buf, offset))
00085 offset+=3*8
00086 rs.tool_acc_values = copy.deepcopy(all_values)
00087
00088
00089 offset+=120
00090 rs.unused = []
00091
00092
00093 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00094 offset+=6*8
00095 rs.tcp_force = copy.deepcopy(all_values)
00096
00097
00098 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00099 offset+=6*8
00100 rs.tool_vector = copy.deepcopy(all_values)
00101
00102
00103 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00104 offset+=6*8
00105 rs.tcp_speed = copy.deepcopy(all_values)
00106
00107
00108 rs.digital_input_bits = struct.unpack_from("!d",buf, offset)[0]
00109 offset+=8
00110
00111
00112 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00113 offset+=6*8
00114 rs.motor_temperatures = copy.deepcopy(all_values)
00115
00116
00117 rs.controller_timer = struct.unpack_from("!d",buf, offset)[0]
00118 offset+=8
00119
00120
00121 rs.test_value = struct.unpack_from("!d",buf, offset)[0]
00122 offset+=8
00123
00124
00125 rs.robot_mode = struct.unpack_from("!d",buf, offset)[0]
00126 offset+=8
00127
00128
00129 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00130 offset+=6*8
00131 rs.joint_modes = copy.deepcopy(all_values)
00132
00133 return rs
00134
00135
00136 class RobotStateRT_V30(object):
00137 __slots__ = ['time',
00138 'q_target', 'qd_target', 'qdd_target', 'i_target', 'm_target',
00139 'q_actual', 'qd_actual', 'i_actual', 'i_control',
00140 'tool_vector_actual', 'tcp_speed_actual', 'tcp_force',
00141 'tool_vector_target', 'tcp_speed_target',
00142 'digital_input_bits', 'motor_temperatures', 'controller_timer',
00143 'test_value',
00144 'robot_mode', 'joint_modes', 'safety_mode',
00145
00146 'tool_acc_values',
00147
00148 'speed_scaling', 'linear_momentum_norm',
00149
00150 'v_main', 'v_robot', 'i_robot', 'v_actual']
00151
00152 @staticmethod
00153 def unpack(buf):
00154 offset = 0
00155 message_size = struct.unpack_from("!i", buf, offset)[0]
00156 offset+=4
00157 if message_size != len(buf):
00158 print("MessageSize: ", message_size, "; BufferSize: ", len(buf))
00159 raise Exception("Could not unpack RobotStateRT packet: length field is incorrect")
00160
00161 rs = RobotStateRT_V30()
00162
00163 rs.time = struct.unpack_from("!d",buf, offset)[0]
00164 offset+=8
00165
00166
00167 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00168 offset+=6*8
00169 rs.q_target = copy.deepcopy(all_values)
00170
00171
00172 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00173 offset+=6*8
00174 rs.qd_target = copy.deepcopy(all_values)
00175
00176
00177 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00178 offset+=6*8
00179 rs.qdd_target = copy.deepcopy(all_values)
00180
00181
00182 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00183 offset+=6*8
00184 rs.i_target = copy.deepcopy(all_values)
00185
00186
00187 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00188 offset+=6*8
00189 rs.m_target = copy.deepcopy(all_values)
00190
00191
00192 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00193 offset+=6*8
00194 rs.q_actual = copy.deepcopy(all_values)
00195
00196
00197 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00198 offset+=6*8
00199 rs.qd_actual = copy.deepcopy(all_values)
00200
00201
00202 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00203 offset+=6*8
00204 rs.i_actual = copy.deepcopy(all_values)
00205
00206
00207 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00208 offset+=6*8
00209 rs.i_control = copy.deepcopy(all_values)
00210
00211
00212 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00213 offset+=6*8
00214 rs.tool_vector_actual = copy.deepcopy(all_values)
00215
00216
00217 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00218 offset+=6*8
00219 rs.tcp_speed_actual = copy.deepcopy(all_values)
00220
00221
00222 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00223 offset+=6*8
00224 rs.tcp_force = copy.deepcopy(all_values)
00225
00226
00227 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00228 offset+=6*8
00229 rs.tool_vector_target = copy.deepcopy(all_values)
00230
00231
00232 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00233 offset+=6*8
00234 rs.tcp_speed_target = copy.deepcopy(all_values)
00235
00236
00237 rs.digital_input_bits = struct.unpack_from("!d",buf, offset)[0]
00238 offset+=8
00239
00240
00241 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00242 offset+=6*8
00243 rs.motor_temperatures = copy.deepcopy(all_values)
00244
00245
00246 rs.controller_timer = struct.unpack_from("!d",buf, offset)[0]
00247 offset+=8
00248
00249
00250 rs.test_value = struct.unpack_from("!d",buf, offset)[0]
00251 offset+=8
00252
00253
00254 rs.robot_mode = struct.unpack_from("!d",buf, offset)[0]
00255 offset+=8
00256
00257
00258 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00259 offset+=6*8
00260 rs.joint_modes = copy.deepcopy(all_values)
00261
00262
00263 rs.safety_mode = struct.unpack_from("!d",buf, offset)[0]
00264 offset+=8
00265
00266
00267 offset+=48
00268
00269
00270 all_values = list(struct.unpack_from("!ddd",buf, offset))
00271 offset+=3*8
00272 rs.tool_acc_values = copy.deepcopy(all_values)
00273
00274
00275 offset+=48
00276
00277
00278 rs.speed_scaling = struct.unpack_from("!d",buf, offset)[0]
00279 offset+=8
00280
00281
00282 rs.linear_momentum_norm = struct.unpack_from("!d",buf, offset)[0]
00283 offset+=8
00284
00285
00286 offset+=16
00287
00288
00289 rs.v_main = struct.unpack_from("!d",buf, offset)[0]
00290 offset+=8
00291
00292
00293 rs.v_robot = struct.unpack_from("!d",buf, offset)[0]
00294 offset+=8
00295
00296
00297 rs.i_robot = struct.unpack_from("!d",buf, offset)[0]
00298 offset+=8
00299
00300
00301 all_values = list(struct.unpack_from("!dddddd",buf, offset))
00302 offset+=6*8
00303 rs.v_actual = copy.deepcopy(all_values)
00304
00305 return rs