Skip to content

Commit d3adff1

Browse files
committed
feat: add basic control api, remove set_led_color
* fix typo
1 parent 19e7fe6 commit d3adff1

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

pymycobot/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class Command():
5959
IS_GRIPPER_MOVING = 0x69
6060
SET_COLOR = 0x6a
6161

62+
# Baisc
63+
SET_BASIC_OUTPUT = 0xa0
64+
6265

6366
class MyCobotData():
6467
# Functional approach

pymycobot/mycobot.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sys.path.append('.')
33
import time, serial, math
44

5-
from pymycobot.error import MyCobotDataException, check_parameters
5+
from pymycobot.error import check_parameters
66
from pymycobot.common import Command, MyCobotData
77

88

@@ -22,10 +22,12 @@ class MyCobot(MyCobotData):
2222
get_angles()
2323
send_angle()
2424
send_angles()
25+
sync_send_angles() *
2526
get_radians()
2627
send_radians()
2728
get_coords()
2829
send_coords()
30+
sync_send_coords() *
2931
pause()
3032
resume()
3133
stop()
@@ -64,6 +66,11 @@ class MyCobot(MyCobotData):
6466
set_gripper_ini()
6567
is_gripper_moving()
6668
69+
# Basic
70+
set_basic_output() *
71+
72+
73+
# Other
6774
wait() *
6875
'''
6976

@@ -120,8 +127,8 @@ def __mesg(self, genre, *args, **kwargs):
120127
Args:
121128
genre: command type (Command)
122129
*args: other data.
123-
It is converted to octal by default.
124-
If the data needs to be encapsulated into hexadecimal,
130+
It is converted to octal by default.
131+
If the data needs to be encapsulated into hexadecimal,
125132
the array is used to include them. (Data cannot be nested)
126133
**kwargs: support `has_reply`
127134
has_reply: Whether there is a return value to accept.
@@ -343,7 +350,7 @@ def is_in_position(self, data, id):
343350
elif id == 0:
344351
data_list = [self._angle_to_int(i) for i in data]
345352
else:
346-
raise MyCobotDataException("id is not right, please input 0 or 1")
353+
raise Exception("id is not right, please input 0 or 1")
347354

348355
received = self.__mesg(Command.IS_IN_POSITION,
349356
data_list,
@@ -462,27 +469,6 @@ def set_color(self, r=0, g=0, b=0):
462469
self.__mesg(Command.SET_COLOR, r, g, b)
463470
return self
464471

465-
def set_led_color(self, rgb):
466-
'''Set the light color
467-
468-
Args:
469-
rgs (str): example 'ff0000'
470-
471-
'''
472-
if len(rgb) != 6:
473-
raise MyCobotDataException('rgb format should be like: "FF0000"')
474-
475-
# data = list(bytearray(rgb))
476-
# self.__mesg(Command.SET_COLOR, data=data)
477-
command = 'fefe056a{}fa'.format(rgb)
478-
if self._version == 2:
479-
command = command.decode('hex')
480-
elif self._version == 3:
481-
command = bytes.fromhex(command)
482-
self._serial_port.write(command)
483-
self._serial_port.flush()
484-
time.sleep(0.05)
485-
486472
def set_pin_mode(self, pin_no, pin_mode):
487473
'''
488474
@@ -533,11 +519,11 @@ def set_gripper_value(self, value, speed):
533519
'''Set gripper value
534520
535521
Args:
536-
value (int): 0 ~ 496
522+
value (int): 0 ~ 4096
537523
speed (int): 0 ~ 100
538524
539525
'''
540-
self.__mesg(Command.SET_GRIPPER_VALUE, value, speed)
526+
self.__mesg(Command.SET_GRIPPER_VALUE, [value], speed)
541527

542528
def set_gripper_ini(self):
543529
'''Set the current position to zero
@@ -559,6 +545,18 @@ def is_gripper_moving(self):
559545
return self._process_single(
560546
self.__mesg(Command.IS_GRIPPER_MOVING, has_reply=True))
561547

548+
# Baisc
549+
def set_basic_output(self, pin_no, pin_signal):
550+
'''
551+
552+
Args:
553+
pin_signal: 0 / 1
554+
555+
'''
556+
self.__mesg(Command.SET_BASIC_OUTPUT, pin_no, pin_signal)
557+
return self
558+
559+
# Other
562560
def wait(self, t):
563561
time.sleep(t)
564562
return self

0 commit comments

Comments
 (0)