Skip to content

Commit c82f67d

Browse files
committed
release v3.1.4
1 parent dd084a5 commit c82f67d

File tree

5 files changed

+331
-6
lines changed

5 files changed

+331
-6
lines changed

CHANGELOG.md

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

3+
# v3.1.4 (2023-7-5)
4+
5+
- release v3.1.4
6+
- Update set_gservo_round() function.
7+
- Add pro 600 interface
8+
39
## v3.1.3 (2023-06-29)
410

511
- release v3.1.3

docs/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,17 @@ Set the terminal atom io status
11041104

11051105
### set_gservo_round
11061106

1107-
- **Prototype**: `set_gservo_round()`
1107+
- **Prototype**: `set_gservo_round(angle)`
11081108

11091109
- **Description**: Drive the 9g steering gear clockwise for one revolution.
11101110

1111+
- **Parameters**
1112+
1113+
- `angle` (`int`) 0 - 255.
1114+
0 : stop
1115+
255 : Keep turning
1116+
1 ~ 254: Based on 30° (1->30°, 2->60°)
1117+
11111118
### get_servo_speeds
11121119

11131120
- **Prototype**: `get_servo_speeds()`

pymycobot/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pymycobot.mybuddybluetooth import MyBuddyBlueTooth
1919
from pymycobot.mypalletizersocket import MyPalletizerSocket
2020
from pymycobot.myarm import MyArm
21+
from pymycobot.elephantrobot import ElephantRobot
2122

2223
__all__ = [
2324
"MyCobot",
@@ -34,15 +35,16 @@
3435
"ultraArm",
3536
"MyPalletizerSocket",
3637
"MechArm",
37-
"MyArm"
38+
"MyArm",
39+
"ElephantRobot"
3840
]
3941

4042

4143
if sys.platform == "linux":
4244
from pymycobot.mybuddyemoticon import MyBuddyEmoticon
4345
__all__.append("MyBuddyEmoticon")
4446

45-
__version__ = "3.1.3"
47+
__version__ = "3.1.4"
4648
__author__ = "Elephantrobotics"
4749
__email__ = "weiquan.xu@elephantrobotics.com"
4850
__git_url__ = "https://github.com/elephantrobotics/pymycobot"

pymycobot/elephantrobot.py

