@@ -216,6 +216,31 @@ class ProtocolCode(object):
216216 MERCURY_DRAG_TECH_PAUSE = 0x72
217217 MERCURY_DRAG_TEACH_CLEAN = 0x73
218218
219+ GET_ROBOT_MODIFIED_VERSION = 1
220+ GET_ROBOT_FIRMWARE_VERSION = 2
221+ GET_ROBOT_AUXILIARY_FIRMWARE_VERSION = 3
222+ GET_ROBOT_ATOM_MODIFIED_VERSION = 4
223+ GET_ROBOT_TOOL_FIRMWARE_VERSION = 9
224+ GET_ROBOT_SERIAL_NUMBER = 5
225+ SET_ROBOT_ERROR_CHECK_STATE = 6
226+ GET_ROBOT_ERROR_CHECK_STATE = 7
227+ GET_ROBOT_ERROR_STATUS = 0x15
228+ GET_ATOM_PRESS_STATUS = 0x6b
229+ GET_ATOM_LED_COLOR = 0x6a
230+ SET_ATOM_PIN_STATUS = 0x61
231+ GET_ATOM_PIN_STATUS = 0x62
232+ SET_MASTER_PIN_STATUS = 0x65
233+ GET_MASTER_PIN_STATUS = 0x66
234+ SET_AUXILIARY_PIN_STATUS = 0xa0
235+ GET_AUXILIARY_PIN_STATUS = 0xa1
236+ SET_SERVO_MOTOR_CLOCKWISE = 0x73
237+ GET_SERVO_MOTOR_CLOCKWISE = 0Xea
238+ SET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0x74
239+ GET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0xeb
240+ SET_SERVO_MOTOR_CONFIG = 0x52
241+ GET_SERVO_MOTOR_CONFIG = 0x53
242+ CLEAR_RECV_QUEUE = 0x19
243+ GET_RECV_QUEUE_LENGTH = 0x08
219244 GET_BASE_COORDS = 0xF0
220245 BASE_TO_SINGLE_COORDS = 0xF1
221246 COLLISION = 0xF2
@@ -226,6 +251,9 @@ class ProtocolCode(object):
226251 JOG_INC_COORD = 0xF7
227252 COLLISION_SWITCH = 0xF8
228253 IS_COLLISION_ON = 0xF9
254+ CLEAR_ROBOT_ERROR = 0x16
255+ GET_RECV_QUEUE_SIZE = 0x17
256+ SET_RECV_QUEUE_SIZE = 0x18
229257
230258 # IIC
231259 # SET_IIC_STATE = 0xA4
@@ -265,6 +293,41 @@ class ProtocolCode(object):
265293
266294
267295class DataProcessor (object ):
296+ def _mesg (self , genre , * args , ** kwargs ):
297+ """
298+ Args:
299+ genre: command type (Command)
300+ *args: other data.
301+ It is converted to octal by default.
302+ If the data needs to be encapsulated into hexadecimal,
303+ the array is used to include them. (Data cannot be nested)
304+ **kwargs: support `has_reply`
305+ has_reply: Whether there is a return value to accept.
306+ """
307+ command_data = self ._process_data_command (genre , self .__class__ .__name__ , args )
308+ if genre == 178 :
309+ command_data = self ._encode_int16 (command_data )
310+ elif genre in [76 , 77 ]:
311+ command_data = [command_data [0 ]] + self ._encode_int16 (command_data [1 ] * 10 )
312+ elif genre == 115 and self .__class__ .__name__ != "MyArmM" :
313+ command_data = [command_data [1 ], command_data [3 ]]
314+ LEN = len (command_data ) + 2
315+ command = [
316+ ProtocolCode .HEADER ,
317+ ProtocolCode .HEADER ,
318+ LEN ,
319+ genre ,
320+ ]
321+ if command_data :
322+ command .extend (command_data )
323+ if self .__class__ .__name__ in ["Mercury" , "MercurySocket" ]:
324+ command [2 ] += 1
325+ command .extend (self .crc_check (command ))
326+ else :
327+ command .append (ProtocolCode .FOOTER )
328+ real_command = self ._flatten (command )
329+ has_reply = kwargs .get ("has_reply" , False )
330+ return real_command , has_reply
268331 # Functional approach
269332 def _encode_int8 (self , data ):
270333 return struct .pack ("b" , data )
@@ -346,7 +409,7 @@ def _process_data_command(self, genre, _class, args):
346409 byte_value = data .to_bytes (4 , byteorder = 'big' , signed = True )
347410 res = []
348411 for i in range (len (byte_value )):
349- res .append (byte_value [i ])
412+ res .append (byte_value [i ])
350413 processed_args .extend (res )
351414 else :
352415 processed_args .extend (self ._encode_int16 (args [index ]))
@@ -358,7 +421,7 @@ def _process_data_command(self, genre, _class, args):
358421 byte_value = args [index ].to_bytes (2 , byteorder = 'big' , signed = True )
359422 res = []
360423 for i in range (len (byte_value )):
361- res .append (byte_value [i ])
424+ res .append (byte_value [i ])
362425 processed_args .extend (res )
363426 else :
364427 processed_args .append (args [index ])
@@ -382,7 +445,7 @@ def _process_received(self, data, genre, arm=6):
382445 header_i , header_j = 0 , 1
383446 while header_j < data_len - 4 :
384447 if self ._is_frame_header (data , header_i , header_j ):
385- if arm in [6 , 7 , 14 ]:
448+ if arm in [6 , 7 , 14 , 8 ]:
386449 cmd_id = data [header_i + 3 ]
387450 elif arm == 12 :
388451 cmd_id = data [header_i + 4 ]
@@ -393,7 +456,7 @@ def _process_received(self, data, genre, arm=6):
393456 header_j += 1
394457 else :
395458 return []
396- if arm in [6 , 7 ]:
459+ if arm in [6 , 7 , 8 ]:
397460 data_len = data [header_i + 2 ] - 2
398461 elif arm == 12 :
399462 data_len = data [header_i + 3 ] - 2
@@ -410,7 +473,7 @@ def _process_received(self, data, genre, arm=6):
410473 data_pos = header_i + 5
411474 data_len -= 1
412475 else :
413- if arm in [6 , 7 , 14 ]:
476+ if arm in [6 , 7 , 14 , 8 ]:
414477 data_pos = header_i + 4
415478 elif arm == 12 :
416479 data_pos = header_i + 5
@@ -423,7 +486,17 @@ def _process_received(self, data, genre, arm=6):
423486 # res.append(i)
424487 # return res
425488 if data_len in [6 , 8 , 12 , 14 , 16 , 24 , 26 , 60 ]:
426- if data_len == 8 and arm == 14 and cmd_id == ProtocolCode .IS_INIT_CALIBRATION :
489+ ignor_t = (
490+ ProtocolCode .GET_SERVO_CURRENTS ,
491+ ProtocolCode .GET_SERVO_TEMPS ,
492+ ProtocolCode .GET_SERVO_VOLTAGES ,
493+ ProtocolCode .GET_SERVO_STATUS ,
494+ ProtocolCode .IS_ALL_SERVO_ENABLE
495+ )
496+ if data_len == 8 and (
497+ (arm == 14 and cmd_id == ProtocolCode .IS_INIT_CALIBRATION ) or
498+ (arm == 8 and cmd_id in ignor_t )
499+ ):
427500 for v in valid_data :
428501 res .append (v )
429502 return res
@@ -572,21 +645,24 @@ def write(self, command, method=None):
572645 self ._serial_port .flush ()
573646
574647
575- def read (self , genre , method = None , command = None , _class = None ):
648+ def read (self , genre , method = None , command = None , _class = None , timeout = None ):
576649 datas = b""
577650 data_len = - 1
578651 k = 0
579652 pre = 0
580653 t = time .time ()
581654 wait_time = 0.1
582655 if method is not None :
583- wait_time = 0.3
656+ wait_time = 0.3
584657 if genre == ProtocolCode .GO_ZERO :
585658 wait_time = 120
659+ if timeout is not None :
660+ wait_time = timeout
586661 if _class in ["Mercury" , "MercurySocket" ]:
587662 if genre == ProtocolCode .POWER_ON :
588663 wait_time = 8
589- elif genre in [ProtocolCode .POWER_OFF , ProtocolCode .RELEASE_ALL_SERVOS , ProtocolCode .FOCUS_ALL_SERVOS , ProtocolCode .RELEASE_SERVO , ProtocolCode .FOCUS_SERVO , ProtocolCode .STOP ]:
664+ elif genre in [ProtocolCode .POWER_OFF , ProtocolCode .RELEASE_ALL_SERVOS , ProtocolCode .FOCUS_ALL_SERVOS ,
665+ ProtocolCode .RELEASE_SERVO , ProtocolCode .FOCUS_SERVO , ProtocolCode .STOP ]:
590666 wait_time = 3
591667 if method is not None :
592668 if genre == 177 :
0 commit comments