Skip to content

Commit 40f7406

Browse files
committed
320新增三指夹爪部分控制接口
1 parent 3fc5d95 commit 40f7406

File tree

3 files changed

+109
-65
lines changed

3 files changed

+109
-65
lines changed

pymycobot/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ProGripper(object):
2222
SET_GRIPPER_PAUSE = 37
2323
SET_GRIPPER_RESUME = 38
2424
SET_GRIPPER_STOP = 39
25+
SET_GRIPPER_ANGLES = 45
2526

2627

2728
class ProtocolCode(object):

pymycobot/error.py

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -787,41 +787,63 @@ def calibration_parameters(**kwargs):
787787
"The range of 'torque_value' in {} is 100 ~ 300, but the received value is {}".format(parameter,
788788
torque_value))
789789

790-
elif parameter == "gripper_speed":
791-
gripper_id, speed = value
792-
if not isinstance(gripper_id, int) or not isinstance(speed, int):
793-
raise MyCobot320DataException(
794-
"Both 'gripper_id' and 'speed' in {} must be integers".format(parameter))
795-
if gripper_id < 1 or gripper_id > 254:
796-
raise MyCobot320DataException(
797-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
798-
gripper_id))
799-
if speed < 1 or torque_value > 100:
800-
raise MyCobot320DataException(
801-
"The range of 'speed' in {} is 1 ~ 100, but the received value is {}".format(parameter,
802-
speed))
803-
elif parameter == "set_gripper_args":
804-
if len(value) != 3:
805-
raise ValueError(f"Expected 3 arguments, but got {len(value)}")
806-
gripper_id, address, data = value
807-
if not isinstance(gripper_id, int) or not isinstance(address, int) or not isinstance(data, int):
808-
raise MyCobot320DataException(
809-
"All arguments in {} must be integers".format(parameter))
810-
if gripper_id < 1 or gripper_id > 254:
811-
raise MyCobot320DataException(
812-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
813-
gripper_id))
814-
invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 27, 28, 32, 33,
815-
36,
816-
37, 38, 39, 40, 42, 44]
817-
if address < 1 or address > 44:
790+
elif parameter == "gripper_speed":
791+
gripper_id, speed = value
792+
if not isinstance(gripper_id, int) or not isinstance(speed, int):
793+
raise MyCobot320DataException(
794+
"Both 'gripper_id' and 'speed' in {} must be integers".format(parameter))
795+
if gripper_id < 1 or gripper_id > 254:
796+
raise MyCobot320DataException(
797+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
798+
gripper_id))
799+
if speed < 1 or speed > 100:
800+
raise MyCobot320DataException(
801+
"The range of 'speed' in {} is 1 ~ 100, but the received value is {}".format(parameter,
802+
speed))
803+
elif parameter == "joint_id":
804+
check_value_type(parameter, value_type, MyCobot320DataException, int)
805+
if not 0 <= value <= 6:
806+
raise MyCobot320DataException(
807+
"speed value not right, should be 1 ~ 100, the received speed is %s"
808+
% value
809+
)
810+
elif parameter == "set_gripper_args":
811+
gripper_id, address, data = value
812+
if not isinstance(gripper_id, int) or not isinstance(address, int):
813+
raise MyCobot320DataException(
814+
"All arguments in {} must be integers".format(parameter))
815+
if gripper_id < 1 or gripper_id > 254:
816+
raise MyCobot320DataException(
817+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
818+
gripper_id))
819+
invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 27, 28, 32, 33,
820+
36,
821+
37, 38, 39, 40, 42, 44]
822+
if address < 1 or address > 48:
823+
raise MyCobot320DataException(
824+
"The range of 'address' in {} is 1 ~ 48, but the received value is {}".format(parameter,
825+
address))
826+
if address in invalid_addresses:
827+
raise MyCobot320DataException(
828+
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
829+
parameter, invalid_addresses, address))
830+
print('data:', data)
831+
if isinstance(data, list):
832+
# 处理 data 为列表的情况
833+
if len(data) != 6:
818834
raise MyCobot320DataException(
819-
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
820-
address))
821-
if address in invalid_addresses:
835+
"data must be a list of length 6。"
836+
)
837+
for index, value in enumerate(data):
838+
if not (0 <= value <= 100):
839+
raise MyCobot320DataException(
840+
"Each value in the data list must be between 0 and 100. Error index {}: The received value is {}".format(index, value)
841+
)
842+
else:
843+
if not isinstance(data, int):
822844
raise MyCobot320DataException(
823-
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
824-
parameter, invalid_addresses, address))
845+
"The parameter {} must be an integer".format(data)
846+
)
825847
# 根据 address 来处理 value
826848
if address in [3, 43]:
827849
if data < 1 or data > 254:
@@ -849,24 +871,24 @@ def calibration_parameters(**kwargs):
849871
"Error in parameter '{}': The range of 'value' for address={} is 0 ~ 100, but the received value is {}".format(
850872
parameter, address, data))
851873

