Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anla-xu committed Aug 2, 2022
1 parent 2095d3f commit f83bb31
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
64 changes: 48 additions & 16 deletions pymycobot/Interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding=utf-8
from re import I
from pymycobot.common import ProtocolCode
from pymycobot.generate import MyCobotCommandGenerator

Expand Down Expand Up @@ -136,8 +137,8 @@ def set_fresh_mode(self, id, mode):
Args:
id: 1/2 (L/R).\n
mode: int
0 - Always execute the latest command first.
1 - Execute instructions sequentially in the form of a queue.
1 - Always execute the latest command first.
0 - Execute instructions sequentially in the form of a queue.
"""
return self._mesg(ProtocolCode.SET_FRESH_MODE, id, mode)

Expand All @@ -157,7 +158,8 @@ def is_free_mode(self, id):
id: 0/1/2/3 (ALL/L/R/W)
Return:
0/1
0 - No
1 - Yes
"""
return self._process_single(
self._mesg(ProtocolCode.IS_FREE_MODE, id, has_reply=True)
Expand Down Expand Up @@ -293,12 +295,12 @@ def stop(self, id):
"""
return self._mesg(ProtocolCode.STOP, id)

def is_in_position(self, id, data, mode): # TODO 通信协议可能有问题,待完善
def is_in_position(self, id, data: list, mode): # TODO 通信协议可能有问题,待完善
"""Judge whether in the position.
Args:
id: 0/1/2/3 (ALL/L/R/W).
data: A data list, angles or coords. If id is 1/2. data length is 6. If id is 0. data len 13. if id is 3. data len 1
data: A data list, angles or coords. If id is 1/2. data length is 6. If id is 0. data len 13 (data==[[left_angles/left_coords],[right_angles/right_coords],[waist_angle/waist_coord]]). if id is 3. data len 1
mode: 1 - coords, 0 - angles
Expand All @@ -307,20 +309,45 @@ def is_in_position(self, id, data, mode): # TODO 通信协议可能有问题,
0 - False
-1 - Error
"""
# TODO 22-8-2 need test
data_list = []
if mode == 1:
# self.calibration_parameters(coords=data)
data_list = []
for idx in range(3):
data_list.append(self._coord2int(data[idx]))
for idx in range(3, 6):
data_list.append(self._angle2int(data[idx]))
if len(data) == 3:
for i in data:
# if isinstance(i, list):
if len(i) == 6:
for idx in range(3):
data_list.append(self._coord2int(i[idx]))
for idx in range(3, 6):
data_list.append(self._angle2int(i[idx]))
elif len(i) == 1:
data_list.append(self._coord2int(i[0]))
elif len(data) == 6:
for idx in range(3):
data_list.append(self._coord2int(data[idx]))
for idx in range(3, 6):
data_list.append(self._angle2int(data[idx]))
elif len(data) == 1:
data_list.append(self._coord2int(data[0]))
elif mode == 0:
# self.calibration_parameters(degrees=data)
data_list = [self._angle2int(i) for i in data]
if len(data) == 3:
for i in data:
# if isinstance(i, list):
if len(i) == 6:
for idx in range(6):
data_list.append(self._angle2int(i[idx]))
elif len(i) == 1:
data_list.append(self._angle2int(i[0]))
elif len(data) == 6:
for idx in range(6):
data_list.append(self._angle2int(data[idx]))
elif len(data) == 1:
data_list.append(self._angle2int(data[0]))
else:
raise Exception("id is not right, please input 0 or 1")

return self._mesg(ProtocolCode.IS_IN_POSITION, data_list, id, has_reply=True)
return self._mesg(ProtocolCode.IS_IN_POSITION, id, data_list, mode, has_reply=True)

def is_moving(self, id):
"""Detect if the robot is moving
Expand Down Expand Up @@ -462,7 +489,7 @@ def get_acceleration(self, id):
return self._mesg(ProtocolCode.GET_ACCELERATION, id, has_reply=True)

def set_acceleration(self, id, acc):
"""Read acceleration during all moves
"""Set acceleration during all moves
Args:
id: 1/2/3 (L/R/W)
Expand Down Expand Up @@ -865,7 +892,7 @@ def get_plan_acceleration(self, id = 0):
id: 0/1/2/3 (ALL/L/R/W)
Return:
[movel planning acceleration, movej planning acceleration].
acceleration value.
"""
return self._mesg(ProtocolCode.GET_PLAN_ACCELERATION, id, has_reply=True)

Expand Down Expand Up @@ -1038,7 +1065,12 @@ def collision_switch(self, state):
return self._mesg(ProtocolCode.COLLISION_SWITCH, state)

def is_collision_on(self):
"""Get collision detection status"""
"""Get collision detection status
Args:
0 - close
1 - open
"""
return self._mesg(ProtocolCode.IS_COLLISION_ON, 0, has_reply = True)


Expand Down
4 changes: 2 additions & 2 deletions pymycobot/mybuddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def set_gpio_output(self, pin, v):
"""
self.gpio.output(pin, v)

def set_gpio_input(self, pin):
"""Set GPIO input value.
def get_gpio_input(self, pin):
"""Get GPIO input value.
Args:
pin: (int)pin number.
Expand Down

0 comments on commit f83bb31

Please sign in to comment.