Skip to content

Commit 4447355

Browse files
committed
update
1 parent beff20e commit 4447355

File tree

8 files changed

+104
-11
lines changed

8 files changed

+104
-11
lines changed

pymycobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from pymycobot.mybuddyemoticon import MyBuddyEmoticon
5353
__all__.append("MyBuddyEmoticon")
5454

55-
__version__ = "3.2.0"
55+
__version__ = "3.2.1"
5656
__author__ = "Elephantrobotics"
5757
__email__ = "weiquan.xu@elephantrobotics.com"
5858
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/cobotx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _mesg(self, genre, *args, **kwargs):
123123
if res[i] == 1:
124124
r.append(i)
125125
return r
126-
elif genre == ProtocolCode.COBOTX_GET_ANGLE:
126+
elif genre in [ProtocolCode.COBOTX_GET_ANGLE, ProtocolCode.GET_SOLUTION_ANGLES]:
127127
return self._int2angle(res[0])
128128
else:
129129
return res
@@ -256,7 +256,7 @@ def sync_send_angles(self, degrees, speed, timeout=15):
256256
time.sleep(0.1)
257257
return self
258258

259-
def sync_send_coords(self, coords, speed, mode=0, timeout=15):
259+
def sync_send_coords(self, coords, speed, mode=None, timeout=15):
260260
"""Send the coord in synchronous state and return when the target point is reached
261261
262262
Args:

pymycobot/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def public_check(parameter_list, kwargs, robot_limit, class_name, exception_clas
159159
raise exception_class("The range of encoder is 0 ~ 4096, but the received value is {}".format(data))
160160
elif parameter == 'speeds':
161161
if "MyCobot" in class_name or "MechArm" in class_name:
162-
if len(value) != 6:
163-
raise exception_class("The length of `speeds` must be 6.")
162+
if len(value) not in [6, 7]:
163+
raise exception_class("The length of `speeds` must be 6. but the received value is {}".format(value))
164164
elif "MyPalletizer" in class_name:
165165
if len(value) != 4:
166166
raise exception_class("The length of `speeds` must be 4.")

pymycobot/myagv.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class ProtocolCode(enum.Enum):
1212
HEADER = 0xFE
13+
RESTORE = [0x01, 0x00]
1314
SET_LED = [0x01, 0x02]
1415
GET_FIRMWARE_VERSION = [0x01, 0x03]
1516
GET_MOTORS_CURRENT = [0x01, 0x04]
@@ -39,6 +40,8 @@ def _read(self, command):
3940
pre = 0
4041
end = 5
4142
t = time.time()
43+
if command[k-1] == 29:
44+
end = 29
4245
while time.time() - t < 0.2:
4346
data = self._serial_port.read()
4447
k += 1
@@ -60,7 +63,7 @@ def _read(self, command):
6063
elif len(datas) >= 2:
6164
data_len = struct.unpack("b", data)[0]
6265
# print("``````:",datas, command, k, data_len)
63-
if data_len == command[k-1]:
66+
if data_len == command[k-1] or command[k-1] == 29:
6467
datas += data
6568
else:
6669
datas = b''
@@ -251,4 +254,26 @@ def stop(self):
251254
"""stop motion
252255
"""
253256
self._mesg(128, 128, 128)
257+
258+
def get_muc_info(self):
259+
""""""
260+
datas = self._read([0xfe, 0xfe, 29])
261+
res = []
262+
for index in range(2, len(datas)):
263+
if index < 5:
264+
res.append(datas[index])
265+
elif index < 17 or index >= 20:
266+
res.append(self._decode_int16(datas[index:index+2]))
267+
elif index == 17:
268+
byte_1 = bin(datas[index])
269+
while len(byte_1) != 6:
270+
byte_1 = "0"+byte_1
271+
res.append(byte_1)
272+
elif index < 20:
273+
res.append(self._int2coord(datas[index]))
274+
return res
275+
276+
def restore(self):
277+
""""""
278+
self._mesg(ProtocolCode.RESTORE.value, 1)
254279

pymycobot/mybuddy.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,37 @@ def open(self):
396396

397397
def is_open(self):
398398
return self._serial_port.is_open
399+
400+
def sync_send_angles(self, id, degrees, speed, timeout=15):
401+
"""Send the angle in synchronous state and return when the target point is reached
402+
403+
Args:
404+
degrees: a list of degree values(List[float]), length 6.
405+
speed: (int) 0 ~ 100
406+
timeout: default 7s.
407+
"""
408+
t = time.time()
409+
self.send_angles(id, degrees, speed)
410+
while time.time() - t < timeout:
411+
f = self.is_in_position(id, degrees, 0)
412+
if f == 1:
413+
break
414+
time.sleep(0.1)
415+
return self
416+
417+
def sync_send_coords(self, id, coords, speed, mode=0, timeout=15):
418+
"""Send the coord in synchronous state and return when the target point is reached
419+
420+
Args:
421+
coords: a list of coord values(List[float])
422+
speed: (int) 0 ~ 100
423+
mode: (int): 0 - angular(default), 1 - linear
424+
timeout: default 7s.
425+
"""
426+
t = time.time()
427+
self.send_coords(id, coords, speed, mode)
428+
while time.time() - t < timeout:
429+
if self.is_in_position(id, coords, 1) == 1:
430+
break
431+
time.sleep(0.1)
432+
return self

pymycobot/mybuddyemoticon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class MyBuddyEmoticon:
10-
def __init__(self, file_path, window_size, loop=False):
10+
def __init__(self, file_path, window_size=None, loop=False):
1111
"""API for playing emoticons
1212
1313
Args:

