Skip to content

Commit d00257d

Browse files
committed
push code
1 parent c5b06bb commit d00257d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

pymycobot/mercury.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ def drag_tech_pause(self):
334334
"""Pause recording of dragging teaching point"""
335335
self._mesg(ProtocolCode.MERCURY_DRAG_TECH_PAUSE)
336336

337+
def is_gripper_moving(self, mode=None):
338+
"""Judge whether the gripper is moving or not
339+
340+
Args:
341+
mode: 1 - pro gripper(default) 2 - Parallel gripper
342+
343+
Returns:
344+
0 - not moving
345+
1 - is moving
346+
-1- error data
347+
"""
348+
if mode:
349+
return self._mesg(ProtocolCode.IS_GRIPPER_MOVING, mode, has_reply=True)
350+
return self._mesg(ProtocolCode.IS_GRIPPER_MOVING, has_reply=True)
337351

338352

339353

pymycobot/mercurychassis.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
import socket
3+
import json
4+
import threading
5+
6+
class MercuryChassis:
7+
def __init__(self):
8+
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9+
self._sock.connect(("192.168.99.102", 9000))
10+
self.recv = threading.Thread(self.is_move_end, daemon=True)
11+
self.recv.start()
12+
self.move_end = False
13+
14+
def is_move_end(self):
15+
while True:
16+
data = self._sock.recv(1024)
17+
data = json.load(data)
18+
key = data.keys()[0]
19+
self.move_end = key["return"]
20+
21+
@property
22+
def move_end(self):
23+
return self.move_end
24+
25+
def go_straight(self, speed=0.5, exercise_duration=5):
26+
command = {"goStraight": {"time": exercise_duration, "speed": speed}}
27+
self._sock.sendall(json.dump(command))
28+
29+
def go_back(self, speed=0.5, exercise_duration=5):
30+
command = {"goBack": {"time": exercise_duration, "speed": speed}}
31+
self._sock.sendall(json.dump(command))
32+
33+
def turn_left(self, speed=0.5, exercise_duration=5):
34+
command = {"turnLeft": {"time": exercise_duration, "speed": speed}}
35+
self._sock.sendall(json.dump(command))
36+
37+
def go_straight(self, speed=0.5, exercise_duration=5):
38+
command = {"turnRight": {"time": exercise_duration, "speed": speed}}
39+
self._sock.sendall(json.dump(command))
40+
41+
def stop(self):
42+
command = {"stop": True}
43+
self._sock.sendall(json.dump(command))
44+

0 commit comments

Comments
 (0)