Skip to content

Commit d1b48df

Browse files
author
Leonid Fedorenchik
committed
mycobotpro630: Add pro gripper API
1 parent 81c5d5f commit d1b48df

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ demo/__pycache__/port.cpython-39.pyc
2323
demo/__pycache__/port_setup.cpython-39.pyc
2424
.idea
2525
.vscode
26-
*.log
26+
*.log
27+
.venv/

pymycobot/mycobotpro630.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111
import os
1212
import sys
13+
import crc
1314

1415
from pymycobot.log import setup_logging
1516

@@ -86,7 +87,7 @@ def __init__(self, temperature):
8687
jog_velocity = 1.0 # 100.0/60.0
8788
angular_jog_velocity = 3600 / 60
8889
MAX_PINS = 64
89-
MAX_ANGULAR_SPEED = 6930
90+
MAX_ANGULAR_SPEED = 6500
9091
MAX_LINEAR_SPEED = 30000
9192
DEFAULT_XY_TORQUE_LIMIT = 55
9293
DEFAULT_Z_TORQUE_LIMIT = 30
@@ -2780,6 +2781,58 @@ def tool_set_gripper_mode(self, mode):
27802781
"""
27812782
self._send_can([0x02, 0x6D, mode])
27822783

2784+
def tool_gripper_pro_set_angle(self, angle):
2785+
if angle < 0 or angle > 100:
2786+
return False
2787+
command = [254, 254, 8, 14, 6, 0, 11, 0, angle]
2788+
crc16_value = crc.Calculator(crc.Crc16.MODBUS.value).checksum(bytes(command))
2789+
command.extend([(crc16_value >> 8), (crc16_value & 0xFF)])
2790+
self.tool_serial_write_data(command)
2791+
ret = self.tool_serial_read_data(11)
2792+
return bool(ret[8])
2793+
2794+
def tool_gripper_pro_get_angle(self):
2795+
command = [254, 254, 8, 14, 3, 0, 12, 0, 0]
2796+
crc16_value = crc.Calculator(crc.Crc16.MODBUS.value).checksum(bytes(command))
2797+
command.extend([(crc16_value >> 8), (crc16_value & 0xFF)])
2798+
self.tool_serial_write_data(command)
2799+
ret = self.tool_serial_read_data(11)
2800+
return int((ret[7] << 8) | (ret[8]))
2801+
2802+
def tool_gripper_pro_open(self):
2803+
return self.tool_gripper_pro_set_angle(100)
2804+
2805+
def tool_gripper_pro_close(self):
2806+
return self.tool_gripper_pro_set_angle(0)
2807+
2808+
def tool_gripper_pro_set_torque(self, torque_value):
2809+
if torque_value < 100 or torque_value > 300:
2810+
return False
2811+
command = [
2812+
254,
2813+
254,
2814+
8,
2815+
14,
2816+
6,
2817+
0,
2818+
27,
2819+
(torque_value >> 8),
2820+
(torque_value & 0xFF),
2821+
]
2822+
crc16_value = crc.Calculator(crc.Crc16.MODBUS.value).checksum(bytes(command))
2823+
command.extend([(crc16_value >> 8), (crc16_value & 0xFF)])
2824+
self.tool_serial_write_data(command)
2825+
ret = self.tool_serial_read_data(11)
2826+
return bool(ret[8])
2827+
2828+
def tool_gripper_pro_get_torque(self):
2829+
command = [254, 254, 8, 14, 3, 0, 28, 0, 0]
2830+
crc16_value = crc.Calculator(crc.Crc16.MODBUS.value).checksum(bytes(command))
2831+
command.extend([(crc16_value >> 8), (crc16_value & 0xFF)])
2832+
self.tool_serial_write_data(command)
2833+
ret = self.tool_serial_read_data(11)
2834+
return int((ret[7] << 8) | (ret[8]))
2835+
27832836
def tool_serial_restore(self):
27842837
"""Restore ESP32 serial."""
27852838
self._send_can([0x01, 0xB1])
@@ -2819,7 +2872,7 @@ def tool_serial_read_data(self, n):
28192872
data = []
28202873
msg = self._receive_can()
28212874
data.extend(msg.data[3:])
2822-
while msg is not None:
2875+
while msg is not None and len(data) < n:
28232876
msg = self._receive_can()
28242877
data.extend(msg.data[3:])
28252878
return data

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ python-can
33
pytest
44
flake8
55
opencv-python
6+
crc

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@
8888
"License :: OSI Approved :: MIT License",
8989
"Operating System :: OS Independent",
9090
],
91-
install_requires=["pyserial","python-can"],
91+
install_requires=["pyserial", "python-can", "crc"],
9292
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, != 3.4.*",
9393
)

0 commit comments

Comments
 (0)