Skip to content

Commit 934f140

Browse files
authored
Merge pull request #56 from Mrkun5018/main
add myarmm and myarmc class api
2 parents f67e7d8 + 4351bd8 commit 934f140

File tree

6 files changed

+619
-22
lines changed

6 files changed

+619
-22
lines changed

pymycobot/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
from pymycobot.mercurychassis import MercuryChassis
2727
from pymycobot.mercurysocket import MercurySocket
2828
from pymycobot.mycobotpro630 import Phoenix
29-
29+
from pymycobot.myarmm import MyArmM
30+
from pymycobot.myarmc import MyArmC
3031
__all__ = [
3132
"MyCobot",
3233
"CommandGenerator",
@@ -50,7 +51,9 @@
5051
"MyArmSocket",
5152
"MercuryChassis",
5253
"MercurySocket",
53-
"Phoenix"
54+
"Phoenix",
55+
"MyArmM",
56+
"MyArmC"
5457
]
5558

5659

pymycobot/common.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,18 @@ class ProtocolCode(object):
229229
GET_ATOM_LED_COLOR = 0x6a
230230
SET_ATOM_PIN_STATUS = 0x61
231231
GET_ATOM_PIN_STATUS = 0x62
232-
SET_MASTER_PIN_STATUS = 0x61
233-
GET_MASTER_PIN_STATUS = 0x62
234-
SET_AUXILIARY_PIN_STATUS = 0x63
235-
GET_AUXILIARY_PIN_STATUS = 0x64
232+
SET_MASTER_PIN_STATUS = 0x65
233+
GET_MASTER_PIN_STATUS = 0x66
234+
SET_AUXILIARY_PIN_STATUS = 0xa0
235+
GET_AUXILIARY_PIN_STATUS = 0xa1
236236
SET_SERVO_MOTOR_CLOCKWISE = 0x73
237237
GET_SERVO_MOTOR_CLOCKWISE = 0Xea
238238
SET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0x74
239239
GET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0xeb
240240
SET_SERVO_MOTOR_CONFIG = 0x52
241241
GET_SERVO_MOTOR_CONFIG = 0x53
242+
CLEAR_RECV_QUEUE = 0x19
243+
GET_RECV_QUEUE_LENGTH = 0x08
242244
GET_BASE_COORDS = 0xF0
243245
BASE_TO_SINGLE_COORDS = 0xF1
244246
COLLISION = 0xF2
@@ -249,6 +251,9 @@ class ProtocolCode(object):
249251
JOG_INC_COORD = 0xF7
250252
COLLISION_SWITCH = 0xF8
251253
IS_COLLISION_ON = 0xF9
254+
CLEAR_ROBOT_ERROR = 0x16
255+
GET_RECV_QUEUE_SIZE = 0x17
256+
SET_RECV_QUEUE_SIZE = 0x18
252257