852-
elif parameter == "get_gripper_args":
853-
gripper_id, address = value
854-
if not isinstance(gripper_id, int) or not isinstance(address, int):
855-
raise MyCobot320DataException(
856-
"All arguments in {} must be integers".format(parameter))
857-
if gripper_id < 1 or gripper_id > 254:
858-
raise MyCobot320DataException(
859-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
860-
gripper_id))
861-
invalid_addresses = [5, 6, 10, 15, 16, 17, 18, 19, 20, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43]
862-
if address < 1 or address > 44:
863-
raise MyCobot320DataException(
864-
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
865-
address))
866-
if address in invalid_addresses:
867-
raise MyCobot320DataException(
868-
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
869-
parameter, invalid_addresses, address))
874+
elif parameter == "get_gripper_args":
875+
gripper_id, address = value
876+
if not isinstance(gripper_id, int) or not isinstance(address, int):
877+
raise MyCobot320DataException(
878+
"All arguments in {} must be integers".format(parameter))
879+
if gripper_id < 1 or gripper_id > 254:
880+
raise MyCobot320DataException(
881+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
882+
gripper_id))
883+
invalid_addresses = [5, 6, 10, 15, 16, 17, 18, 19, 20, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43]
884+
if address < 1 or address > 44:
885+
raise MyCobot320DataException(
886+
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
887+
address))
888+
if address in invalid_addresses:
889+
raise MyCobot320DataException(
890+
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
891+
parameter, invalid_addresses, address))
870892
elif class_name in ["MechArm", "MechArmSocket"]:
871893
public_check(parameter_list, kwargs, robot_limit, class_name, MechArmDataException)
872894
elif class_name in ["MechArm270", "MechArmSocket"]:
@@ -1154,7 +1176,7 @@ def calibration_parameters(**kwargs):
11541176
elif parameter == 'gripper_type':
11551177
check_0_or_1(parameter, value, [1, 3, 4], value_type, MyPalletizer260DataException, int)
11561178
elif parameter == '_type_1':
1157-
check_0_or_1(parameter, value, [1, 2, 3, 4], value_type, MyPalletizer260DataException, int)
1179+
check_0_or_1(parameter, value, [1, 2, 3, 4, 5], value_type, MyPalletizer260DataException, int)
11581180
# if value not in [0, 1, 10]:
11591181
# raise exception_class("The data supported by parameter {} is 0 or 1 or 10, but the received value is {}".format(parameter, value))
11601182
elif parameter == 'gripper_value':

