Skip to content

Commit 0e8ba89

Browse files
author
Leonid Fedorenchik
committed
Merge remote-tracking branch 'github/main'
2 parents 3b3ba93 + 0afb2d8 commit 0e8ba89

17 files changed

+211
-116
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ChangeLog for pymycobot
22

3+
## v3.6.5 (2024-10-25)
4+
5+
- release v3.6.5
6+
- Added 280 set_encoders_drag interface
7+
38
## v3.6.4 (2024-10-22)
49

510
- release v3.6.4

pymycobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
from pymycobot.mybuddyemoticon import MyBuddyEmoticon
8686
__all__.append("MyBuddyEmoticon")
8787

88-
__version__ = "3.6.4"
88+
__version__ = "3.6.6"
8989
__author__ = "Elephantrobotics"
9090
__email__ = "weiquan.xu@elephantrobotics.com"
9191
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ProGripper(object):
2222
SET_GRIPPER_PAUSE = 37
2323
SET_GRIPPER_RESUME = 38
2424
SET_GRIPPER_STOP = 39
25+
SET_GRIPPER_ANGLES = 45
2526

2627

2728
class ProtocolCode(object):
@@ -795,6 +796,10 @@ def read(self, genre, method=None, command=None, _class=None, timeout=None):
795796
elif _class in ["MyCobot", "MyCobotSocket", "MyCobot320", "MyCobot320Socket"]:
796797
if genre == ProtocolCode.GET_ROBOT_STATUS:
797798
wait_time = 75
799+
elif genre == ProtocolCode.GET_ROBOT_STATUS:
800+
wait_time = 90
801+
elif genre == ProtocolCode.SET_SSID_PWD or genre == ProtocolCode.GET_SSID_PWD:
802+
wait_time = 0.05
798803
data = b""
799804

800805
if method is not None:

pymycobot/error.py

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -787,41 +787,63 @@ def calibration_parameters(**kwargs):
787787
"The range of 'torque_value' in {} is 100 ~ 300, but the received value is {}".format(parameter,
788788
torque_value))
789789

790-
elif parameter == "gripper_speed":
791-
gripper_id, speed = value
792-
if not isinstance(gripper_id, int) or not isinstance(speed, int):
793-
raise MyCobot320DataException(
794-
"Both 'gripper_id' and 'speed' in {} must be integers".format(parameter))
795-
if gripper_id < 1 or gripper_id > 254:
796-
raise MyCobot320DataException(
797-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
798-
gripper_id))
799-
if speed < 1 or torque_value > 100:
800-
raise MyCobot320DataException(
801-
"The range of 'speed' in {} is 1 ~ 100, but the received value is {}".format(parameter,
802-
speed))
803-
elif parameter == "set_gripper_args":
804-
if len(value) != 3:
805-
raise ValueError(f"Expected 3 arguments, but got {len(value)}")
806-
gripper_id, address, data = value
807-
if not isinstance(gripper_id, int) or not isinstance(address, int) or not isinstance(data, int):
808-
raise MyCobot320DataException(
809-
"All arguments in {} must be integers".format(parameter))
810-
if gripper_id < 1 or gripper_id > 254:
811-
raise MyCobot320DataException(
812-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
813-
gripper_id))
814-
invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 27, 28, 32, 33,
815-
36,
816-
37, 38, 39, 40, 42, 44]
817-
if address < 1 or address > 44:
790+
elif parameter == "gripper_speed":
791+
gripper_id, speed = value
792+
if not isinstance(gripper_id, int) or not isinstance(speed, int):
793+
raise MyCobot320DataException(
794+
"Both 'gripper_id' and 'speed' in {} must be integers".format(parameter))
795+
if gripper_id < 1 or gripper_id > 254:
796+
raise MyCobot320DataException(
797+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
798+
gripper_id))
799+
if speed < 1 or speed > 100:
800+
raise MyCobot320DataException(
801+
"The range of 'speed' in {} is 1 ~ 100, but the received value is {}".format(parameter,
802+
speed))
803+
elif parameter == "joint_id":
804+
check_value_type(parameter, value_type, MyCobot320DataException, int)
805+
if not 0 <= value <= 6:
806+
raise MyCobot320DataException(
807+
"speed value not right, should be 1 ~ 100, the received speed is %s"
808+
% value
809+
)
810+
elif parameter == "set_gripper_args":
811+
gripper_id, address, data = value
812+
if not isinstance(gripper_id, int) or not isinstance(address, int):
813+
raise MyCobot320DataException(
814+
"All arguments in {} must be integers".format(parameter))
815+
if gripper_id < 1 or gripper_id > 254:
816+
raise MyCobot320DataException(
817+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
818+
gripper_id))
819+
invalid_addresses = [1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 27, 28, 32, 33,
820+
36,
821+
37, 38, 39, 40, 42, 44]
822+
if address < 1 or address > 48:
823+
raise MyCobot320DataException(
824+
"The range of 'address' in {} is 1 ~ 48, but the received value is {}".format(parameter,
825+
address))
826+
if address in invalid_addresses:
827+
raise MyCobot320DataException(
828+
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
829+
parameter, invalid_addresses, address))
830+
print('data:', data)
831+
if isinstance(data, list):
832+
# 处理 data 为列表的情况
833+
if len(data) != 6:
818834
raise MyCobot320DataException(
819-
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
820-
address))
821-
if address in invalid_addresses:
835+
"data must be a list of length 6。"
836+
)
837+
for index, value in enumerate(data):
838+
if not (0 <= value <= 100):
839+
raise MyCobot320DataException(
840+
"Each value in the data list must be between 0 and 100. Error index {}: The received value is {}".format(index, value)
841+
)
842+
else:
843+
if not isinstance(data, int):
822844
raise MyCobot320DataException(
823-
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
824-
parameter, invalid_addresses, address))
845+
"The parameter {} must be an integer".format(data)
846+
)
825847
# 根据 address 来处理 value
826848
if address in [3, 43]:
827849
if data < 1 or data > 254:
@@ -849,24 +871,24 @@ def calibration_parameters(**kwargs):
849871
"Error in parameter '{}': The range of 'value' for address={} is 0 ~ 100, but the received value is {}".format(
850872
parameter, address, data))
851873

