Skip to content

Commit beafd66

Browse files
authored
Merge pull request #83 from Mrkun5018/main
The packet loss issue is fixed
2 parents 9424dca + 076f719 commit beafd66

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pymycobot/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class ProtocolCode(object):
264264
RESTORE_SERVO_SYSTEM_PARAM = 0x0a
265265
GET_SERVO_D = 0xE8
266266
SET_SERVO_P = 0x70
267+
GET_SERVO_P = 0xE7
267268
# IIC
268269
# SET_IIC_STATE = 0xA4
269270
# GET_IIS_BYTE = 0xA5
@@ -729,6 +730,7 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None):
729730
wait_time = 1
730731
while True and time.time() - t < wait_time:
731732
data = self._serial_port.read()
733+
self.log.debug("data: {}".format(data))
732734
k += 1
733735
if _class in ["Mercury", "MercurySocket"]:
734736
if data_len == 3:
@@ -743,7 +745,8 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None):
743745
if genre in (
744746
ProtocolCode.GET_ATOM_PRESS_STATUS,
745747
ProtocolCode.GET_SERVO_MOTOR_COUNTER_CLOCKWISE,
746-
ProtocolCode.GET_SERVO_MOTOR_CLOCKWISE
748+
ProtocolCode.GET_SERVO_MOTOR_CLOCKWISE,
749+
ProtocolCode.GET_SERVO_P,
747750
) and _class in ["MyArmM", "MyArmC", "MyArmAPI"]:
748751
break
749752
datas = b''

pymycobot/myarm_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
import logging
77
import threading
8+
import time
9+
810
from pymycobot.common import ProtocolCode, write, read, DataProcessor
911
from pymycobot.error import calibration_parameters
1012
from pymycobot.log import setup_logging
@@ -52,7 +54,7 @@ def _mesg(self, genre, *args, **kwargs):
5254
**kwargs: support `has_reply`
5355
has_reply: Whether there is a return value to accept.
5456
"""
55-
57+
time.sleep(0.01)
5658
real_command, has_reply = super(MyArmAPI, self)._mesg(genre, *args, **kwargs)
5759
command = self._flatten(real_command)
5860
with self.lock:
@@ -284,7 +286,7 @@ def get_servo_p(self, servo_id):
284286
Args:
285287
servo_id (int): 0-254
286288
"""
287-
return self._mesg(ProtocolCode.SERVO_RESTORE, servo_id, has_reply=True)
289+
return self._mesg(ProtocolCode.GET_SERVO_P, servo_id, has_reply=True)
288290

289291
def set_servo_d(self, servo_id, data):
290292
"""Sets the proportional factor for the position ring D of the specified servo motor

0 commit comments

Comments
 (0)