Skip to content

Commit 868e098

Browse files
committed
add myarmc
1 parent 5b1c0d7 commit 868e098

File tree

4 files changed

+545
-46
lines changed

4 files changed

+545
-46
lines changed

pymycobot/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pymycobot.mercurychassis import MercuryChassis
2727
from pymycobot.mercurysocket import MercurySocket
2828
from pymycobot.mycobotpro630 import Phoenix
29+
from pymycobot.myarmc import MyArmC
2930

3031
__all__ = [
3132
"MyCobot",
@@ -50,7 +51,8 @@
5051
"MyArmSocket",
5152
"MercuryChassis",
5253
"MercurySocket",
53-
"Phoenix"
54+
"Phoenix",
55+
"MyArmC"
5456
]
5557

5658

pymycobot/common.py

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,29 @@ class ProtocolCode(object):
216216
MERCURY_DRAG_TECH_PAUSE = 0x72
217217
MERCURY_DRAG_TEACH_CLEAN = 0x73
218218

219+
GET_ROBOT_MODIFIED_VERSION = 1
220+
GET_ROBOT_FIRMWARE_VERSION = 2
221+
GET_ROBOT_AUXILIARY_FIRMWARE_VERSION = 3
222+
GET_ROBOT_ATOM_MODIFIED_VERSION = 4
223+
GET_ROBOT_TOOL_FIRMWARE_VERSION = 9
224+
GET_ROBOT_SERIAL_NUMBER = 5
225+
SET_ROBOT_ERROR_CHECK_STATE = 6
226+
GET_ROBOT_ERROR_CHECK_STATE = 7
227+
GET_ROBOT_ERROR_STATUS = 0x15
228+
GET_ATOM_PRESS_STATUS = 0x6b
229+
GET_ATOM_LED_COLOR = 0x6a
230+
SET_ATOM_PIN_STATUS = 0x61
231+
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
236+
SET_SERVO_MOTOR_CLOCKWISE = 0x73
237+
GET_SERVO_MOTOR_CLOCKWISE = 0Xea
238+
SET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0x74
239+
GET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0xeb
240+
SET_SERVO_MOTOR_CONFIG = 0x52
241+
GET_SERVO_MOTOR_CONFIG = 0x53
219242
GET_BASE_COORDS = 0xF0
220243
BASE_TO_SINGLE_COORDS = 0xF1
221244
COLLISION = 0xF2
@@ -265,6 +288,47 @@ class ProtocolCode(object):
265288

266289

267290
class DataProcessor(object):
291+
def _mesg(self, genre, *args, **kwargs):
292+
"""
293+
Args:
294+
genre: command type (Command)
295+
*args: other data.
296+
It is converted to octal by default.
297+
If the data needs to be encapsulated into hexadecimal,
298+
the array is used to include them. (Data cannot be nested)
299+
**kwargs: support `has_reply`
300+
has_reply: Whether there is a return value to accept.
301+
"""
302+
command_data = self._process_data_command(genre, self.__class__.__name__, args)
303+
304+
if genre == 178:
305+
# 修改wifi端口
306+
command_data = self._encode_int16(command_data)
307+
308+
elif genre in [76, 77]:
309+
command_data = [command_data[0]] + self._encode_int16(command_data[1]*10)
310+
elif genre == 115 and self.__class__.__name__ not in ["MyArmC", "MyArmM"]:
311+
command_data = [command_data[1],command_data[3]]
312+
LEN = len(command_data) + 2
313+
314+
command = [
315+
ProtocolCode.HEADER,
316+
ProtocolCode.HEADER,
317+
LEN,
318+
genre,
319+
]
320+
if command_data:
321+
command.extend(command_data)
322+
if self.__class__.__name__ in ["Mercury", "MercurySocket"]:
323+
command[2] += 1
324+
command.extend(self.crc_check(command))
325+
else:
326+
command.append(ProtocolCode.FOOTER)
327+
328+
real_command = self._flatten(command)
329+
has_reply = kwargs.get("has_reply", False)
330+
return real_command, has_reply
331+
268332
# Functional approach
269333
def _encode_int8(self, data):
270334
return struct.pack("b", data)
@@ -572,7 +636,7 @@ def write(self, command, method=None):
572636
self._serial_port.flush()
573637

574638

575-
def read(self, genre, method=None, command=None, _class=None):
639+
def read(self, genre, method=None, command=None, _class=None, timeout=None):
576640
datas = b""
577641
data_len = -1
578642
k = 0
@@ -581,8 +645,8 @@ def read(self, genre, method=None, command=None, _class=None):
581645
wait_time = 0.1
582646
if method is not None:
583647
wait_time = 0.3
584-
if genre == ProtocolCode.GO_ZERO:
585-
wait_time = 120
648+
if timeout is not None:
649+
wait_time = timeout
586650
if _class in ["Mercury", "MercurySocket"]:
587651
if genre == ProtocolCode.POWER_ON:
588652
wait_time = 8
@@ -677,4 +741,4 @@ def read(self, genre, method=None, command=None, _class=None):
677741
command_log += hex(d)[2:] + " "
678742
self.log.debug("_read : {}".format(command_log))
679743

680-
return datas
744+
return datas

pymycobot/generate.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,6 @@ def __init__(self, debug=False):
9494
self.log = logging.getLogger(__name__)
9595
self.calibration_parameters = calibration_parameters
9696

97-
def _mesg(self, genre, *args, **kwargs):
98-
"""
99-
Args:
100-
genre: command type (Command)
101-
*args: other data.
102-
It is converted to octal by default.
103-
If the data needs to be encapsulated into hexadecimal,
104-
the array is used to include them. (Data cannot be nested)
105-
**kwargs: support `has_reply`
106-
has_reply: Whether there is a return value to accept.
107-
"""
108-
command_data = self._process_data_command(genre, self.__class__.__name__, args)
109-
110-
if genre == 178:
111-
# 修改wifi端口
112-
command_data = self._encode_int16(command_data)
113-
114-
elif genre in [76, 77]:
115-
command_data = [command_data[0]] + self._encode_int16(command_data[1]*10)
116-
elif genre == 115:
117-
command_data = [command_data[1],command_data[3]]
118-
LEN = len(command_data) + 2
119-
120-
command = [
121-
ProtocolCode.HEADER,
122-
ProtocolCode.HEADER,
123-
LEN,
124-
genre,
125-
]
126-
if command_data:
127-
command.extend(command_data)
128-
if self.__class__.__name__ in ["Mercury", "MercurySocket"]:
129-
command[2] += 1
130-
command.extend(self.crc_check(command))
131-
else:
132-
command.append(ProtocolCode.FOOTER)
133-
134-
real_command = self._flatten(command)
135-
has_reply = kwargs.get("has_reply", False)
136-
return real_command, has_reply
137-
13897
# System status
13998
def get_robot_version(self): # TODO: test method <2021-03-11, yourname> #
14099
"""Get cobot version

0 commit comments

Comments
 (0)