Skip to content

Commit 264fcba

Browse files
author
蓝启琨
committed
Added myGripper H100 API
1 parent 3c8c370 commit 264fcba

File tree

2 files changed

+333
-1
lines changed

2 files changed

+333
-1
lines changed

pymycobot/common.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ class ProGripper(object):
3030
SET_GRIPPER_STOP = 39
3131

3232

33+
class FingerGripper(object):
34+
GET_HAND_MAJOR_FIRMWARE_VERSION = 1
35+
GET_HAND_MINOR_FIRMWARE_VERSION = 2
36+
SET_HAND_GRIPPER_ID = 3
37+
GET_HAND_GRIPPER_ID = 4
38+
SET_HAND_GRIPPER_ENABLED = 0x0A
39+
SET_HAND_GRIPPER_ANGLE = 0x0B
40+
GET_HAND_GRIPPER_ANGLE = 0x0C
41+
SET_HAND_GRIPPER_CALIBRATION = 0x0D
42+
GET_HAND_GRIPPER_STATUS = 0x0E
43+
SET_HAND_GRIPPER_P = 0x0F
44+
GET_HAND_GRIPPER_P = 0x10
45+
SET_HAND_GRIPPER_D = 0x11
46+
GET_HAND_GRIPPER_D = 0x12
47+
SET_HAND_GRIPPER_I = 0x13
48+
GET_HAND_GRIPPER_I = 0x14
49+
SET_HAND_GRIPPER_CLOCKWISE = 0x15
50+
GET_HAND_GRIPPER_CLOCKWISE = 0x16
51+
SET_HAND_GRIPPER_COUNTERCLOCKWISE = 0x17
52+
GET_HAND_GRIPPER_COUNTERCLOCKWISE = 0x18
53+
SET_HAND_GRIPPER_MIN_PRESSURE = 0x19
54+
GET_HAND_GRIPPER_MIN_PRESSURE = 0x1A
55+
SET_HAND_GRIPPER_TORQUE = 0x1B
56+
GET_HAND_GRIPPER_TORQUE = 0x1C
57+
SET_HAND_GRIPPER_SPEED = 0x20
58+
GET_HAND_GRIPPER_DEFAULT_SPEED = 0x21
59+
SET_HAND_GRIPPER_ANGLES = 0x2D
60+
GET_HAND_SINGLE_PRESSURE_SENSOR = 0x2E
61+
GET_HAND_ALL_PRESSURE_SENSOR = 0x2F
62+
GET_HAND_ALL_ANGLES = 0x32
63+
SET_HAND_GRIPPER_PINCH_ACTION = 0x33
64+
SET_HAND_GRIPPER_PINCH_ACTION_SPEED_CONSORT = 0x34
65+
66+
3367
class ProtocolCode(object):
3468
# BASIC
3569
HEADER = 0xFE

pymycobot/mercury_api.py

Lines changed: 299 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010

1111
from pymycobot.error import calibration_parameters, restrict_serial_port
12-
from pymycobot.common import DataProcessor, ProtocolCode, write, read, ProGripper
12+
from pymycobot.common import DataProcessor, ProtocolCode, write, read, ProGripper, FingerGripper
1313
from pymycobot.robot_info import _interpret_status_code
1414

1515

@@ -173,6 +173,13 @@ def _mesg(self, genre, *args, **kwargs):
173173
elif genre in [ProtocolCode.SERVO_RESTORE]:
174174
wait_time = 0.3
175175
big_wait_time = True
176+
177+
elif genre in (ProtocolCode.MERCURY_SET_TOQUE_GRIPPER, ProtocolCode.MERCURY_GET_TOQUE_GRIPPER):
178+
if real_command[3] == FingerGripper.SET_HAND_GRIPPER_CALIBRATION:
179+
wait_time = 8
180+
elif real_command[3] == FingerGripper.SET_HAND_GRIPPER_ANGLES:
181+
wait_time = 0.5
182+
176183
need_break = False
177184
data = None
178185
timeout = 0.5
@@ -2277,3 +2284,294 @@ def set_pro_gripper_resume(self, gripper_id):
22772284

