-
Notifications
You must be signed in to change notification settings - Fork 0
/
owi535state.py
77 lines (61 loc) · 2.12 KB
/
owi535state.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
import usb
class Motor:
def __init__(self, cw_flag, acw_flag, off_flag):
self.clockwise = False
self.anticlockwise = False
self.cw_flag = cw_flag
self.acw_flag = acw_flag
self.off_flag = off_flag
def isTurningCW(self):
return self.clockwise
def isTurningACW(self):
return self.anticlockwise
def startACW(self):
if self.isTurningCW():
self.stopCW()
self.anticlockwise = True
def stopACW(self):
self.anticlockwise = False
def startCW(self):
if self.isTurningACW():
self.stopACW()
self.clockwise = True
def stopCW(self):
self.clockwise = False
def render(self):
if self.clockwise:
return self.cw_flag
elif self.anticlockwise:
return self.acw_flag
else:
return self.off_flag
class Owi535State:
def __init__(self):
self.components = {
'''light''': Motor([0,0,1],[0,0,0],[0,0,0]),
'''base''': Motor([0,1,0],[0,2,0],[0,0,0]), # M5
'''shoulder''': Motor([64,0,0],[128,0,0],[0,0,0]), # M4
'''elbow''': Motor([16,0,0],[32,0,0],[0,0,0]), # M3
'''wrist''': Motor([4,0,0],[8,0,0],[0,0,0]), # M2
'''gripper''': Motor([1,0,0],[2,0,0],[0,0,0]) # M1
}
def render(self):
flags = [0, 0, 0]
for key,c in self.components.items():
ArmCmd = c.render()
flags[0] |= ArmCmd[0]
flags[1] |= ArmCmd[1]
flags[2] |= ArmCmd[2]
return flags
def startACW(self, component):
self.components[component].startACW()
def stopACW(self, component):
self.components[component].stopACW()
def isTurningACW(self, component):
return self.components[component].isTurningACW()
def startCW(self, component):
self.components[component].startCW()
def stopCW(self, component):
self.components[component].stopCW()
def isTurningCW(self, component):
return self.components[component].isTurningCW()