Skip to content

Commit

Permalink
Merge pull request #109 from elephantrobotics/myhand_gripper
Browse files Browse the repository at this point in the history
Myhand gripper
  • Loading branch information
wangWking authored Nov 15, 2024
2 parents 7187cfb + 48bb575 commit 4c254c6
Show file tree
Hide file tree
Showing 4 changed files with 940 additions and 10 deletions.
41 changes: 39 additions & 2 deletions pymycobot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,39 @@ class ProGripper(object):
SET_GRIPPER_ANGLES = 45


class MyHandGripper(object):
GET_HAND_MAJOR_FIRMWARE_VERSION = 1
GET_HAND_MINOR_FIRMWARE_VERSION = 2
SET_HAND_GRIPPER_ID = 3
GET_HAND_GRIPPER_ID = 4
SET_HAND_GRIPPER_ENABLED = 10
SET_HAND_GRIPPER_ANGLE = 11
GET_HAND_GRIPPER_ANGLE = 12
SET_HAND_GRIPPER_CALIBRATION = 13
GET_HAND_GRIPPER_STATUS = 14
SET_HAND_GRIPPER_P = 15
GET_HAND_GRIPPER_P = 16
SET_HAND_GRIPPER_D = 17
GET_HAND_GRIPPER_D = 18
SET_HAND_GRIPPER_I = 19
GET_HAND_GRIPPER_I = 20
SET_HAND_GRIPPER_CLOCKWISE = 21
GET_HAND_GRIPPER_CLOCKWISE = 22
SET_HAND_GRIPPER_COUNTERCLOCKWISE = 23
GET_HAND_GRIPPER_COUNTERCLOCKWISE = 24
SET_HAND_GRIPPER_MIN_PRESSURE = 25
GET_HAND_GRIPPER_MIN_PRESSURE = 26
SET_HAND_GRIPPER_TORQUE = 27
GET_HAND_GRIPPER_TORQUE = 28
SET_HAND_GRIPPER_SPEED = 32
GET_HAND_GRIPPER_DEFAULT_SPEED = 33
SET_HAND_GRIPPER_ANGLES = 45
GET_HAND_SINGLE_PRESSURE_SENSOR = 46
GET_HAND_ALL_PRESSURE_SENSOR = 47
GET_HAND_ALL_ANGLES = 50
SET_HAND_GRIPPER_PINCH_ACTION = 51


class ProtocolCode(object):
# BASIC
HEADER = 0xFE
Expand Down Expand Up @@ -802,8 +835,12 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None, real
wait_time = 0.05
if real_command:
if genre == ProtocolCode.SET_TOQUE_GRIPPER:
if real_command[6] == 13:
wait_time = 3
if len(real_command) == 12:
if real_command[6] == 13:
wait_time = 10
else:
if real_command[6] == 13:
wait_time = 3
data = b""
if method is not None:
if real_command:
Expand Down
67 changes: 61 additions & 6 deletions pymycobot/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def calibration_parameters(**kwargs):
raise MyCobot320DataException(
"The range of 'gripper_angle' in {} is 0 ~ 100, but the received value is {}".format(parameter,
gripper_angle))
elif parameter == "gripper_id":
elif parameter == "gripper_id" or parameter == "set_id":
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 1 or value > 254:
raise MyCobot320DataException(
Expand Down Expand Up @@ -881,6 +881,56 @@ def calibration_parameters(**kwargs):
raise MyCobot320DataException(
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
parameter, invalid_addresses, address))

elif parameter == "gripper_joint_id":
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 1 or value > 6:
raise MyCobot320DataException(
"The range of 'gripper_id' in {} is 1 ~ 6, but the received value is {}".format(parameter,
value))
elif parameter == "gripper_angles":
if len(value) != 6:
raise MyCobot320DataException(
"{}: 'gripper_angles' must contain exactly 6 values, but received {}.".format(class_name,
len(value)))

