This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autonomous.cpp
330 lines (242 loc) · 5.49 KB
/
autonomous.cpp
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include "main.h"
#include "config.hpp"
#include "movement.hpp"
/**
* Plan for close:
* Start facing straight ahead
* 1. Hit top flag with preload
* 2. Hit low flag with poles
* 3. Flip cap
* 4. Get other cap core touching
* 5. Hit low middle flag
* 6. Park on alliance platform
* 7. Stop
*/
/**
* Plan for far:
* Start facing straight ahead
* 1. Hit middle flag with preload
* 2. Flip cap
* 3. Get other cap core touching
* 4. Park
* 5. Stop
*/
/**
* Plan for any:
* 1. Get cap core touching
* 2. Stop
*/
/**
* Plan for skills - Start Red Close, facing straight ahead:
* 1. Shoot high flag
* 2. Hit low flag with poles
* 3. Flip cap
* 4. Flip other cap
* 5. Hit low middle flag
* 6. Flip cap
* 7. Hit low far flag
* 8. Flip other cap
* 9. Flip far cap
* 10. Flip other far cap
* 11. Flip other far cap
* 12. Flip other far cap
* 13. Park on middle
* 14. Stop
*/
// 1000 raw units about equal to 1 square
// 900 raw units for 90 degree turn
inline void autonomousBlueClose() {
using namespace movement;
// Get launcher to full speed in time
revUpLauncher();
// Move forward
forward(0.175, 127);
// Face flags
turnRight(0.67, 70);
// Wait for launcher to rev up
pros::delay(4500);
// Move forward a little
forward(0.4, 127);
// Launch
mtr_combine = -127;
pros::delay(500);
mtr_combine = 0;
// Stop all motors
zeroAllMotors();
// Turn right just a little
turnRight(0.05, 127);
// Hit low flag
forward(1, 127);
// Back up
forward(0.8, -127);
// Turn toward cap
turnLeft(0.4875, 127);
// Turn on combine
mtr_combine = 110;
// Hit the cap
forward(0.6, 127);
pros::delay(300);
// Stop combine
mtr_combine = 0;
// Backwards
forward(0.155, -127);
/*
// Turn to platform
turnLeft(0.24, 127);
// Get on platform
forward(1.4, 127);*/
}
inline void autonomousBlueFar() {
using namespace movement;
forwardEncoder(2500);
turnRight(0.3);
backward(0.1);
}
inline void autonomousRedClose() {
using namespace movement;
// Get launcher to full speed in time
revUpLauncher();
// Move forward
forward(0.175, 127);
// Face flags
turnLeft(0.7, 70);
// Wait for launcher to rev up
pros::delay(4500);
// Move forward a little
forward(0.4, 127);
// Launch
mtr_combine = -127;
pros::delay(500);
mtr_combine = 0;
// Stop all motors
zeroAllMotors();
// Turn left just a little
turnLeft(0.07, 127);
// Hit low flag
forward(1, 127);
// Back up
forward(0.8, -127);
// Turn toward cap
turnRight(0.53, 127);
/*// Turn on combine
mtr_combine = 110;
// Hit the cap
forward(0.6, 127);
pros::delay(300);
// Stop combine
mtr_combine = 0;
// Backwards
forward(0.155, -127);
// Turn to platform
turnRight(0.34, 127);
// Get on platform
forward(1.55, 127);*/
zeroAllMotors();
}
inline void autonomousRedFar() {
using namespace movement;
forwardEncoder(2500);
turnRight(0.3);
backward(0.1);
}
inline void autonomousAny() {
using namespace movement;
forwardEncoder(2500);
turnLeftEncoder(1000);
}
inline void autonomousSkills() {
using namespace movement;
// Move forward
forwardEncoder(230);
// Face flags
turnRightEncoder(885);
// Get launcher to full speed in time
revUpLauncher();
// Wait for launcher to rev up
pros::delay(3750);
// Move forward a little
forwardEncoder(1645);
// Launch
mtr_combine = -127;
pros::delay(500);
mtr_combine = 0;
// Stop all motors
zeroLaunchMotors();
// Turn right just a little
turnRightEncoder(100);
// Hit low flag
forwardEncoder(1760);
// Back up
backwardEncoder(1605);
// Turn toward cap
turnLeftEncoder(1100);
// Turn on combine
mtr_combine = 100;
// Hit the cap
forwardEncoder(2600);
pros::delay(300);
// Stop combine
mtr_combine = 0;
// Backwards
backwardEncoder(400);
// Turn toward low middle flag
turnRightEncoder(700);
//Other stuff to hit the flag
// Hit low middle flag
forwardEncoder(1945);
turnRight(0.2);
backward(0.1);
turnLeft(0.1);
forward(0.5);
//Backwards
backward(1.3, 100);
// Scoot up just a little
forward(0.1);
// Turn right
turnRightEncoder(1000);
// Forward a little
forwardEncoder(900);
// Turn to platform
turnRightEncoder(840);
// Get on platform
forwardEncoder(3000);
// Turn right
turnRightEncoder(900);
// Get on
forwardEncoder(1300);
zeroAllMotors();
}
void autonomous() {
// Make sure we know what's going on
pros::lcd::clear_line(1);
pros::lcd::print(1, "Autonomous mode.");
ctr_master.clear_line(0);
ctr_master.print(0, 0, "Autonomous");
// Tell driver we're starting
ctr_master.rumble(".");
// Turn on braking
mtr_frontLeft.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
mtr_backLeft.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
mtr_frontRight.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
mtr_backRight.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
#ifdef BLUE_CLOSE
autonomousBlueClose();
#endif
#ifdef BLUE_FAR
autonomousBlueFar();
#endif
#ifdef RED_CLOSE
autonomousRedClose();
#endif
#ifdef RED_FAR
autonomousRedFar();
#endif
#ifdef ANY
autonomousAny();
#endif
#ifdef SKILLS
autonomousSkills();
#endif
// Stop
movement::zeroAllMotors();
}