-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbasic_moves.py
199 lines (156 loc) · 4.66 KB
/
basic_moves.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
8#"""
# Basic moves for Hexy.
#"""
#imports
import time
def walkForward(steps = 2):
# walk forward a number of complete steps
deg = 25
midFloor = 30
hipSwing = 25
for step in range(steps):
hexy.LF.replantFoot(deg-hipSwing,stepTime=0.5)
hexy.RM.replantFoot(hipSwing,stepTime=0.5)
hexy.LB.replantFoot(-deg-hipSwing,stepTime=0.5)
hexy.RF.setHipDeg(-deg-hipSwing,stepTime=0.5)
hexy.LM.setHipDeg(hipSwing,stepTime=0.5)
hexy.RB.setHipDeg(deg-hipSwing,stepTime=0.5)
time.sleep(0.6)
hexy.RF.replantFoot(-deg+hipSwing,stepTime=0.5)
hexy.LM.replantFoot(-hipSwing,stepTime=0.5)
hexy.RB.replantFoot(deg+hipSwing,stepTime=0.5)
hexy.LF.setHipDeg(deg+hipSwing,stepTime=0.5)
hexy.RM.setHipDeg(-hipSwing,stepTime=0.5)
hexy.LB.setHipDeg(-deg+hipSwing,stepTime=0.5)
time.sleep(0.6)
def walkBackward(steps = 2):
# move backward a number of complete steps
deg = 25
midFloor = 30
hipSwing = 25
for step in range(steps):
hexy.LF.replantFoot(deg+hipSwing,stepTime=0.5)
hexy.RM.replantFoot(-hipSwing,stepTime=0.5)
hexy.LB.replantFoot(-deg+hipSwing,stepTime=0.5)
hexy.RF.setHipDeg(-deg+hipSwing,stepTime=0.5)
hexy.LM.setHipDeg(-hipSwing,stepTime=0.5)
hexy.RB.setHipDeg(deg+hipSwing,stepTime=0.5)
time.sleep(0.6)
hexy.RF.replantFoot(-deg-hipSwing,stepTime=0.5)
hexy.LM.replantFoot(hipSwing,stepTime=0.5)
hexy.RB.replantFoot(deg-hipSwing,stepTime=0.5)
hexy.LF.setHipDeg(deg-hipSwing,stepTime=0.5)
hexy.RM.setHipDeg(hipSwing,stepTime=0.5)
hexy.LB.setHipDeg(-deg-hipSwing,stepTime=0.5)
time.sleep(0.6)
def turnLeft(degrees = 40):
# rotate left a number of degrees in one or more complete moves
deg = 40
moves = int(degrees) // deg
remainder = int(degrees) % deg
for each in range(moves):
for leg in hexy.tripod2:
leg.replantFoot(deg,stepTime=0.2)
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setFootY(int(floor/2.0))
time.sleep(0.3)
for leg in hexy.tripod2:
leg.setHipDeg(-deg,stepTime=0.3)
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setFootY(floor)
time.sleep(0.3)
hexy.LF.replantFoot(deg,stepTime=0.3)
hexy.RM.replantFoot(1,stepTime=0.3)
hexy.LB.replantFoot(-deg,stepTime=0.3)
time.sleep(0.5)
if remainder != 0:
for leg in hexy.tripod2:
leg.replantFoot(remainder,stepTime=0.2)
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setFootY(int(floor/2.0))
time.sleep(0.3)
for leg in hexy.tripod2:
leg.setHipDeg(-remainder,stepTime=0.3)
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setFootY(floor)
time.sleep(0.3)
hexy.LF.replantFoot(remainder,stepTime=0.3)
hexy.RM.replantFoot(1,stepTime=0.3)
hexy.LB.replantFoot(-remainder,stepTime=0.3)
time.sleep(0.5)
def turnRight(degrees = 40):
# rotate right a number of degrees in one or more complete moves
deg = -40
moves = int(degrees) // abs(deg)
remainder = int(degrees) % deg
for each in range(moves):
for leg in hexy.tripod1:
leg.replantFoot(deg,stepTime=0.2)
time.sleep(0.5)
for leg in hexy.tripod2:
leg.setFootY(int(floor/2.0))
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setHipDeg(-deg,stepTime=0.3)
time.sleep(0.3)
for leg in hexy.tripod2:
leg.setFootY(floor)
time.sleep(0.3)
hexy.RF.replantFoot(deg,stepTime=0.3)
hexy.LM.replantFoot(1,stepTime=0.3)
hexy.RB.replantFoot(-deg,stepTime=0.3)
time.sleep(0.5)
if remainder != 0:
for leg in hexy.tripod1:
leg.replantFoot(remainder,stepTime=0.2)
time.sleep(0.5)
for leg in hexy.tripod2:
leg.setFootY(int(floor/2.0))
time.sleep(0.3)
for leg in hexy.tripod1:
leg.setHipDeg(-remainder,stepTime=0.3)
time.sleep(0.3)
for leg in hexy.tripod2:
leg.setFootY(floor)
time.sleep(0.3)
hexy.RF.replantFoot(remainder,stepTime=0.3)
hexy.LM.replantFoot(1,stepTime=0.3)
hexy.RB.replantFoot(-remainder,stepTime=0.3)
time.sleep(0.5)
def getDistance():
# return distance
distance = "CM: 0.00"
while distance.strip() == "CM: 0.00":
controller.serialHandler.ser.write("Q")
distance = controller.serialHandler.ser.readline()
return float(distance.strip()[3:])
def scanDistance(degrees = 90):
# scan a total number of degrees in front of Hexy and return list of distances
distances = []
degree = degrees // 2
time.sleep(.1)
hexy.neck.set(degree)
time.sleep(.3)
dist = getDistance()
distances.append((degree, dist))
time.sleep(.1)
for each in range(degrees // 10):
degree = degree - 10
hexy.neck.set(degree)
time.sleep(.2)
dist = getDistance()
distances.append((degree, dist))
time.sleep(.1)
print(distances)
distances.sort(key=lambda tup: tup[1])
time.sleep(.5)
return distances
# alternative names for moves start here
def moveForward(steps = 2):
walkForward(steps)
def moveBackward(steps = 2):
walkBackward(steps)