pymycobot/mybuddysocket.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,37 @@ def wait(self, t):
207207

208208
def close(self):
209209
self.sock.close()
210+
211+
def sync_send_angles(self, id, degrees, speed, timeout=15):
212+
"""Send the angle in synchronous state and return when the target point is reached
213+
214+
Args:
215+
degrees: a list of degree values(List[float]), length 6.
216+
speed: (int) 0 ~ 100
217+
timeout: default 7s.
218+
"""
219+
t = time.time()
220+
self.send_angles(id, degrees, speed)
221+
while time.time() - t < timeout:
222+
f = self.is_in_position(id, degrees, 0)
223+
if f == 1:
224+
break
225+
time.sleep(0.1)
226+
return self
227+
228+
def sync_send_coords(self, id, coords, speed, mode=0, timeout=15):
229+
"""Send the coord in synchronous state and return when the target point is reached
230+
231+
Args:
232+
coords: a list of coord values(List[float])
233+
speed: (int) 0 ~ 100
234+
mode: (int): 0 - angular(default), 1 - linear
235+
timeout: default 7s.
236+
"""
237+
t = time.time()
238+
self.send_coords(id, coords, speed, mode)
239+
while time.time() - t < timeout:
240+
if self.is_in_position(id, coords, 1) == 1:
241+
break
242+
time.sleep(0.1)
243+
return self

pymycobot/robot_limit.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
},
1616
"MyCobot":{
1717
"id":[1,2,3,4,5,6],
18-
"angles_min":[-170, -135, -150, -130, -170, -180],
19-
"angles_max":[170, 135, 150, 135, 170, 180],
18+
"angles_min":[-170, -135, -150, -145, -170, -180],
19+
"angles_max":[170, 140, 150, 135, 170, 180],
2020
"coords_min":[-350, -350, -70, -180, -180, -180],
2121
"coords_max":[350, 350, 523.9, 180, 180, 180]
2222
},
2323
"MyCobotSocket":{
2424
"id":[1,2,3,4,5,6],
25-
"angles_min":[-165, -135, -150, -130, -170, -180],
26-
"angles_max":[165, 135, 150, 130, 170, 180],
25+
"angles_min":[-170, -135, -150, -145, -170, -180],
26+
"angles_max":[170, 140, 150, 135, 170, 180],
2727
"coords_min":[-350, -350, -70, -180, -180, -180],
2828
"coords_max":[350, 350, 523.9, 180, 180, 180]
2929
},

0 commit comments

Comments
 (0)