@@ -25,9 +25,9 @@ def _mesg(self, genre, *args, **kwargs):
2525 command_data = self ._encode_int16 (command_data )
2626
2727 LEN = len (command_data ) + 1
28- check_digit = sum (command_data [1 :]) + genre
29- if check_digit >= 256 :
30- check_digit %= 256
28+ check_digit = ( sum (command_data [1 :]) + genre ) & 0xff
29+ # if check_digit >= 256:
30+ # check_digit %= 256
3131 command = [
3232 ProtocolCode .HEADER ,
3333 ProtocolCode .HEADER ,
@@ -843,33 +843,6 @@ def get_joint_current(self, id, joint_id):
843843 """
844844 return self ._mesg (ProtocolCode .GET_JOINT_CURRENT , id , joint_id )
845845
846- # Basic
847- def set_basic_mode (self , pin_no , pin_mode ):
848- """Set base IO, input or output mode
849-
850- Args:
851- pin_no: 1 - 5
852- pin_mode: 0 - input 1 - output
853- """
854- return self ._mesg (ProtocolCode .SET_BASIC_OUTPUT , 0 , pin_no , pin_mode )
855-
856- def set_basic_output (self , pin_no , pin_signal ):
857- """Set basic output.
858-
859- Args:
860- pin_no: pin port number (0 - 20).
861- pin_signal: 0 / 1 (0 - low, 1 - high)
862- """
863- return self ._mesg (ProtocolCode .GET_BASIC_INPUT , 0 , pin_no , pin_signal )
864-
865- def get_basic_input (self , pin_no ):
866- """Get basic input for M5 version.
867-
868- Args:
869- pin_no: (int) pin port number (0 - 20).
870- """
871- return self ._mesg (ProtocolCode .GET_BASE_INPUT , 0 , pin_no , has_reply = True )
872-
873846 def get_plan_speed (self , id = 0 ):
874847 """Get planning speed
875848
@@ -953,8 +926,8 @@ def get_servo_temps(self, id):
953926 """
954927 return self ._mesg (0xE6 , id , has_reply = True )
955928
956- def get_base_coords (self , coords , arm ):
957- """Convert coordinates to base coordinates
929+ def get_base_coords (self , * args : int ):
930+ """Convert coordinates to base coordinates. Pass in parameters or no parameters
958931
959932 Args:
960933 coords: a list of coords value(List[float]), length 6 [x(mm), y, z, rx(angle), ry, rz]
@@ -963,12 +936,16 @@ def get_base_coords(self, coords, arm):
963936 Return:
964937 Base coords
965938 """
966- coord_list = []
967- for idx in range (3 ):
968- coord_list .append (self ._coord2int (coords [idx ]))
969- for angle in coords [3 :]:
970- coord_list .append (self ._angle2int (angle ))
971- return self ._mesg (ProtocolCode .GET_BASE_COORDS , 0 , coord_list , arm , has_reply = True )
939+ if len (args ) == 2 :
940+ coords , arm = args
941+ coord_list = []
942+ for idx in range (3 ):
943+ coord_list .append (self ._coord2int (coords [idx ]))
944+ for angle in coords [3 :]:
945+ coord_list .append (self ._angle2int (angle ))
946+ return self ._mesg (ProtocolCode .GET_BASE_COORDS , 0 , coord_list , arm , has_reply = True )
947+ elif len (args ) == 0 :
948+ return self ._mesg (ProtocolCode .GET_ALL_BASE_COORDS , 0 , has_reply = True )
972949
973950 def base_to_single_coords (self , base_coords , arm ):
974951 """Convert base coordinates to coordinates
@@ -1002,6 +979,65 @@ def collision(self, left_angles, right_angles):
1002979
1003980 return self ._mesg (ProtocolCode .COLLISION , 0 , degrees1 , degrees2 , has_reply = True )
1004981
982+ def get_base_coord (self , id ):
983+ """Get the base coordinates of the single arm
984+
985+ Args:
986+ id: 1/2 (L/R)
987+ """
988+ return self ._mesg (ProtocolCode .GET_BASE_COORD , id , has_reply = True )
989+
990+ def write_base_coord (self , id , axis , coord , speed ):
991+ """Base single coordinate movement
992+
993+ Args:
994+ id: 1/2 (L/R)
995+ axis: 1 - 6 (x/y/z/rx/ry/rz)
996+ coord: Coordinate value
997+ speed: 1 - 100
998+ """
999+ value = self ._coord2int (coord ) if axis <= 3 else self ._angle2int (coord )
1000+ return self ._mesg (ProtocolCode .WRITE_BASE_COORD , id , axis , [value ], speed )
1001+
1002+ def write_base_coords (self , id , coords , speed ):
1003+ """base coordinate move
1004+
1005+ Args:
1006+ id: 1/2 (L/R)
1007+ coords: coords: a list of coords value(List[float]), length 6, [x(mm), y, z, rx(angle), ry, rz]
1008+ speed: 1 - 100
1009+ """
1010+ coord_list = []
1011+ for idx in range (3 ):
1012+ coord_list .append (self ._coord2int (coords [idx ]))
1013+ for angle in coords [3 :]:
1014+ coord_list .append (self ._angle2int (angle ))
1015+ return self ._mesg (ProtocolCode .WRITE_BASE_COORDS , id , coord_list , speed )
1016+
1017+ def jog_inc_coord (self , axis , increment , speed ):
1018+ """Double-arm coordinated coordinate stepping
1019+
1020+ Args:
1021+ axis: 1 - 6 (x/y/z/rx/ry/rz)
1022+ increment:
1023+ speed: 1 - 100
1024+ """
1025+ value = self ._coord2int (increment ) if axis <= 3 else self ._angle2int (increment )
1026+ return self ._mesg (ProtocolCode .JOG_INC_COORD , 0 , [value ], speed )
1027+
1028+ def collision_switch (self , state ):
1029+ """Collision Detection Switch
1030+
1031+ Args:
1032+ state (int): 0 - close 1 - open (Off by default)
1033+ """
1034+ return self ._mesg (ProtocolCode .COLLISION_SWITCH , state )
1035+
1036+ def is_collision_on (self ):
1037+ """Get collision detection status"""
1038+ return self ._mesg (ProtocolCode .IS_COLLISION_ON , 0 , has_reply = True )
1039+
1040+
10051041 # def init_iic(self):
10061042 # from smbus2 import SMBus
10071043 # i2c = SMBus(1) # 1 代表 /dev/i2c-1
0 commit comments