-
Notifications
You must be signed in to change notification settings - Fork 0
/
owi535.py
128 lines (110 loc) · 3.94 KB
/
owi535.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import sys
import usb
import time
from owi535state import Owi535State
class Owi535:
def __init__(self):
self.state = Owi535State()
self.arm = usb.core.find(idVendor=0x1267, idProduct=0x0001) # owi535's hardware id
if self.arm is None:
raise ValueError("Arm not found")
else:
sys.stdout.write("Arm Connection established." + '\n')
def SendMove(self):
"""
Send a motion command to the robot.
WARNING: This method does not contain a stop command. The robot will keep moving until \
another stop command (implemented by other methods) is sent.
"""
ArmCmd = self.state.render()
self.arm.ctrl_transfer(0x40,6,0x100,0,ArmCmd,3)
def StopMove(self):
"""
Send a stop command to pause the robot motion.
This method does not change the motion state values.
"""
ArmCmd = [0,0,0]
self.arm.ctrl_transfer(0x40,6,0x100,0,ArmCmd,3)
def MoveTime(self, t):
"""
Make the robot move for a certain time.
:param t: duration time of the motion, in seconds.
"""
self.SendMove()
time.sleep(t)
self.StopMove()
def RotateBase(self, value=0):
"""
Rotate the base motor (M5).
:param value: motion state flag, if smaller than 0, rotate anticlockwise; \
if larger than 0, rotate clockwise; if equals 0, cancel the rotation.
"""
if value < 0: # anti-clock wise
self.state.startACW('base')
elif value > 0: # clock wise
self.state.startCW('base')
else:
self.state.stopCW('base')
self.state.stopACW('base')
def RotateShoulder(self, value=0):
"""
Rotate the shoulder motor (M4).
:param value: motion state flag, if smaller than 0, the arm goes down; \
if larger than 0, the arm goes up; if equals 0, cancel the motion.
"""
if value < 0: # down
self.state.startACW('shoulder')
elif value > 0: # up
self.state.startCW('shoulder')
else:
self.state.stopCW('shoulder')
self.state.stopACW('shoulder')
def RotateElbow(self, value=0):
"""
Rotate the elbow motor (M3).
:param value: motion state flag, if smaller than 0, the arm goes down; \
if larger than 0, the arm goes up; if equals 0, cancel the motion.
"""
if value < 0: # down
self.state.startACW('elbow')
elif value > 0: # up
self.state.startCW('elbow')
else:
self.state.stopCW('elbow')
self.state.stopACW('elbow')
def RotateWrist(self, value=0):
"""
Rotate the wrist motor (M2).
:param value: motion state flag, if smaller than 0, the arm goes down; \
if larger than 0, the arm goes up; if equals 0, cancel the motion.
"""
if value < 0: # down
self.state.startACW('wrist')
elif value > 0: # up
self.state.startCW('wrist')
else:
self.state.stopCW('wrist')
self.state.stopACW('wrist')
def RotateGripper(self, value=0):
"""
Rotate the gripper motor (M1).
:param value: motion state flag, if smaller than 0, open the gripper; \
if larger than 0, close the gripper; if equals 0, cancel the motion.
"""
if value < 0:
self.state.startACW('gripper') # open
elif value > 0:
self.state.startCW('gripper') # close
else:
self.state.stopCW('gripper')
self.state.stopACW('gripper')
def SwitchLight(self, value=0):
"""
Switch the light.
:param value: light state flag, if larger than 0, turn on the light, \
else turn off the light.
"""
if value > 0:
self.state.startCW('light')
else:
self.state.stopCW('light')