Skip to content

Commit bbacbdb

Browse files
committed
push code
1 parent 9bcc570 commit bbacbdb

File tree

9 files changed

+99
-8
lines changed

9 files changed

+99
-8
lines changed

pymycobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from pymycobot.mybuddyemoticon import MyBuddyEmoticon
4747
__all__.append("MyBuddyEmoticon")
4848

49-
__version__ = "3.1.6"
49+
__version__ = "3.1.7b2"
5050
__author__ = "Elephantrobotics"
5151
__email__ = "[email protected]"
5252
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/cobotx.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# coding=utf-8
22
from pymycobot import MyArm
3+
from pymycobot.common import ProtocolCode, write, read
4+
35

46
class CobotX(MyArm):
57
def __init__(self, port, baudrate="115200", timeout=0.1, debug=False):
6-
super().__init__(port, baudrate, timeout, debug)
8+
super().__init__(port, baudrate, timeout, debug)
9+
10+
def set_solution_angles(self, angle, speed):
11+
"""Set zero space deflection angle value
12+
13+
Args:
14+
angle: Angle of joint 1.
15+
speed: 1 - 100.
16+
"""
17+
return self._mesg(ProtocolCode.COBOTX_SET_SOLUTION_ANGLES, [self._angle2int(angle)], speed)
18+
19+
def get_solution_angles(self):
20+
"""Get zero space deflection angle value"""
21+
return self._mesg(ProtocolCode.COBOTX_GET_SOLUTION_ANGLES, has_reply=True)

pymycobot/common.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class ProtocolCode(object):
5656
JOG_COORD = 0x32
5757
JOG_INCREMENT = 0x33
5858
JOG_STOP = 0x34
59+
60+
COBOTX_GET_SOLUTION_ANGLES = 0x35
61+
COBOTX_SET_SOLUTION_ANGLES = 0x36
62+
5963
SET_ENCODER = 0x3A
6064
GET_ENCODER = 0x3B
6165
SET_ENCODERS = 0x3C
@@ -148,6 +152,7 @@ class ProtocolCode(object):
148152
SET_PLAN_SPEED = 0xD2
149153
SET_PLAN_ACCELERATION = 0xD3
150154
SET_GSERVO_ROUND = 0xD4
155+
GET_ANGLES_COORDS = 0xD5
151156

152157
# Motor status read
153158
GET_SERVO_SPEED = 0xE1
@@ -284,7 +289,10 @@ def _process_received(self, data, genre, arm=6):
284289
unique_data = [ProtocolCode.GET_BASIC_INPUT, ProtocolCode.GET_DIGITAL_INPUT]
285290

286291
if cmd_id in unique_data:
287-
data_pos = header_i + 5
292+
if arm == 12:
293+
data_pos = header_i + 6
294+
else:
295+
data_pos = header_i + 5
288296
data_len -= 1
289297
else:
290298
if arm == 6:

pymycobot/elephantrobot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def assign_variable(self, var_name, var_value):
253253
def get_variable(self, var_name):
254254
command = 'get_variable("' + str(var_name) + '")\n'
255255
return self.send_command(command)
256+
257+
def jog_relative(self, joint_id, angle, speed):
258+
command = 'SendJogIncrement("' + str(var_name) + '")\n'
259+
return self.send_command(command)
256260

257261

258262
if __name__ == "__main__":