pymycobot/mycobot320.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -576,46 +576,67 @@ def get_end_type(self):
576576
"""
577577
return self._mesg(ProtocolCode.GET_END_TYPE, has_reply=True)
578578

579-
# Force Control Gripper
580-
def set_pro_gripper(self, gripper_id, address, value):
579+
# Force Control Gripper and myHand Gripper Control
580+
def set_pro_gripper(self, gripper_id, address, joint_id=0, value=None, speed=None):
581581
"""Setting the force-controlled gripper parameters
582582
583583
Args:
584584
gripper_id (int): 1 ~ 254
585585
address (int): Corresponding to the command sequence number in the force-controlled gripper protocol
586586
value : Parameters in the force-controlled gripper protocol
587587
"""
588-
self.calibration_parameters(class_name=self.__class__.__name__, set_gripper_args=[gripper_id, address, value])
589-
return self._mesg(ProtocolCode.SET_TOQUE_GRIPPER, gripper_id, [address], [value])
588+
if value is None:
589+
# self.calibration_parameters(class_name=self.__class__.__name__,
590+
# set_gripper_args=[gripper_id, address], joint_id=joint_id)
591+
return self._mesg(ProtocolCode.SET_TOQUE_GRIPPER, gripper_id, [address], [joint_id])
592+
elif speed:
593+
self.calibration_parameters(class_name=self.__class__.__name__,
594+
set_gripper_args=[gripper_id, address, value], joint_id=joint_id, speed=speed)
595+
return self._mesg(ProtocolCode.SET_TOQUE_GRIPPER, gripper_id, [address], [joint_id], [value], [speed])
596+
else:
597+
self.calibration_parameters(class_name=self.__class__.__name__,
598+
set_gripper_args=[gripper_id, address, value], joint_id=joint_id)
599+
return self._mesg(ProtocolCode.SET_TOQUE_GRIPPER, gripper_id, [address], [joint_id], [value])
590600

591-
def get_pro_gripper(self, gripper_id, address):
601+
def get_pro_gripper(self, gripper_id, address, joint_id=0):
592602
"""Get the force-controlled gripper parameters
593603
594604
Args:
595605
gripper_id (int): 1 ~ 254
596606
address (int): Corresponding to the command sequence number in the force-controlled gripper protocol
597607
"""
598-
self.calibration_parameters(class_name=self.__class__.__name__, get_gripper_args=[gripper_id, address])
599-
return self._mesg(ProtocolCode.GET_TOQUE_GRIPPER, gripper_id, [address])
608+
self.calibration_parameters(class_name=self.__class__.__name__, get_gripper_args=[gripper_id, address], joint_id=joint_id)
609+
return self._mesg(ProtocolCode.GET_TOQUE_GRIPPER, gripper_id, [address], [joint_id])
600610

601-
def set_pro_gripper_angle(self, gripper_id, gripper_angle):
611+
def set_pro_gripper_angle(self, gripper_id, joint_id=0, gripper_angle=None):
602612
""" Setting the angle of the force-controlled gripper
603613
604614
Args:
605615
gripper_id (int): 1 ~ 254
606616
gripper_angle (int): 0 ~ 100
607617
"""
608618
self.calibration_parameters(class_name=self.__class__.__name__, gripper_angle=[gripper_id, gripper_angle])
609-
return self.set_pro_gripper(gripper_id, ProGripper.SET_GRIPPER_ANGLE, gripper_angle)
619+
return self.set_pro_gripper(gripper_id, ProGripper.SET_GRIPPER_ANGLE, joint_id=joint_id, value=gripper_angle)
620+
621+
def set_pro_gripper_angles(self, gripper_id, gripper_angles, speed):
622+
""" Setting the angle of the force-controlled gripper
623+
624+
Args:
625+
gripper_id (int): 1 ~ 254
626+
gripper_angles (list): 0 ~ 100
627+
speed (int): 0 ~ 100
628+
"""
629+
# self.calibration_parameters(class_name=self.__class__.__name__, gripper_angle=[gripper_id, gripper_angles])
630+
return self.set_pro_gripper(gripper_id, ProGripper.SET_GRIPPER_ANGLES, value=gripper_angles, speed=speed)
610631

611-
def get_pro_gripper_angle(self, gripper_id):
632+
def get_pro_gripper_angle(self, gripper_id, joint_id=0):
612633
""" Setting the angle of the force-controlled gripper
613634
614635
Return:
615636
gripper_id (int): 1 ~ 254
616637
"""
617638
self.calibration_parameters(class_name=self.__class__.__name__, gripper_id=gripper_id)
618-
return self.get_pro_gripper(gripper_id, ProGripper.GET_GRIPPER_ANGLE)
639+
return self.get_pro_gripper(gripper_id, ProGripper.GET_GRIPPER_ANGLE, joint_id=joint_id)
619640

620641
def set_pro_gripper_open(self, gripper_id):
621642
""" Open force-controlled gripper
@@ -637,15 +658,15 @@ def set_pro_gripper_close(self, gripper_id):
637658
self.calibration_parameters(class_name=self.__class__.__name__, gripper_id=gripper_id)
638659
return self.set_pro_gripper_angle(gripper_id, 0)
639660

640-
def set_pro_gripper_calibration(self, gripper_id):
661+
def set_pro_gripper_calibration(self, gripper_id, joint_id=0):
641662
""" Setting the gripper jaw zero position
642663
643664
Args:
644665
gripper_id (int): 1 ~ 254
645666
646667
"""
647668
self.calibration_parameters(class_name=self.__class__.__name__, gripper_id=gripper_id)
648-
return self.set_pro_gripper(gripper_id, ProGripper.SET_GRIPPER_CALIBRATION, 0)
669+
return self.set_pro_gripper(gripper_id, ProGripper.SET_GRIPPER_CALIBRATION, joint_id=joint_id)
649670

650671
def get_pro_gripper_status(self, gripper_id):
651672
""" Get the clamping status of the gripper

0 commit comments

Comments
 (0)