22782285
def get_motors_run_err(self):
22792286
return self._mesg(ProtocolCode.GET_MOTORS_RUN_ERR)
2287+
2288+
def __set_tool_fittings_value(self, addr, *args, gripper_id=14, **kwargs):
2289+
kwargs["has_replay"] = True
2290+
return self._mesg(ProtocolCode.MERCURY_SET_TOQUE_GRIPPER, gripper_id, [addr], *args or ([0x00],), **kwargs)
2291+
2292+
def __get_tool_fittings_value(self, addr, *args, gripper_id=14, **kwargs):
2293+
kwargs["has_replay"] = True
2294+
return self._mesg(ProtocolCode.MERCURY_GET_TOQUE_GRIPPER, gripper_id, [addr], *args or ([0x00],), **kwargs)
2295+
2296+
def get_hand_firmware_major_version(self, gripper_id):
2297+
return self.__get_tool_fittings_value(
2298+
FingerGripper.GET_HAND_MAJOR_FIRMWARE_VERSION, gripper_id=gripper_id
2299+
)
2300+
2301+
def get_hand_firmware_minor_version(self, gripper_id):
2302+
return self.__get_tool_fittings_value(FingerGripper.GET_HAND_MINOR_FIRMWARE_VERSION, gripper_id=gripper_id)
2303+
2304+
def set_hand_gripper_id(self, gripper_id, hand_id):
2305+
return self.__set_tool_fittings_value(
2306+
FingerGripper.SET_HAND_GRIPPER_ID, [hand_id], gripper_id=gripper_id
2307+
)
2308+
2309+
def get_hand_gripper_id(self, gripper_id):
2310+
return self.__get_tool_fittings_value(
2311+
FingerGripper.GET_HAND_GRIPPER_ID, gripper_id=gripper_id
2312+
)
2313+
2314+
def set_hand_gripper_angle(self, gripper_id, joint_id, gripper_angle):
2315+
"""Set the angle of the single joint of the gripper
2316+
2317+
Args:
2318+
gripper_id (int) : 1 ~ 254
2319+
joint_id (int): 1 ~ 6
2320+
gripper_angle (int): 0 ~ 100
2321+
"""
2322+
return self.__set_tool_fittings_value(
2323+
FingerGripper.SET_HAND_GRIPPER_ANGLE, [joint_id], [gripper_angle], gripper_id=gripper_id
2324+
)
2325+
2326+
def get_hand_gripper_angle(self, gripper_id, joint_id):
2327+
"""Get the angle of the single joint of the gripper
2328+
2329+
Args:
2330+
gripper_id (int) : 1 ~ 254
2331+
joint_id (int): 1 ~ 6
2332+
2333+
Return:
2334+
gripper_angle (int): 0 ~ 100
2335+
"""
2336+
return self.__get_tool_fittings_value(
2337+
FingerGripper.GET_HAND_GRIPPER_ANGLE, [joint_id], gripper_id=gripper_id
2338+
)
2339+
2340+
def set_hand_gripper_angles(self, gripper_id, angles, speed):
2341+
return self.__set_tool_fittings_value(
2342+
FingerGripper.SET_HAND_GRIPPER_ANGLES, [angles], [speed], gripper_id=gripper_id
2343+
)
2344+
2345+
def get_hand_gripper_angles(self, gripper_id):
2346+
return self.__get_tool_fittings_value(FingerGripper.GET_HAND_ALL_ANGLES, gripper_id)
2347+
2348+
def set_hand_gripper_torque(self, gripper_id, joint_id, value):
2349+
return self.__set_tool_fittings_value(
2350+
FingerGripper.SET_HAND_GRIPPER_TORQUE, [joint_id], [value], gripper_id=gripper_id
2351+
)
2352+
2353+
def get_hand_gripper_torque(self, gripper_id, joint_id):
2354+
return self.__get_tool_fittings_value(
2355+
FingerGripper.GET_HAND_GRIPPER_TORQUE, [joint_id], gripper_id=gripper_id
2356+
)
2357+
2358+
def set_hand_gripper_calibrate(self, gripper_id, joint_id):
2359+
""" Setting the gripper jaw zero position
2360+
2361+
Args:
2362+
gripper_id (int): 1 ~ 254
2363+
joint_id (int): 1 ~ 6
2364+
"""
2365+
return self.__set_tool_fittings_value(
2366+
FingerGripper.SET_HAND_GRIPPER_CALIBRATION, [joint_id], gripper_id=gripper_id
2367+
)
2368+
2369+
def get_hand_gripper_status(self, gripper_id):
2370+
""" Get the clamping status of the gripper
2371+
2372+
Args:
2373+
gripper_id (int): 1 ~ 254
2374+
2375+
Return:
2376+
0 - Moving
2377+
1 - Stopped moving, no clamping detected
2378+
2 - Stopped moving, clamping detected
2379+
3 - After clamping detected, the object fell
2380+
"""
2381+
return self.__set_tool_fittings_value(
2382+
FingerGripper.GET_HAND_GRIPPER_STATUS, gripper_id=gripper_id
2383+
)
2384+
2385+
def set_hand_gripper_enabled(self, gripper_id, flag):
2386+
""" Set the enable state of the gripper
2387+
2388+
Args:
2389+
gripper_id (int): 1 ~ 254
2390+
flag (int): 1 ~ 6
2391+
2392+
"""
2393+
return self.__set_tool_fittings_value(
2394+
FingerGripper.SET_HAND_GRIPPER_ENABLED, [flag], gripper_id=gripper_id
2395+
)
2396+
2397+
def set_hand_gripper_speed(self, gripper_id, joint_id, speed):
2398+
""" Set the speed of the gripper
2399+
2400+
Args:
2401+
gripper_id (int): 1 ~ 254
2402+
joint_id (int): 1 ~ 6
2403+
speed (int): 1 ~ 100
2404+
2405+
"""
2406+
return self.__set_tool_fittings_value(
2407+
FingerGripper.SET_HAND_GRIPPER_SPEED, [joint_id], [speed], gripper_id=gripper_id
2408+
)
2409+
2410+
def get_hand_gripper_default_speed(self, gripper_id, joint_id):
2411+
""" Get the default speed of the gripper
2412+
2413+
Args:
2414+
gripper_id (int): 1 ~ 254
2415+
joint_id (int): 1 ~ 6
2416+
2417+
Return:
2418+
default speed (int): 1 ~ 100
2419+
2420+
"""
2421+
return self.__set_tool_fittings_value(
2422+
FingerGripper.GET_HAND_GRIPPER_DEFAULT_SPEED, [joint_id], gripper_id=gripper_id
2423+
)
2424+
2425+
def set_hand_gripper_pinch_action(self, gripper_id, pinch_mode):
2426+
""" Set the pinching action of the gripper
2427+
2428+
Args:
2429+
gripper_id (int): 1 ~ 254
2430+
pinch_mode (int):
2431+
0 - Index finger and thumb pinch
2432+
1 - Middle finger and thumb pinch
2433+
2 - Three-finger grip
2434+
3 - Two-finger grip
2435+
"""
2436+
return self.__set_tool_fittings_value(
2437+
FingerGripper.SET_HAND_GRIPPER_PINCH_ACTION, pinch_mode, gripper_id=gripper_id
2438+
)
2439+
2440+
def set_hand_gripper_p(self, gripper_id, joint_id, value):
2441+
return self.__set_tool_fittings_value(
2442+
FingerGripper.SET_HAND_GRIPPER_P, [joint_id], [value], gripper_id=gripper_id
2443+
)
2444+
2445+
def get_hand_gripper_p(self, gripper_id, joint_id):
2446+
return self.__get_tool_fittings_value(
2447+
FingerGripper.GET_HAND_GRIPPER_P, [joint_id], gripper_id=gripper_id
2448+
)
2449+
2450+
def set_hand_gripper_d(self, gripper_id, joint_id, value):
2451+
return self.__set_tool_fittings_value(
2452+
FingerGripper.SET_HAND_GRIPPER_D, [joint_id], [value], gripper_id=gripper_id
2453+
)
2454+
2455+
def get_hand_gripper_d(self, gripper_id, joint_id):
2456+
return self.__get_tool_fittings_value(
2457+
FingerGripper.GET_HAND_GRIPPER_D, [joint_id], gripper_id=gripper_id
2458+
)
2459+
2460+
def set_hand_gripper_i(self, gripper_id, joint_id, value):
2461+
return self.__set_tool_fittings_value(
2462+
FingerGripper.SET_HAND_GRIPPER_I, [joint_id], [value], gripper_id=gripper_id
2463+
)
2464+
2465+
def get_hand_gripper_i(self, gripper_id, joint_id):
2466+
return self.__get_tool_fittings_value(
2467+
FingerGripper.GET_HAND_GRIPPER_I, [joint_id], gripper_id=gripper_id
2468+
)
2469+
2470+
def set_hand_gripper_min_pressure(self, gripper_id, joint_id, value):
2471+
""" Set the minimum starting force of the single joint of the gripper
2472+
2473+
Args:
2474+
gripper_id (int): 1 ~ 254
2475+
joint_id (int): 1 ~ 6
2476+
value (int): 0 ~ 254
2477+
2478+
"""
2479+
return self.__get_tool_fittings_value(
2480+
FingerGripper.SET_HAND_GRIPPER_MIN_PRESSURE, [joint_id], [value], gripper_id=gripper_id
2481+
)
2482+
2483+
def get_hand_gripper_min_pressure(self, gripper_id, joint_id):
2484+
""" Set the minimum starting force of the single joint of the gripper
2485+
2486+
Args:
2487+
gripper_id (int): 1 ~ 254
2488+
joint_id (int): 1 ~ 6
2489+
2490+
Return:
2491+
min pressure value (int): 0 ~ 254
2492+
2493+
"""
2494+
return self.__get_tool_fittings_value(
2495+
FingerGripper.SET_HAND_GRIPPER_MIN_PRESSURE, [joint_id], gripper_id=gripper_id
2496+
)
2497+
2498+
def set_hand_gripper_clockwise(self, gripper_id, joint_id, value):
2499+
"""
2500+
state: 0 or 1, 0 - disable, 1 - enable
2501+
"""
2502+
return self.__set_tool_fittings_value(
2503+
FingerGripper.SET_HAND_GRIPPER_CLOCKWISE, [joint_id], [value], gripper_id=gripper_id
2504+
)
2505+
2506+
def get_hand_gripper_clockwise(self, gripper_id, joint_id):
2507+
return self.__get_tool_fittings_value(
2508+
FingerGripper.GET_HAND_GRIPPER_CLOCKWISE, joint_id, gripper_id=gripper_id
2509+
)
2510+
2511+
def set_hand_gripper_counterclockwise(self, gripper_id, joint_id, value):
2512+
return self.__set_tool_fittings_value(
2513+
FingerGripper.SET_HAND_GRIPPER_COUNTERCLOCKWISE, [joint_id], [value], gripper_id=gripper_id
2514+
)
2515+
2516+
def get_hand_gripper_counterclockwise(self, gripper_id, joint_id):
2517+
return self.__get_tool_fittings_value(
2518+
FingerGripper.GET_HAND_GRIPPER_COUNTERCLOCKWISE, [joint_id], gripper_id=gripper_id
2519+
)
2520+
2521+
def get_hand_single_pressure_sensor(self, gripper_id, finger_id):
2522+
""" Get the counterclockwise runnable error of the single joint of the gripper
2523+
2524+
Args:
2525+
gripper_id (int): 1 ~ 254
2526+
finger_id (int): 1 ~ 5
2527+
2528+
Return:
2529+
int: 0 ~ 4096
2530+
2531+
"""
2532+
return self.__get_tool_fittings_value(
2533+
FingerGripper.GET_HAND_SINGLE_PRESSURE_SENSOR, [finger_id], gripper_id=gripper_id
2534+
)
2535+
2536+
def get_hand_all_pressure_sensor(self, gripper_id):
2537+
""" Get the counterclockwise runnable error of the single joint of the gripper
2538+
2539+
Args:
2540+
gripper_id (int): 1 ~ 254
2541+
2542+
Return:
2543+
int: 0 ~ 4096
2544+
2545+
"""
2546+
return self.__get_tool_fittings_value(
2547+
FingerGripper.GET_HAND_ALL_PRESSURE_SENSOR, gripper_id=gripper_id
2548+
)
2549+
2550+
def set_hand_gripper_pinch_action_speed_consort(self, gripper_id, pinch_pose, rank_mode, idle_flag=None):
2551+
""" Setting the gripper pinching action-speed coordination
2552+
2553+
Args:
2554+
gripper_id (int): 1 ~ 254
2555+
pinch_pose (int): 0 ~ 4
2556+
0: All joints return to zero
2557+
1: Index finger and thumb pinch together
2558+
2: Middle finger and thumb pinch together
2559+
3: Index finger and middle finger pinch together
2560+
4: Three fingers together
2561+
rank_mode (int): 0 ~ 5
2562+
The degree of closure,the higher the level, the more closed
2563+
idle_flag (int): default None, 0 ~ 4
2564+
Idle flag. By default, there is no such byte. When this byte is 1, the idle finger can be freely manipulated.
2565+
2566+
"""
2567+
if idle_flag is None:
2568+
return self.__set_tool_fittings_value(
2569+
FingerGripper.SET_HAND_GRIPPER_PINCH_ACTION_SPEED_CONSORT, pinch_pose, rank_mode, gripper_id=gripper_id
2570+
)
2571+
else:
2572+
return self.__set_tool_fittings_value(
2573+
FingerGripper.SET_HAND_GRIPPER_PINCH_ACTION_SPEED_CONSORT, pinch_pose, rank_mode, idle_flag, gripper_id=gripper_id
2574+
)
2575+
2576+
2577+

0 commit comments

Comments
 (0)