852-
elif parameter == "get_gripper_args":
853-
gripper_id, address = value
854-
if not isinstance(gripper_id, int) or not isinstance(address, int):
855-
raise MyCobot320DataException(
856-
"All arguments in {} must be integers".format(parameter))
857-
if gripper_id < 1 or gripper_id > 254:
858-
raise MyCobot320DataException(
859-
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
860-
gripper_id))
861-
invalid_addresses = [5, 6, 10, 15, 16, 17, 18, 19, 20, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43]
862-
if address < 1 or address > 44:
863-
raise MyCobot320DataException(
864-
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
865-
address))
866-
if address in invalid_addresses:
867-
raise MyCobot320DataException(
868-
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
869-
parameter, invalid_addresses, address))
874+
elif parameter == "get_gripper_args":
875+
gripper_id, address = value
876+
if not isinstance(gripper_id, int) or not isinstance(address, int):
877+
raise MyCobot320DataException(
878+
"All arguments in {} must be integers".format(parameter))
879+
if gripper_id < 1 or gripper_id > 254:
880+
raise MyCobot320DataException(
881+
"The range of 'gripper_id' in {} is 1 ~ 254, but the received value is {}".format(parameter,
882+
gripper_id))
883+
invalid_addresses = [5, 6, 10, 15, 16, 17, 18, 19, 20, 21, 23, 25, 29, 30, 31, 34, 35, 41, 43]
884+
if address < 1 or address > 44:
885+
raise MyCobot320DataException(
886+
"The range of 'address' in {} is 1 ~ 44, but the received value is {}".format(parameter,
887+
address))
888+
if address in invalid_addresses:
889+
raise MyCobot320DataException(
890+
"'address' in {} cannot be one of the following values: {}, but the received value is {}".format(
891+
parameter, invalid_addresses, address))
870892
elif class_name in ["MechArm", "MechArmSocket"]:
871893
public_check(parameter_list, kwargs, robot_limit, class_name, MechArmDataException)
872894
elif class_name in ["MechArm270", "MechArmSocket"]:
@@ -1154,7 +1176,7 @@ def calibration_parameters(**kwargs):
11541176
elif parameter == 'gripper_type':
11551177
check_0_or_1(parameter, value, [1, 3, 4], value_type, MyPalletizer260DataException, int)
11561178
elif parameter == '_type_1':
1157-
check_0_or_1(parameter, value, [1, 2, 3, 4], value_type, MyPalletizer260DataException, int)
1179+
check_0_or_1(parameter, value, [1, 2, 3, 4, 5], value_type, MyPalletizer260DataException, int)
11581180
# if value not in [0, 1, 10]:
11591181
# raise exception_class("The data supported by parameter {} is 0 or 1 or 10, but the received value is {}".format(parameter, value))
11601182
elif parameter == 'gripper_value':

