-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.py
296 lines (256 loc) · 9.29 KB
/
actions.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
from kipr import msleep, enable_servos, disable_servos, analog_et, a_button, b_button, \
c_button, shut_down_in
from time import time
import constants as c
import utilities as u
import drive
import servo
start_time = 0
def pc(prime, clone):
if c.IS_PRIME:
return prime
else:
return clone
def power_on_self_test():
print("power on self test")
if c.IS_PRIME:
print("I am prime")
else:
print("I am clone")
enable_servos()
servo.move(c.ARM, c.ARM_MID, 35)
print("calibrate gryo with btn")
drive.calibrate_gyro()
print('k thnx')
drive.self_test()
servo.self_test()
servo.move(c.TAIL_STICK, c.TAIL_HIDE, 55)
servo.move(c.TAIL_STICK, int(c.TAIL_OUT / 2), 55)
servo.move(c.TAIL_STICK, c.TAIL_HIDE, 55)
servo.move(c.WRIST, c.WRIST_DELIVER_RINGS_1)
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1 - 60)
adjust_delivery_height()
u.wait_for_button()
adjust_pickup_1_height()
u.wait_for_button()
adjust_pickup_2_height()
u.wait_for_button()
delivery_offset = 0
pickup_1_offset = 0
pickup_2_offset = 0
def adjust_delivery_height():
print("A increase height, B decrease, C when done")
starting_arm = c.ARM_DELIVER_RINGS_1 - 60
starting_wrist = c.WRIST_DELIVER_RINGS_1
global delivery_offset
while True:
servo.move(c.ARM, starting_arm + delivery_offset)
servo.move(c.WRIST, starting_wrist - delivery_offset)
if a_button():
delivery_offset -= 15 # 25
elif b_button():
delivery_offset += 15 # 25
elif c_button():
break
print("height adjusted! :D")
def adjust_pickup_1_height():
print("pick up 1")
print("A increase height, B decrease, C when done")
starting_arm = c.ARM_PICK_UP_1
starting_wrist = c.WRIST_PICK_UP_1
global pickup_1_offset
while True:
servo.move(c.ARM, starting_arm + pickup_1_offset)
servo.move(c.WRIST, starting_wrist - pickup_1_offset)
if a_button():
pickup_1_offset -= 15 # 25
elif b_button():
pickup_1_offset += 15 # 25
elif c_button():
break
print("pick up 1 adjusted! :D")
def adjust_pickup_2_height():
print("pick up 2")
print("A increase height, B decrease, C when done")
starting_wrist = c.WRIST_PICK_UP_2
starting_arm = c.ARM_PICK_UP_2
global pickup_2_offset
while True:
servo.move(c.WRIST, starting_wrist - pickup_2_offset)
servo.move(c.ARM, starting_arm + pickup_2_offset)
if a_button():
pickup_2_offset -= 15 # 25
elif b_button():
pickup_2_offset += 15 # 25
elif c_button():
break
print("pick up 1 adjusted! :D")
def init():
print("starting up :)")
enable_servos()
servo.move(c.WRIST, c.WRIST_START)
servo.move(c.ARM, c.ARM_PICK_UP_1 + pickup_1_offset)
u.wait_4_light()
# u.wait_for_button() # wait for light
global start_time
start_time = time()
shut_down_in(119)
def get_rings_1():
print("get rings 1")
drive.until_line(-50, c.FRONT_TOPHAT)
if c.IS_PRIME:
drive.pivot(50, 13, "l") # was 19
else:
drive.pivot(50, 14, "l") # was 18
drive.until_line(50)
servo.move(c.WRIST, c.WRIST_PICK_UP_1 - pickup_1_offset)
drive.pivot(-50, pc(17, 13), "l") # change 9:48
drive.distance_straight(60, 4)
drive.distance_straight(30, 1)
servo.move_parallel_with_drive(c.ARM_UP_HIGH, 20)
msleep(250)
drive.distance_straight(-70, 3)
servo.move(c.WRIST, c.WRIST_UP)
servo.move(c.ARM, c.ARM_UP)
msleep(250)
def deliver_rings_1():
print("deliver rings 1")
drive.distance_straight(-80, 12, False, pc(0.04, 0.03))
drive.pivot(50, pc(6, 12), "l") # was 5 for prime
drive.until_line(-50)
drive.distance_straight(-80, 9, True, pc(0.00, 0.00))
if c.IS_PRIME:
# drive.pivot(-50, 6, "l")
pass
else:
drive.pivot(50, 5, "l") # added bc front wheel on clone is not on wall so left side of claw snags on pipe
# drive.pivot(50, 5, "l")
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1_HALFWAY + delivery_offset)
msleep(250)
servo.move(c.WRIST, c.WRIST_DELIVER_RINGS_1_HALFWAY - delivery_offset)
msleep(250)
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1 + delivery_offset) # -150
msleep(250)
servo.move(c.WRIST, c.WRIST_DELIVER_RINGS_1 - delivery_offset) # 100
# servo.move(c.ARM, c.ARM_DELIVER_RINGS_1)
drive.distance_straight(40, 12.5) # 12
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1 - 50 + delivery_offset)
servo.move(c.WRIST, c.WRIST_DELIVER_RINGS_1 - delivery_offset)
drive.distance_straight(40, 0.5)
servo.move(c.WRIST, c.WRIST_DELIVER_RINGS_1 + 30 - delivery_offset)
servo.move(c.ARM, c.ARM_PRE_PUSH + delivery_offset)
servo.move(c.ARM, c.ARM_PRE_PUSH + 20 + delivery_offset) # new
servo.move(c.WRIST, c.WRIST_PUSH - delivery_offset)
def return_to_rings():
print("return to rings")
drive.distance_straight(-60, 10, True, pc(0.06, 0.06))
servo.move(c.ARM, c.ARM_UP_MAX)
servo.move(c.WRIST, c.WRIST_UP)
drive.distance_straight(60, 12)
drive.until_line(50, c.FRONT_TOPHAT) # straightens out in case the wheel gets caught
drive.pivot(50, c.return_turn, "l")
drive.until_line(50)
servo.move(c.WRIST, c.WRIST_PICK_UP_2 - pickup_2_offset)
servo.move(c.ARM, c.ARM_PICK_UP_2 + pickup_2_offset)
def get_rings_2():
print("get rings 2")
drive.pivot(-50, pc(15, 12), "l") # angle used to be 15 - test for prime
drive.distance_straight(60, 6)
servo.move_parallel_with_drive(c.ARM_UP_HIGH, 25)
msleep(250)
drive.distance_straight(-70, 3)
servo.move(c.WRIST, c.WRIST_UP_MAX)
servo.move(c.ARM, c.ARM_UP_MAX + 50, 10)
msleep(250)
def deliver_rings_2():
print("deliver rings 2")
drive.distance_straight(-80, 12, False, pc(0.03, 0.03))
drive.pivot(50, pc(5, 11), "l")
drive.until_line(-50)
drive.distance_straight(-80, 9)
# drive.pivot(50, 5, "l")
servo.move(c.ARM, 660)
msleep(250)
servo.move(c.WRIST, c.WRIST_UP - 60)
msleep(250)
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1 + 0 + delivery_offset) # TRY DECREASING THIS VALUE NEXT TIME (HIGHER), 70
msleep(250)
servo.move(c.WRIST,
c.WRIST_DELIVER_RINGS_1 - delivery_offset) # was 110, try putting wrist back even more next time by subtracting more
msleep(250)
servo.move(c.ARM, c.ARM_DELIVER_RINGS_1 + 30 + delivery_offset) # new
msleep(250)
drive.distance_straight(40, 13)
servo.move(c.ARM, c.ARM_PRE_PUSH + delivery_offset)
servo.move(c.WRIST, c.WRIST_PUSH - delivery_offset)
def release_tennis_balls():
servo.move(c.ARM, c.ARM_PRE_PUSH + delivery_offset) # temporary
servo.move(c.WRIST, c.WRIST_PUSH - delivery_offset)
servo.move(c.TAIL_STICK, c.TAIL_HIDE)
drive.until_line(-90, c.BACK_TOPHAT, False)
# drive.blind(-90, -60)
# msleep(1700)
drive.distance_straight(-50, 5) # 7
servo.move(c.ARM, c.ARM_UP_MAX)
servo.move(c.WRIST, c.WRIST_UP)
drive.pivot(-80, 5, "l")
drive.distance_straight(-50, 5) # square up against the side wall
drive.pivot(80, 5, "l")
drive.until_line(90, c.BACK_TOPHAT, False)
drive.distance_straight(-50, 7.5) # same place as before but squared against the wall, was 7, made drive back longer so that the robot is to the right of the bump
msleep(100)
drive.gyro_pivot_precise(90, 90, "r")
# msleep(100)
drive.until_line(50, c.FRONT_TOPHAT, True, 0.05) # 0.06
drive.until_line(50, c.BACK_TOPHAT, True, 0.045) # 0.085
drive.gyro_pivot_precise(-90, 180, "l") # was 180, but it drifts to the right consistently on the next drive
# msleep(100)
drive.until_line(-50, c.FRONT_TOPHAT, True, 0.045) # was 0.05
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
# msleep(100)
drive.distance_straight(-80, 9) # was 9.6, 9, 8.5, drive where the caster ball gets stuck
lift_ball_screen(2)
servo.move(c.TAIL_STICK, c.TAIL_HALF, 70)
drive.distance_straight(80, 5)
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
drive.pivot(-80, 5, "l") # WAS 7
drive.distance_straight(-80, 5) # was 6
lift_ball_screen(2) # was 3
servo.move(c.TAIL_STICK, c.TAIL_HALF, 70) # new
drive.distance_straight(80, 5)
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
drive.pivot(-80, 7, "r")
lift_ball_screen(2)
drive.distance_straight(80, 3)
print("finished run!")
def lift_ball_screen(n):
for x in range(n):
if time() - start_time < 2:
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
print("stopped in loop!")
shutdown()
else:
servo.move(c.TAIL_STICK, c.TAIL_LIFT, 70)
msleep(250)
servo.move(c.TAIL_STICK, c.TAIL_OUT, 70)
drive.pivot(70, 6, "l") # was 8
drive.pivot(-70, 6, "l")
def shutdown():
print("run time:", time() - start_time)
print("Shutting down")
disable_servos()
exit(0)
def gyro_test():
print("gyro test")
drive.calibrate_gyro()
drive.gyro_pivot(60, 90, "l")
u.wait_for_button()
drive.gyro_pivot(60, 90, "l")
u.wait_for_button()
drive.gyro_pivot(60, 90, "l")
u.wait_for_button()
drive.gyro_pivot(60, 90, "l")
u.wait_for_button()
drive.gyro_pivot(60, 90, "l")
u.wait_for_button()