pymycobot/generate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,4 +1053,7 @@ def set_communicate_mode(self, mode):
10531053
Args:
10541054
mode: 0 - Turn off transparent transmission,1 - Open transparent transmission
10551055
"""
1056-
return self._mesg(ProtocolCode.SET_COMMUNICATE_MODE, mode)
1056+
return self._mesg(ProtocolCode.SET_COMMUNICATE_MODE, mode)
1057+
1058+
def get_angles_coords(self):
1059+
return self._mesg(ProtocolCode.GET_ANGLES_COORDS, has_reply = True)

pymycobot/myarm.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ def _mesg(self, genre, *args, **kwargs):
129129
return [self._int2coord(angle) for angle in res]
130130
elif genre in [ProtocolCode.GET_JOINT_MAX_ANGLE, ProtocolCode.GET_JOINT_MIN_ANGLE]:
131131
return self._int2coord(res[0])
132+
elif genre == ProtocolCode.GET_ANGLES_COORDS:
133+
r = []
134+
for index in range(len(res)):
135+
if index < 7:
136+
r.append(self._int2angle(res[index]))
137+
elif index < 10:
138+
r.append(self._int2coord(res[index]))
139+
else:
140+
r.append(self._int2angle(res[index]))
141+
return r
132142
else:
133143
return res
134144
return None
@@ -234,15 +244,15 @@ def release_all_servos(self, data=None):
234244
else:
235245
return self._mesg(ProtocolCode.RELEASE_ALL_SERVOS, data)
236246

237-
def get_transpoendr_mode(self):
247+
def get_transponder_mode(self):
238248
"""Obtain the configuration information of serial transmission mode
239249
240250
Return:
241251
mode: 0 - 1 - 2
242252
"""
243253
return self._mesg(ProtocolCode.SET_SSID_PWD, has_reply=True)
244254

245-
def set_transpoendr_mode(self, mode):
255+
def set_transponder_mode(self, mode):
246256
"""Set serial port transmission mode
247257
248258
Args:
@@ -267,4 +277,34 @@ def set_color(self, r, g, b):
267277
g: Green
268278
b: Blue
269279
"""
270-
return self._mesg(ProtocolCode.SET_COLOR_MYARM, r, g, b)
280+
return self._mesg(ProtocolCode.SET_COLOR_MYARM, r, g, b)
281+
282+
def is_in_position(self, data, id=0):
283+
"""Judge whether in the position. (mypalletizer 340 does not have this interface)
284+
285+
Args:
286+
data: A data list, angles or coords.
287+
for mycobot: len 6.
288+
for mypalletizer: len 4
289+
id: 1 - coords, 0 - angles
290+
291+
Return:
292+
1 - True\n
293+
0 - False\n
294+
-1 - Error
295+
"""
296+
if id == 1:
297+
# self.calibration_parameters(coords=data)
298+
data_list = []
299+
for idx in range(3):
300+
data_list.append(self._coord2int(data[idx]))
301+
for idx in range(3, 6):
302+
data_list.append(self._angle2int(data[idx]))
303+
elif id == 0:
304+
# self.calibration_parameters(degrees=data)
305+
data_list = [self._angle2int(i) for i in data]
306+
else:
307+
raise Exception("id is not right, please input 0 or 1")
308+
return self._mesg(ProtocolCode.IS_IN_POSITION, id, data_list, has_reply=True)
309+
310+

pymycobot/mycobot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ def _mesg(self, genre, *args, **kwargs):
131131
return self._int2coord(res[0])
132132
elif genre in [ProtocolCode.GET_BASIC_VERSION, ProtocolCode.SOFTWARE_VERSION]:
133133
return self._int2coord(self._process_single(res))
134+
elif genre == ProtocolCode.GET_ANGLES_COORDS:
135+
r = []
136+
for index in range(len(res)):
137+
if index < 6:
138+
r.append(self._int2angle(res[index]))
139+
elif index < 9:
140+
r.append(self._int2coord(res[index]))
141+
else:
142+
r.append(self._int2angle(res[index]))
143+
return r
134144
else:
135145
return res
136146
return None
@@ -168,6 +178,7 @@ def sync_send_angles(self, degrees, speed, timeout=7):
168178
self.send_angles(degrees, speed)
169179
while time.time() - t < timeout:
170180
f = self.is_in_position(degrees, 0)
181+
print(f)
171182
if f == 1:
172183
break
173184
time.sleep(0.1)

pymycobot/mycobotsocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, ip, netport=9000):
5959
self.calibration_parameters = calibration_parameters
6060
self.SERVER_IP = ip
6161
self.SERVER_PORT = netport
62-
self.rasp = True
62+
self.rasp = False
6363
self.sock = self.connect_socket()
6464

6565
def connect_socket(self):

pymycobot/mypalletizer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ def _mesg(self, genre, *args, **kwargs):
165165
return self._int2angle(res[0]) if res else 0
166166
elif genre in [ProtocolCode.GET_BASIC_VERSION, ProtocolCode.SOFTWARE_VERSION]:
167167
return self._int2coord(self._process_single(res))
168+
elif genre == ProtocolCode.GET_ANGLES_COORDS:
169+
r = []
170+
for index in range(len(res)):
171+
if index < 4:
172+
r.append(self._int2angle(res[index]))
173+
elif index < 7:
174+
r.append(self._int2coord(res[index]))
175+
else:
176+
r.append(self._int2angle(res[index]))
177+
return r
168178
else:
169179
return res
170180
return None

0 commit comments

Comments
 (0)