pymycobot/generate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@ def get_encoders(self):
343343
"""
344344
return self._mesg(ProtocolCode.GET_ENCODERS, has_reply=True)
345345

346+
def set_encoders_drag(self, encoders, speeds): # TODO 22-5-19 need test
347+
"""Send all encoders and speeds
348+
349+
Args:
350+
encoders: encoders list.
351+
speeds: Obtained by the get_servo_speeds() method
352+
"""
353+
self.calibration_parameters(class_name=self.__class__.__name__, encoders=encoders, speeds=speeds)
354+
return self._mesg(ProtocolCode.SET_ENCODERS_DRAG, encoders, speeds)
355+
346356
# Running status and Settings
347357

348358
def get_joint_min_angle(self, joint_id):

pymycobot/mecharm270.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,24 @@ def _mesg(self, genre, *args, **kwargs):
131131
return self._res(real_command, has_reply, genre)
132132

133133
def _res(self, real_command, has_reply, genre):
134-
try_count = 0
135-
while try_count < 3:
134+
if genre == ProtocolCode.SET_SSID_PWD or genre == ProtocolCode.GET_SSID_PWD:
136135
self._write(self._flatten(real_command))
137136
data = self._read(genre)
138-
if data is not None and data != b'':
139-
break
140-
try_count += 1
141137
else:
142-
return -1
138+
try_count = 0
139+
while try_count < 3:
140+
self._write(self._flatten(real_command))
141+
data = self._read(genre)
142+
if data is not None and data != b'':
143+
break
144+
try_count += 1
145+
else:
146+
return -1
143147
if genre == ProtocolCode.SET_SSID_PWD:
144-
return None
148+
return 1
145149
res = self._process_received(data, genre)
150+
if res is None:
151+
return None
146152
if res is not None and isinstance(res, list) and len(res) == 1 and genre not in [ProtocolCode.GET_BASIC_VERSION,
147153
ProtocolCode.GET_JOINT_MIN_ANGLE,
148154
ProtocolCode.GET_JOINT_MAX_ANGLE,

pymycobot/mecharmsocket.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,23 @@ def _mesg(self, genre, *args, **kwargs):
124124
# [254,...,255]
125125
# data = self._write(self._flatten(real_command), "socket")
126126
with self.lock:
127-
try_count = 0
128-
while try_count < 3:
127+
if genre == ProtocolCode.SET_SSID_PWD or genre == ProtocolCode.GET_SSID_PWD:
129128
self._write(self._flatten(real_command), "socket")
130129
data = self._read(genre, method='socket')
131-
if data is not None and data != b'':
132-
break
133-
try_count += 1
134130
else:
135-
return -1
131+
try_count = 0
132+
while try_count < 3:
133+
self._write(self._flatten(real_command), "socket")
134+
data = self._read(genre, method='socket')
135+
if data is not None and data != b'':
136+
break
137+
try_count += 1
138+
else:
139+
return -1
136140
if genre == ProtocolCode.SET_SSID_PWD:
137-
return None
141+
return 1
138142
res = self._process_received(data, genre)
139-
if res == []:
143+
if res is None:
140144
return None
141145
elif res is not None and isinstance(res, list) and len(res) == 1 and genre not in [
142146
ProtocolCode.GET_BASIC_VERSION,

pymycobot/myarmm.py

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

77
class MyArmM(MyArmAPI):
88

9-
def __init__(self, port, baudrate="115200", timeout=0.1, debug=False):
9+
def __init__(self, port, baudrate="1000000", timeout=0.1, debug=False):
1010
super(MyArmM, self).__init__(port, baudrate, timeout,debug)
1111

1212
def set_joint_angle(self, joint_id, angle, speed):

pymycobot/mybuddy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _mesg(self, genre, *args, **kwargs):
134134
if has_reply:
135135
data = self._read()
136136
res = self._process_received(data, genre, arm=12)
137-
if res == []:
137+
if res is None:
138138
return None
139139
if genre in [
140140
ProtocolCode.ROBOT_VERSION,

pymycobot/mybuddysocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _mesg(self, genre, *args, **kwargs):
8686
if has_reply:
8787
data = self._read(genre, 'socket')
8888
res = self._process_received(data, genre, arm=12)
89-
if res == []:
89+
if res is None:
9090
return None
9191
if genre in [
9292
ProtocolCode.ROBOT_VERSION,

0 commit comments

Comments
 (0)