for i, angle in enumerate(value):
if not isinstance(angle, int):
raise MyCobot320DataException(
"{}: Value at position {} in 'gripper_angles' must be an integer, but received {}.".format(
class_name, i + 1, angle)
)
if angle < 0 or angle > 100:
raise MyCobot320DataException(
"{}: Value {} at position {} in 'gripper_angles' is out of range (0 ~ 100).".format(
class_name, angle, i + 1)
)
elif parameter == 'pinch_mode':
check_0_or_1(parameter, value, [0, 1, 2, 3], value_type, MyCobot320DataException, int)
elif parameter == "gripper_finger_id":
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 1 or value > 5:
raise MyCobot320DataException(
"The range of 'gripper_id' in {} is 1 ~ 6, but the received value is {}".format(parameter,
value))
elif parameter == "clockwise":
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 0 or value > 16:
raise MyCobot320DataException(
"The range of 'value' in {} is 0 ~ 16, but the received value is {}".format(parameter,
value))
elif parameter in ["min_pressure", "gripper_i"]:
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 0 or value > 254:
raise MyCobot320DataException(
"The range of 'value' in {} is 0 ~ 254, but the received value is {}".format(parameter,
value))
elif parameter in ["gripper_p", "gripper_d"]:
check_value_type(parameter, value_type, MyCobot320DataException, int)
if value < 0 or value > 150:
raise MyCobot320DataException(
"The range of 'value' in {} is 0 ~ 150, but the received value is {}".format(parameter,
value))
elif class_name in ["MechArm", "MechArmSocket"]:
public_check(parameter_list, kwargs, robot_limit, class_name, MechArmDataException)
elif class_name in ["MechArm270", "MechArmSocket"]:
Expand Down Expand Up @@ -1292,31 +1342,36 @@ def calibration_parameters(**kwargs):
value = kwargs[parameter]
value_type = type(value)
if parameter in ("servo_id", "joint_id") and value not in limit_info[parameter]:
raise ValueError(f"The {parameter} not right, should be in {limit_info[parameter]}, but received {value}.")
raise ValueError(
f"The {parameter} not right, should be in {limit_info[parameter]}, but received {value}.")
elif parameter == 'angle':
i = kwargs['joint_id'] - 1
min_angle = limit_info["angles_min"][i]
max_angle = limit_info["angles_max"][i]
if value < min_angle or value > max_angle:
raise ValueError(f"angle value not right, should be {min_angle} ~ {max_angle}, but received {value}")
raise ValueError(
f"angle value not right, should be {min_angle} ~ {max_angle}, but received {value}")
elif parameter == 'angles':
for i, v in enumerate(value):
min_angle = limit_info["angles_min"][i]
max_angle = limit_info["angles_max"][i]
if v < min_angle or v > max_angle:
raise ValueError(f"angle value not right, should be {min_angle} ~ {max_angle}, but received {v}")
raise ValueError(
f"angle value not right, should be {min_angle} ~ {max_angle}, but received {v}")
elif parameter == 'encoder':
i = kwargs['servo_id'] - 1
max_encoder = limit_info["encoders_max"][i]
min_encoder = limit_info["encoders_min"][i]
if value < min_encoder or value > max_encoder:
raise ValueError(f"angle value not right, should be {min_encoder} ~ {max_encoder}, but received {value}")
raise ValueError(
f"angle value not right, should be {min_encoder} ~ {max_encoder}, but received {value}")
elif parameter == 'encoders':
for i, v in enumerate(value):
max_encoder = limit_info["encoders_max"][i]
min_encoder = limit_info["encoders_min"][i]
if v < min_encoder or v > max_encoder:
raise ValueError(f"encoder value not right, should be {min_encoder} ~ {max_encoder}, but received {v}")
raise ValueError(
f"encoder value not right, should be {min_encoder} ~ {max_encoder}, but received {v}")
elif parameter == "speed":
check_value_type(parameter, value_type, TypeError, int)
if not 1 <= value <= 100:
Expand Down
Loading

0 comments on commit 4c254c6

Please sign in to comment.