253258
# IIC
254259
# SET_IIC_STATE = 0xA4
@@ -300,7 +305,6 @@ def _mesg(self, genre, *args, **kwargs):
300305
has_reply: Whether there is a return value to accept.
301306
"""
302307
command_data = self._process_data_command(genre, self.__class__.__name__, args)
303-
304308
if genre == 178:
305309
# 修改wifi端口
306310
command_data = self._encode_int16(command_data)
@@ -328,7 +332,7 @@ def _mesg(self, genre, *args, **kwargs):
328332
real_command = self._flatten(command)
329333
has_reply = kwargs.get("has_reply", False)
330334
return real_command, has_reply
331-
335+
332336
# Functional approach
333337
def _encode_int8(self, data):
334338
return struct.pack("b", data)
@@ -410,7 +414,7 @@ def _process_data_command(self, genre, _class, args):
410414
byte_value = data.to_bytes(4, byteorder='big', signed=True)
411415
res = []
412416
for i in range(len(byte_value)):
413-
res.append(byte_value[i])
417+
res.append(byte_value[i])
414418
processed_args.extend(res)
415419
else:
416420
processed_args.extend(self._encode_int16(args[index]))
@@ -422,7 +426,7 @@ def _process_data_command(self, genre, _class, args):
422426
byte_value = args[index].to_bytes(2, byteorder='big', signed=True)
423427
res = []
424428
for i in range(len(byte_value)):
425-
res.append(byte_value[i])
429+
res.append(byte_value[i])
426430
processed_args.extend(res)
427431
else:
428432
processed_args.append(args[index])
@@ -446,7 +450,7 @@ def _process_received(self, data, genre, arm=6):
446450
header_i, header_j = 0, 1
447451
while header_j < data_len - 4:
448452
if self._is_frame_header(data, header_i, header_j):
449-
if arm in [6, 7, 14]:
453+
if arm in [6, 7, 14, 8]:
450454
cmd_id = data[header_i + 3]
451455
elif arm == 12:
452456
cmd_id = data[header_i + 4]
@@ -457,7 +461,7 @@ def _process_received(self, data, genre, arm=6):
457461
header_j += 1
458462
else:
459463
return []
460-
if arm in [6, 7]:
464+
if arm in [6, 7, 8]:
461465
data_len = data[header_i + 2] - 2
462466
elif arm == 12:
463467
data_len = data[header_i + 3] - 2
@@ -474,7 +478,7 @@ def _process_received(self, data, genre, arm=6):
474478
data_pos = header_i + 5
475479
data_len -= 1
476480
else:
477-
if arm in [6, 7, 14]:
481+
if arm in [6, 7, 14, 8]:
478482
data_pos = header_i + 4
479483
elif arm == 12:
480484
data_pos = header_i + 5
@@ -487,7 +491,17 @@ def _process_received(self, data, genre, arm=6):
487491
# res.append(i)
488492
# return res
489493
if data_len in [6, 8, 12, 14, 16, 24, 26, 60]:
490-
if data_len == 8 and arm == 14 and cmd_id == ProtocolCode.IS_INIT_CALIBRATION:
494+
ignor_t = (
495+
ProtocolCode.GET_SERVO_CURRENTS,
496+
ProtocolCode.GET_SERVO_TEMPS,
497+
ProtocolCode.GET_SERVO_VOLTAGES,
498+
ProtocolCode.GET_SERVO_STATUS,
499+
ProtocolCode.IS_ALL_SERVO_ENABLE
500+
)
501+
if data_len == 8 and (
502+
(arm == 14 and cmd_id == ProtocolCode.IS_INIT_CALIBRATION) or
503+
(arm == 8 and cmd_id in ignor_t)
504+
):
491505
for v in valid_data:
492506
res.append(v)
493507
return res
@@ -650,7 +664,8 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None):
650664
if _class in ["Mercury", "MercurySocket"]:
651665
if genre == ProtocolCode.POWER_ON:
652666
wait_time = 8
653-
elif genre in [ProtocolCode.POWER_OFF, ProtocolCode.RELEASE_ALL_SERVOS, ProtocolCode.FOCUS_ALL_SERVOS, ProtocolCode.RELEASE_SERVO, ProtocolCode.FOCUS_SERVO, ProtocolCode.STOP]:
667+
elif genre in [ProtocolCode.POWER_OFF, ProtocolCode.RELEASE_ALL_SERVOS, ProtocolCode.FOCUS_ALL_SERVOS,
668+
ProtocolCode.RELEASE_SERVO, ProtocolCode.FOCUS_SERVO, ProtocolCode.STOP]:
654669
wait_time = 3
655670
if method is not None:
656671
if genre == 177:

pymycobot/generate.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ def get_robot_version(self): # TODO: test method <2021-03-11, yourname> #
103103
mycobotPro: 101
104104
"""
105105
return self._mesg(ProtocolCode.ROBOT_VERSION, has_reply=True)
106-
106+
107107
def get_system_version(self):
108108
"""get system version"""
109-
return self._mesg(ProtocolCode.SOFTWARE_VERSION, has_reply = True)
109+
return self._mesg(ProtocolCode.SOFTWARE_VERSION, has_reply=True)
110110

111111
def get_robot_id(self):
112112
"""get robot id"""
113-
return self._mesg(ProtocolCode.GET_ROBOT_ID, has_reply = True)
114-
113+
return self._mesg(ProtocolCode.GET_ROBOT_ID, has_reply=True)
114+
115115
def set_robot_id(self, id):
116116
"""set robot id
117117
@@ -408,7 +408,8 @@ def set_encoder(self, joint_id, encoder, speed):
408408
encoder: The value of the set encoder.
409409
speed : 1 - 100
410410
"""
411-
self.calibration_parameters(class_name = self.__class__.__name__, encode_id = joint_id, encoder = encoder, speed=speed)
411+
self.calibration_parameters(class_name=self.__class__.__name__, encode_id=joint_id, encoder=encoder,
412+
speed=speed)
412413
return self._mesg(ProtocolCode.SET_ENCODER, joint_id, [encoder], speed)
413414

414415
def get_encoder(self, joint_id):
@@ -544,7 +545,8 @@ def set_servo_data(self, servo_id, data_id, value, mode=None):
544545
self.calibration_parameters(class_name = self.__class__.__name__, id=servo_id, address=data_id, value=value)
545546
return self._mesg(ProtocolCode.SET_SERVO_DATA, servo_id, data_id, value)
546547
else:
547-
self.calibration_parameters(class_name = self.__class__.__name__, id=servo_id, address=data_id, value=value, mode=mode)
548+
self.calibration_parameters(class_name=self.__class__.__name__, id=servo_id, address=data_id, value=value,
549+
mode=mode)
548550
return self._mesg(ProtocolCode.SET_SERVO_DATA, servo_id, data_id, [value], mode)
549551

550552
def get_servo_data(self, servo_id, data_id, mode=None):
@@ -729,7 +731,8 @@ def set_gripper_value(self, gripper_value, speed, gripper_type=None):
729731
4: Flexible gripper
730732
"""
731733
if gripper_type is not None:
732-
self.calibration_parameters(class_name = self.__class__.__name__, gripper_value=gripper_value, speed=speed, gripper_type=gripper_type)
734+
self.calibration_parameters(class_name=self.__class__.__name__, gripper_value=gripper_value, speed=speed,
735+
gripper_type=gripper_type)
733736
return self._mesg(ProtocolCode.SET_GRIPPER_VALUE, gripper_value, speed, gripper_type)
734737
else:
735738
return self._mesg(ProtocolCode.SET_GRIPPER_VALUE, gripper_value, speed)

0 commit comments

Comments
 (0)