1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
autons.cpp
Go to the documentation of this file.
1#include "robot/auton.h"
2#include "globals.h"
3#include "lemlib/chassis/chassis.hpp"
4#include "main.h" // IWYU pragma: export
5#include "pros/motors.h"
6#include "pros/rtos.hpp"
7#include "robot/intake.h"
8#include "robot/ladybrown.h"
9#include "robot/sweeper.h"
10#include <iostream>
11#include <string>
12
13using namespace Robot;
14using namespace Robot::Globals;
15
17std::string Autonomous::autonName = "Red Positive";
18
19constexpr int delay_constant = 1050;
20
21// Red Left
22void Autonomous::RedNeg(Intake &intake, Latch &latch, DistanceSensor &distance) {
23 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
24 chassis.setPose(0, 0, 0);
25 // Move to first stake, then a bit farther at a slower speed for alignment
26 chassis.moveToPoint(0, -27, 1800, {.forwards = false, .maxSpeed = 60}, true);
27 chassis.moveToPoint(0, -35, 2050, {.forwards = false, .maxSpeed = 30}, true);
28 chassis.waitUntilDone();
29 pros::delay(500);
30 // Grab the closest MOGO mech
31 LatchControl.extend();
32 pros::delay(1500);
33 // Load the ring onto the stake
34 IntakeMotor.move_velocity(600);
35 HookMotor.move_velocity(200);
36 pros::delay(3000);
37}
38// Red Right
39void Autonomous::RedPos(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown) {
40 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
41 chassis.setPose(0, 0,0);
42
43 // Move to first stake
44 chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
45 chassis.waitUntilDone();
46 // Grab the closest MOGO mech
47 latch.toggle();
48 pros::delay(250);
49
50 // Rotate toward blue ring
51 chassis.turnToPoint(-25, -27, 1000);
52 chassis.waitUntilDone();
53
54 // Load the ring onto the stake
55 IntakeMotor.move_velocity(600);
56 HookMotor.move_velocity(200);
57
58 // Moves to 2 ring stack
59
60 chassis.moveToPoint(-25, -27, 1250, {.forwards = true});
61 chassis.turnToPoint(-33.5, 6, 1000);
62 SweeperControl.extend();
63 chassis.moveToPoint(-35, 7, 1500);
64 chassis.waitUntilDone();
65 IntakeMotor.move_velocity(0);
66 HookMotor.move_velocity(0);
67
68 chassis.moveToPose(-25, -4, 170, 2000, {.horizontalDrift = 2});
69 chassis.moveToPoint(-32, 10, 1000, {.forwards = false});
70 chassis.waitUntilDone();
71 latch.toggle();
72
73 chassis.turnToPoint(14, -36, 800);
74 SweeperControl.retract();
76
77 chassis.moveToPoint(14, -36, 5000);
78}
79
80// Blue left
81void Autonomous::BluePos(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown) {
82
83 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
84 chassis.setPose(0, 0,0);
85
86 // Move to first stake
87 chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
88 chassis.waitUntilDone();
89 // Grab the closest MOGO mech
90 latch.toggle();
91 pros::delay(250);
92
93 // Rotate toward blue ring
94 chassis.turnToPoint(25, -27, 1000);
95 chassis.waitUntilDone();
96
97 // Load the ring onto the stake
98 IntakeMotor.move_velocity(600);
99 HookMotor.move_velocity(200);
100
101 // Moves to 2 ring stack
102
103 chassis.moveToPoint(25, -27, 1250, {.forwards = true});
104 chassis.turnToPoint(33.5, 6, 1000);
105 SweeperControl.extend();
106 chassis.moveToPoint(35, 7, 1500);
107 chassis.waitUntilDone();
108 IntakeMotor.move_velocity(0);
109 HookMotor.move_velocity(0);
110
111 chassis.moveToPose(25, -4, 170, 2000, {.horizontalDrift = 2});
112 chassis.moveToPoint(32, 10, 1000, {.forwards = false});
113 chassis.waitUntilDone();
114 latch.toggle();
115
116 chassis.turnToPoint(-14, -36, 800);
117 SweeperControl.retract();
119
120 chassis.moveToPoint(-14, -36, 5000);
121
122}
123
124void Autonomous::BluePosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown) {
125 // drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
126 // chassis.setPose(-36, 11,-17);
127
128 // IntakeMotor.move_velocity(600);
129 // chassis.moveToPoint(-49, 38.5, 1100, {.minSpeed=60}, false);
130 // chassis.moveToPose(-47, 47, -5, 1000, {.horizontalDrift=8, .earlyExitRange=2}, true);
131
132
133 // chassis.waitUntil(37);
134 // SweeperControl.extend();
135
136 // chassis.waitUntilDone();
137
138 // pros::delay(200);
139
140 // chassis.moveToPoint(-48, 8, 1500, {.forwards=false, .maxSpeed=90}, false);
141
142 // SweeperControl.retract();
143
144 // chassis.turnToPoint(-24, 38.5, 750, {.forwards=false});
145 // chassis.moveToPoint(-24, 38.5, 1100, {.forwards=false, .maxSpeed=65});
146 // chassis.moveToPoint(-22, 40.5, 550, {.forwards=false, .maxSpeed=50});
147
148 // LatchControl.extend();
149
150 // chassis.turnToPoint(-24, 4, 600, {.forwards=true});
151 // chassis.moveToPoint(-24, 4, 1200, {.maxSpeed=90});
152 // chassis.waitUntil(8);
153 // HookMotor.move_velocity(200);
154
155 // chassis.turnToPoint(-12, 45, 1100, {.forwards=true}, false);
156
157 // chassis.moveToPoint(-12, 45, 1150, {.maxSpeed=60});
158
159 // chassis.turnToHeading(90, 650);
160
161 // SweeperControl.extend();
162
163 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
164 chassis.setPose(0, 0,0);
165
166 // Move to first stake
167 chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
168 chassis.waitUntilDone();
169 // Grab the closest MOGO mech
170 latch.toggle();
171 pros::delay(250);
172
173 // Rotate toward blue ring
174 chassis.turnToPoint(25, -27, 1000);
175 chassis.waitUntilDone();
176
177 // Load the ring onto the stake
178 IntakeMotor.move_velocity(600);
179 HookMotor.move_velocity(200);
180
181 // Moves to 2 ring stack
182 chassis.moveToPoint(25, -27, 1250, {.forwards = true});
183 chassis.turnToPoint(25, 0, 1000, {.forwards = false});
184 chassis.waitUntilDone();
185
186 // Moves goal to corner
187 chassis.moveToPoint(28, 3, 1250, {.forwards = false});
188 chassis.waitUntilDone();
189
190 HookMotor.brake();
191 latch.toggle();
192
193 // Move to Third goal
194 chassis.moveToPoint(25, -30, 1500, {.forwards = true},true);
195 chassis.turnToPoint(25, -40, 1000, {.forwards = false});
196 chassis.moveToPoint(25, -38,1000, {.forwards = false});
197}
198
199void Autonomous::RedPosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown) {
200 // drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
201 // chassis.setPose(-36, 11,-17);
202
203 // IntakeMotor.move_velocity(600);
204 // chassis.moveToPoint(-49, 38.5, 1100, {.minSpeed=60}, false);
205 // chassis.moveToPose(-47, 47, -5, 1000, {.horizontalDrift=8, .earlyExitRange=2}, true);
206
207
208 // chassis.waitUntil(37);
209 // SweeperControl.extend();
210
211 // chassis.waitUntilDone();
212
213 // pros::delay(200);
214
215 // chassis.moveToPoint(-48, 8, 1500, {.forwards=false, .maxSpeed=90}, false);
216
217 // SweeperControl.retract();
218
219 // chassis.turnToPoint(-24, 38.5, 750, {.forwards=false});
220 // chassis.moveToPoint(-24, 38.5, 1100, {.forwards=false, .maxSpeed=65});
221 // chassis.moveToPoint(-22, 40.5, 550, {.forwards=false, .maxSpeed=50});
222
223 // LatchControl.extend();
224
225 // chassis.turnToPoint(-24, 4, 600, {.forwards=true});
226 // chassis.moveToPoint(-24, 4, 1200, {.maxSpeed=90});
227 // chassis.waitUntil(8);
228 // HookMotor.move_velocity(200);
229
230 // chassis.turnToPoint(-12, 45, 1100, {.forwards=true}, false);
231
232 // chassis.moveToPoint(-12, 45, 1150, {.maxSpeed=60});
233
234 // chassis.turnToHeading(90, 650);
235
236 // SweeperControl.extend();
237
238 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
239 chassis.setPose(0, 0,0);
240
241 // Move to first stake
242 chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
243 chassis.waitUntilDone();
244 // Grab the closest MOGO mech
245 latch.toggle();
246 pros::delay(250);
247
248 // Rotate toward blue ring
249 chassis.turnToPoint(-25, -27, 1000);
250 chassis.waitUntilDone();
251
252 // Load the ring onto the stake
253 IntakeMotor.move_velocity(600);
254 HookMotor.move_velocity(200);
255
256 // Moves to 2 ring stack
257 chassis.moveToPoint(-25, -27, 1250, {.forwards = true});
258 chassis.turnToPoint(-25, 0, 1000, {.forwards = false});
259 chassis.waitUntilDone();
260
261 // Moves goal to corner
262 chassis.moveToPoint(-28, 3, 1250, {.forwards = false});
263 chassis.waitUntilDone();
264 HookMotor.brake();
265 latch.toggle();
266
267 // Move to Third goal
268 chassis.moveToPoint(-25, -30, 1500, {.forwards = true},true);
269 chassis.turnToPoint(-25, -40, 1000, {.forwards = false});
270 chassis.moveToPoint(-25, -38,1000, {.forwards = false});
271}
272
273/*
274 * @todo Flesh out this method before the competition in order to make it a full
275 * solo awp autonomous. Blue right
276 */
277void Autonomous::BlueNeg(Intake &intake, Latch &latch, DistanceSensor &distance) {
278 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
279 chassis.setPose(0, 0, 0);
280 // Move to first stake, then a bit farther at a slower speed for alignment
281 chassis.moveToPoint(0, -27, 1800, {.forwards = false, .maxSpeed = 60}, true);
282 chassis.moveToPoint(0, -35, 2050, {.forwards = false, .maxSpeed = 30}, true);
283 chassis.waitUntilDone();
284 pros::delay(500);
285 // Grab the closest MOGO mech
286 LatchControl.extend();
287 pros::delay(2000);
288 // Load the ring onto the stake
289 IntakeMotor.move_velocity(600);
290 HookMotor.move_velocity(200);
291 pros::delay(3000);
292}
293
294// Takes in two parameters: The autonomous value as well as the puncher object.
295void Autonomous::AutoDrive(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance,
296 LadyBrown &ladybrown) {
297 // Keep the switcher running while the controller down button has not been pressed and the time period is not
298 // autonomous Compare the current auton value to run the auton routine
299 switch (Autonomous::auton) {
300 case RED_NEG:
301 Autonomous::autonName = "Red Negative";
302 RedNeg(intake, latch, distance);
303 break;
304 case RED_POS:
305 Autonomous::autonName = "Red Positive";
306 RedPos(intake, latch, sweeper, distance, ladybrown);
307 break;
309 Autonomous::autonName = "Red Positive Late Rush";
310 RedPosLateGoalRush(intake, latch, sweeper, distance, ladybrown);
311 break;
312 case BLUE_POS:
313 Autonomous::autonName = "Blue Positive";
314 BluePos(intake, latch, sweeper, distance, ladybrown);
315 break;
316 case BLUE_NEG:
317 Autonomous::autonName = "Blue Negative";
318 BlueNeg(intake, latch, distance);
319 break;
321 Autonomous::autonName = "Blue Positive Late Rush";
322 BluePosLateGoalRush(intake, latch, sweeper, distance, ladybrown);
323 break;
324 case SKILLS:
325 Autonomous::autonName = "Skills";
326 Skills(intake, latch, distance, ladybrown);
327 break;
328 }
329}
330
331void Autonomous::AutonSwitcher(int autonNum) {
332 switch (autonNum) {
333 case 1:
334 Autonomous::autonName = "Red Negative";
336 break;
337 case 2:
338 Autonomous::autonName = "Red Positive Sweep";
340 break;
341 case 3:
342 Autonomous::autonName = "Red Positive Late Rush";
344 break;
345 case -1:
346 Autonomous::autonName = "Blue Positive Sweep";
348 break;
349 case -2:
350 Autonomous::autonName = "Blue Positive Late Rush";
352 break;
353 case -3:
354 Autonomous::autonName = "Blue Negative";
356 break;
357 case 0:
358 Autonomous::autonName = "Skills";
360 }
361 std::cout << "Current auton: " + Autonomous::autonName << std::endl;
362}
constexpr int delay_constant
Definition autons.cpp:19
void BluePos(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Runs the puncher routine for the Skills Challenge.
Definition autons.cpp:81
void RedNeg(Intake &intake, Latch &latch, DistanceSensor &distance)
Runs the autonomous path for the far side defensive game strategy.
Definition autons.cpp:22
void RedPosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Definition autons.cpp:199
void RedPos(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Runs the autonomous path for the near side offensive game strategy.
Definition autons.cpp:39
static std::string autonName
The name of the autonomous program.
Definition auton.h:35
void Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Definition skills.cpp:13
void AutoDrive(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Drives the robot autonomously.
Definition autons.cpp:295
void BluePosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Definition autons.cpp:124
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
Definition auton.h:28
static void AutonSwitcher(int autonNum)
Switches the autonomous program.
Definition autons.cpp:331
void BlueNeg(Intake &intake, Latch &latch, DistanceSensor &distance)
Runs the autonomous path for the far side offensive game strategy. This function executes the autonom...
Definition autons.cpp:277
The Intake class represents a robot intake system.
Definition intake.h:8
The LadyBrown class represents the robot lady brown subsystem.
Definition ladybrown.h:9
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
Definition ladybrown.cpp:72
The Latch class represents a latching mechanism.
Definition latch.h:8
void toggle()
Toggles latch state.
Definition latch.cpp:16
The Latch class represents a latching mechanism.
Definition sweeper.h:8
pros::MotorGroup drive_({LeftFront.get_port(), RightFront.get_port(), LeftMid.get_port(), RightMid.get_port(), LeftBack.get_port(), RightBack.get_port()})
pros::adi::Pneumatics LatchControl('A', false)
pros::Motor IntakeMotor(-9, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees)
pros::adi::Pneumatics SweeperControl('B', false)
pros::Motor HookMotor(7, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees)
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
Definition auton.h:10