Lines changed: 303 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,303 @@
1+
#!/usr/bin/python
2+
3+
from socket import *
4+
import sys
5+
from multiprocessing import Lock
6+
import logging
7+
from pymycobot.log import setup_logging
8+
9+
10+
mutex = Lock()
11+
12+
13+
class ElephantRobot(object):
14+
def __init__(self, host, port, debug=False):
15+
# setup connection
16+
self.debug = debug
17+
setup_logging(self.debug)
18+
self.log = logging.getLogger(__name__)
19+
self.BUFFSIZE = 2048
20+
self.ADDR = (host, port)
21+
self.tcp_client = socket(AF_INET, SOCK_STREAM)
22+
23+
def start_client(self):
24+
try:
25+
self.tcp_client.connect(self.ADDR)
26+
return ""
27+
except Exception as e:
28+
return e
29+
30+
def stop_client(self):
31+
self.tcp_client.close()
32+
33+
def send_command(self, command):
34+
with mutex:
35+
self.tcp_client.send(command.encode())
36+
recv_data = self.tcp_client.recv(self.BUFFSIZE).decode()
37+
res_str = str(recv_data)
38+
print("recv = " + res_str)
39+
res_arr = res_str.split(":")
40+
if len(res_arr) == 2:
41+
return res_arr[1]
42+
else:
43+
return ""
44+
45+
def string_to_coords(self, data):
46+
data = data.replace("[", "")
47+
data = data.replace("]", "")
48+
data_arr = data.split(",")
49+
if len(data_arr) == 6:
50+
try:
51+
coords_1 = float(data_arr[0])
52+
coords_2 = float(data_arr[1])
53+
coords_3 = float(data_arr[2])
54+
coords_4 = float(data_arr[3])
55+
coords_5 = float(data_arr[4])
56+
coords_6 = float(data_arr[5])
57+
coords = [coords_1, coords_2, coords_3, coords_4, coords_5, coords_6]
58+
return coords
59+
except:
60+
return self.invalid_coords()
61+
return self.invalid_coords()
62+
63+
def string_to_double(self, data):
64+
try:
65+
val = float(data)
66+
return val
67+
except:
68+
return -9999.99
69+
70+
def string_to_int(self, data):
71+
try:
72+
val = int(data)
73+
return val
74+
except:
75+
return -9999
76+
77+
def invalid_coords(self):
78+
coords = [-1, -2, -3, -4, -1, -1]
79+
return coords
80+
81+
def get_angles(self):
82+
command = "get_angles()\n"
83+
res = self.send_command(command)
84+
return self.string_to_coords(res)
85+
86+
def get_coords(self):
87+
command = "get_coords()\n"
88+
res = self.send_command(command)
89+
return self.string_to_coords(res)
90+
91+
def get_speed(self):
92+
command = "get_speed()\n"
93+
res = self.send_command(command)
94+
return self.string_to_double(res)
95+
96+
def power_on(self):
97+
command = "power_on()\n"
98+
res = self.send_command(command)
99+
return True
100+
101+
def power_off(self):
102+
command = "power_off()\n"
103+
res = self.send_command(command)
104+
return True
105+
106+
def start_robot(self):
107+
command = "start_robot()\n"
108+
res = self.send_command(command)
109+
return True
110+
111+
def check_running(self):
112+
command = "check_running()\n"
113+
res = self.send_command(command)
114+
return res == "1"
115+
116+
def state_check(self):
117+
command = "state_check()\n"
118+
res = self.send_command(command)
119+
return res == "1"
120+
121+
def program_open(self, file_path):
122+
command = "program_open(" + file_path + ")\n"
123+
res = self.send_command(command)
124+
return self.string_to_int(res)
125+
126+
def program_run(self, start_line):
127+
command = "program_run(" + str(start_line) + ")\n"
128+
res = self.send_command(command)
129+
return self.string_to_int(res)
130+
131+
def read_next_error(self):
132+
command = "read_next_error()\n"
133+
res = self.send_command(command)
134+
return res
135+
136+
def write_coords(self, coords, speed):
137+
command = "set_coords("
138+
for item in coords:
139+
command += str(item) + ","
140+
command += str(speed) + ")\n"
141+
self.send_command(command)
142+
143+
def write_coord(self, axis, value, speed):
144+
coords = self.get_coords()
145+
if coords != self.invalid_coords():
146+
coords[axis] = value
147+
self.write_coords(coords, speed)
148+
149+
def write_angles(self, angles, speed):
150+
command = "set_angles("
151+
for item in angles:
152+
command += str(item) + ","
153+
command += str(speed) + ")\n"
154+
self.send_command(command)
155+
156+
def write_angle(self, joint, value, speed):
157+
angles = self.get_angles()
158+
if angles != self.invalid_coords():
159+
angles[joint] = value
160+
self.write_angles(angles, speed)
161+
162+
def set_speed(self, percentage):
163+
command = "set_speed(" + str(percentage) + ")\n"
164+
self.send_command(command)
165+
166+
def set_carte_torque_limit(self, axis_str, value):
167+
command = "set_torque_limit(" + axis_str + "," + str(value) + ")\n"
168+
self.send_command(command)
169+
170+
def set_upside_down(self, up_down):
171+
up = "1"
172+
if up_down:
173+
up = "0"
174+
command = "set_upside_down(" + up + ")\n"
175+
self.send_command(command)
176+
177+
def set_payload(self, payload):
178+
command = "set_speed(" + str(payload) + ")\n"
179+
self.send_command(command)
180+
181+
def state_on(self):
182+
command = "state_on()\n"
183+
self.send_command(command)
184+
185+
def state_off(self):
186+
command = "state_off()\n"
187+
self.send_command(command)
188+
189+
def task_stop(self):
190+
command = "task_stop()\n"
191+
self.send_command(command)
192+
193+
def jog_angle(self, joint_str, direction, speed):
194+
command = (
195+
"jog_angle(" + joint_str + "," + str(direction) + "," + str(speed) + ")\n"
196+
)
197+
self.send_command(command)
198+
199+
def jog_coord(self, axis_str, direction, speed):
200+
command = (
201+
"jog_coord(" + axis_str + "," + str(direction) + "," + str(speed) + ")\n"
202+
)
203+
self.send_command(command)
204+
205+
def get_digital_in(self, pin_number):
206+
command = "get_digital_in(" + str(pin_number) + ")\n"
207+
self.send_command(command)
208+
209+
def get_digital_out(self, pin_number):
210+
command = "get_digital_out(" + str(pin_number) + ")\n"
211+
print(command)
212+
self.send_command(command)
213+
214+
def get_joint_current(self, joint_number: int):
215+
command = "get_joint_current(" + str(joint_number) + ")\n"
216+
print(command)
217+
self.send_command(command)
218+
219+
def set_digital_out(self, pin_number, pin_signal):
220+
command = "set_digital_out(" + str(pin_number) + "," + str(pin_signal) + ")\n"
221+
self.send_command(command)
222+
223+
def set_analog_out(self, pin_number, pin_signal):
224+
command = "set_analog_out(" + str(pin_number) + "," + str(pin_signal) + ")\n"
225+
self.send_command(command)
226+
227+
def send_feed_override(self, override):
228+
command = "set_feed_rate(" + str(override) + ")\n"
229+
res = self.send_command(command)
230+
return self.string_to_int(res)
231+
232+
def get_acceleration(self):
233+
command = "get_acceleration()\n"
234+
res = self.send_command(command)
235+
return self.string_to_int(res)
236+
237+
def set_acceleration(self, acceleration):
238+
command = "set_acceleration(" + str(acceleration) + ")\n"
239+
self.send_command(command)
240+
241+
def command_wait_done(self):
242+
command = "wait_command_done()\n"
243+
self.send_command(command)
244+
245+
def wait(self, seconds):
246+
command = "wait(" + str(seconds) + ")\n"
247+
self.send_command(command)
248+
249+
def assign_variable(self, var_name, var_value):
250+
command = 'assign_variable("' + str(var_name) + '",' + str(var_value) + ")\n"
251+
self.send_command(command)
252+
253+
def get_variable(self, var_name):
254+
command = 'get_variable("' + str(var_name) + '")\n'
255+
return self.send_command(command)
256+
257+
258+
if __name__ == "__main__":
259+
ep = ElephantRobot("192.168.124.28", 5001)
260+
res = ep.start_client()
261+
if res != "":
262+
print(res)
263+
sys.exit(1)
264+
print(ep.wait(5))
265+
print(ep.get_angles())
266+
print(ep.get_coords())
267+
print(ep.get_speed())
268+
# print(ep.power_on())
269+
# print(ep.power_off())
270+
print(ep.check_running())
271+
print(ep.state_check())
272+
print(ep.program_open("a.tax"))
273+
print(ep.program_run(0))
274+
print(ep.read_next_error())
275+
print(ep.write_coords([1, 2, 3, 4, 5, 6], 110))
276+
print(ep.write_coord(1, 100, 200))
277+
print(ep.write_angles([10, 20, 30, 40, 50, 60], 110))
278+
print(ep.write_angle(3, 180, 200))
279+
print(ep.set_speed(377))
280+
print(ep.set_carte_torque_limit("x", 55))
281+
print(ep.set_upside_down(False))
282+
print(ep.set_payload(100))
283+
print(ep.state_on())
284+
print(ep.state_off())
285+
print(ep.task_stop())
286+
print(ep.jog_angle("j2", 1, 300))
287+
print(ep.jog_coord("rY", 0, 200))
288+
print(ep.get_digital_in(3))
289+
print(ep.get_digital_out(3))
290+
print(ep.set_digital_out(3, 1))
291+
print(ep.get_digital_out(3))
292+
print(ep.set_analog_out(1, 3.5))
293+
print(ep.get_acceleration())
294+
print(ep.set_acceleration(55))
295+
print(ep.command_wait_done())
296+
print(ep.get_variable("f"))
297+
print(ep.assign_variable("ss", '"eee"'))
298+
print(ep.get_joint_current(1))
299+
300+
ep.stop_client()
301+
302+
name = input("input:")
303+
print(name)

pymycobot/generate.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,13 @@ def clear_error_information(self):
10311031
"""Clear robot error message"""
10321032
return self._mesg(ProtocolCode.CLEAR_ERROR_INFO, has_reply = True)
10331033

1034-
def set_gservo_round(self):
1035-
"""Drive the 9g steering gear clockwise for one revolution"""
1036-
return self._mesg(ProtocolCode.SET_GSERVO_ROUND)
1034+
def set_gservo_round(self, angle):
1035+
"""Drive the 9g steering gear clockwise for one revolution
1036+
1037+
Args:
1038+
angle (int): 0 ~ 255
1039+
0 : stop
1040+
255 : Keep turning
1041+
1 ~ 254: Based on 30° (1->30°, 2->60°)
1042+
"""
1043+
return self._mesg(ProtocolCode.SET_GSERVO_ROUND, angle)

0 commit comments

Comments
 (0)