Skip to content

Commit ef54a5f

Browse files
authored
Merge pull request #105 from elephantrobotics/mycobot_280_refactor
Mycobot 280 refactor
2 parents fb9edb4 + c303a6a commit ef54a5f

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

pymycobot/common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def write(self, command, method=None):
768768
self._serial_port.flush()
769769

770770

771-
def read(self, genre, method=None, command=None, _class=None, timeout=None):
771+
def read(self, genre, method=None, command=None, _class=None, timeout=None, real_command=None):
772772
datas = b""
773773
data_len = -1
774774
k = 0
@@ -800,9 +800,16 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None):
800800
wait_time = 90
801801
elif genre == ProtocolCode.SET_SSID_PWD or genre == ProtocolCode.GET_SSID_PWD:
802802
wait_time = 0.05
803+
if real_command:
804+
if genre == ProtocolCode.SET_TOQUE_GRIPPER:
805+
if real_command[6] == 13:
806+
wait_time = 3
803807
data = b""
804-
805808
if method is not None:
809+
if real_command:
810+
if genre == ProtocolCode.SET_TOQUE_GRIPPER:
811+
if real_command[6] == 13:
812+
wait_time = 3
806813
if genre == 177:
807814
while True:
808815
data = self.sock.recv(1024)

pymycobot/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def calibration_parameters(**kwargs):
795795
raise MyCobot320DataException(
796796
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
797797
gripper_id))
798-
if torque_value < 100 or torque_value > 300:
798+
if torque_value < 0 or torque_value > 100:
799799
raise MyCobot320DataException(
800800
"The range of 'torque_value' in {} is 100 ~ 300, but the received value is {}".format(parameter,
801801
torque_value))

pymycobot/mycobot320.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _res(self, real_command, has_reply, genre):
154154
try_count = 0
155155
while try_count < 3:
156156
self._write(self._flatten(real_command))
157-
data = self._read(genre)
157+
data = self._read(genre, real_command=real_command)
158158
if data is not None and data != b'':
159159
break
160160
try_count += 1
@@ -165,6 +165,11 @@ def _res(self, real_command, has_reply, genre):
165165
res = self._process_received(data, genre)
166166
if res is None:
167167
return None
168+
if genre == ProtocolCode.SET_TOQUE_GRIPPER:
169+
if res == [0]:
170+
self._write(self._flatten(real_command))
171+
data = self._read(genre, real_command=real_command)
172+
res = self._process_received(data, genre)
168173
if res is not None and isinstance(res, list) and len(res) == 1 and genre not in [ProtocolCode.GET_BASIC_VERSION,
169174
ProtocolCode.GET_JOINT_MIN_ANGLE,
170175
ProtocolCode.GET_JOINT_MAX_ANGLE,
@@ -201,6 +206,10 @@ def _res(self, real_command, has_reply, genre):
201206
]:
202207
return self._process_single(res)
203208
elif genre in [ProtocolCode.GET_TOQUE_GRIPPER]:
209+
if res[-1] == 255 and res[-2] == 255:
210+
self._write(self._flatten(real_command))
211+
data = self._read(genre)
212+
res = self._process_received(data, genre)
204213
return self._process_high_low_bytes(res)
205214
elif genre in [ProtocolCode.GET_ANGLES]:
206215
return [self._int2angle(angle) for angle in res]

pymycobot/mycobot320socket.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _mesg(self, genre, *args, **kwargs):
145145
try_count = 0
146146
while try_count < 3:
147147
self._write(self._flatten(real_command), "socket")
148-
data = self._read(genre, method='socket')
148+
data = self._read(genre, method='socket', real_command=real_command)
149149
if data is not None and data != b'':
150150
break
151151
try_count += 1
@@ -156,7 +156,12 @@ def _mesg(self, genre, *args, **kwargs):
156156
res = self._process_received(data, genre)
157157
if res is None:
158158
return None
159-
elif res is not None and isinstance(res, list) and len(res) == 1 and genre not in [
159+
if genre == ProtocolCode.SET_TOQUE_GRIPPER:
160+
if res == [0]:
161+
self._write(self._flatten(real_command))
162+
data = self._read(genre, real_command=real_command)
163+
res = self._process_received(data, genre)
164+
if res is not None and isinstance(res, list) and len(res) == 1 and genre not in [
160165
ProtocolCode.GET_BASIC_VERSION,
161166
ProtocolCode.GET_JOINT_MIN_ANGLE,
162167
ProtocolCode.GET_JOINT_MAX_ANGLE,

0 commit comments

Comments
 (0)