55import sys
66import logging
77import threading
8+ import time
9+
810from pymycobot .common import ProtocolCode , write , read , DataProcessor
911from pymycobot .error import calibration_parameters
1012from pymycobot .log import setup_logging
@@ -52,7 +54,7 @@ def _mesg(self, genre, *args, **kwargs):
5254 **kwargs: support `has_reply`
5355 has_reply: Whether there is a return value to accept.
5456 """
55-
57+ time . sleep ( 0.01 )
5658 real_command , has_reply = super (MyArmAPI , self )._mesg (genre , * args , ** kwargs )
5759 command = self ._flatten (real_command )
5860 with self .lock :
@@ -96,6 +98,8 @@ def _mesg(self, genre, *args, **kwargs):
9698 result = self ._int2angle (result )
9799 return result
98100 if genre in (ProtocolCode .GET_ATOM_PRESS_STATUS , ):
101+ if self .__class__ .__name__ == 'MyArmM' :
102+ return res [0 ]
99103 return res
100104 elif genre in [
101105 ProtocolCode .GET_ANGLES , ProtocolCode .GET_JOINT_MAX_ANGLE , ProtocolCode .GET_JOINT_MIN_ANGLE ,
@@ -115,7 +119,7 @@ def _mesg(self, genre, *args, **kwargs):
115119 rank = [i for i , e in enumerate (reverse_bins ) if e != '0' ]
116120 result .append (rank )
117121 return result
118- elif genre == ProtocolCode .GET_ROBOT_FIRMWARE_VERSION :
122+ elif genre in ( ProtocolCode .GET_ROBOT_FIRMWARE_VERSION , ProtocolCode . GET_ROBOT_TOOL_FIRMWARE_VERSION ) :
119123 return self ._int2coord (res [0 ])
120124 else :
121125 return res
@@ -144,10 +148,6 @@ def get_robot_tool_firmware_version(self):
144148 """Get the Robot Tool Firmware Version (End Atom)"""
145149 return self ._mesg (ProtocolCode .GET_ROBOT_TOOL_FIRMWARE_VERSION , has_reply = True )
146150
147- # def get_robot_serial_number(self):
148- # """Get the bot number"""
149- # return self._mesg(ProtocolCode.GET_ROBOT_SERIAL_NUMBER, has_reply=True)
150-
151151 def set_robot_err_check_state (self , status ):
152152 """Set Error Detection Status You can turn off error detection, but do not turn it off unless necessary
153153
@@ -175,7 +175,8 @@ def get_recv_queue_max_len(self):
175175
176176 def set_recv_queue_max_len (self , max_len ):
177177 """Set the total length of the receiving command queue"""
178- self ._mesg (ProtocolCode .SET_RECV_QUEUE_SIZE , max_len , has_reply = True )
178+ assert 0 < max_len <= 100 , "queue size must be in range 1 - 100"
179+ self ._mesg (ProtocolCode .SET_RECV_QUEUE_SIZE , max_len )
179180
180181 def get_recv_queue_len (self ):
181182 """The current length of the read receive queue"""
@@ -275,15 +276,17 @@ def set_servo_p(self, servo_id, data):
275276 data (int): 0-254
276277
277278 """
278- self ._mesg (ProtocolCode .MERCURY_DRAG_TECH_SAVE , servo_id , data )
279+ assert 0 <= data <= 254 , "data must be between 0 and 254"
280+ self .calibration_parameters (class_name = self .__class__ .__name__ , servo_id = servo_id )
281+ self ._mesg (ProtocolCode .SET_SERVO_P , servo_id , data )
279282
280283 def get_servo_p (self , servo_id ):
281284 """Reads the position loop P scale factor of the specified servo motor
282285
283286 Args:
284287 servo_id (int): 0-254
285288 """
286- return self ._mesg (ProtocolCode .SERVO_RESTORE , servo_id , has_reply = True )
289+ return self ._mesg (ProtocolCode .GET_SERVO_P , servo_id , has_reply = True )
287290
288291 def set_servo_d (self , servo_id , data ):
289292 """Sets the proportional factor for the position ring D of the specified servo motor
@@ -292,6 +295,8 @@ def set_servo_d(self, servo_id, data):
292295 servo_id (int): 0-254
293296 data (int): 0-254
294297 """
298+ assert 0 <= data <= 254 , "data must be between 0 and 254"
299+ self .calibration_parameters (class_name = self .__class__ .__name__ , servo_id = servo_id )
295300 self ._mesg (ProtocolCode .MERCURY_DRAG_TECH_EXECUTE , servo_id , data )
296301
297302 def get_servo_d (self , servo_id ):
@@ -309,6 +314,8 @@ def set_servo_i(self, servo_id, data):
309314 servo_id (int): 0 - 254
310315 data (int): 0 - 254
311316 """
317+ assert 0 <= data <= 254 , "data must be between 0 and 254"
318+ self .calibration_parameters (class_name = self .__class__ .__name__ , servo_id = servo_id )
312319 self ._mesg (ProtocolCode .MERCURY_DRAG_TECH_PAUSE , servo_id , data )
313320
314321 def get_servo_i (self , servo_id ):
@@ -322,6 +329,8 @@ def set_servo_cw(self, servo_id, data):
322329 servo_id (int): 0 - 254
323330 data (int): 0 - 32
324331 """
332+ assert 0 <= data <= 32 , "data must be between 0 and 32"
333+ self .calibration_parameters (class_name = self .__class__ .__name__ , servo_id = servo_id )
325334 self ._mesg (ProtocolCode .SET_SERVO_MOTOR_CLOCKWISE , servo_id , data )
326335
327336 def get_servo_cw (self , servo_id ):
@@ -339,6 +348,8 @@ def set_servo_cww(self, servo_id, data):
339348 servo_id (int): 0 - 254
340349 data (int): 0 - 32
341350 """
351+ assert 0 <= data <= 32 , "data must be between 0 and 32"
352+ self .calibration_parameters (class_name = self .__class__ .__name__ , servo_id = servo_id )
342353 return self ._mesg (ProtocolCode .SET_SERVO_MOTOR_COUNTER_CLOCKWISE , servo_id , data )
343354
344355 def get_servo_cww (self , servo_id ):
0 commit comments