1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
Robot::Autonomous Class Reference

The Autonomous class contains classes and functions related to the robot's autonomous behavior. More...

#include <auton.h>

Public Types

enum  AUTON_ROUTINE {
  RED_NEG = 1 , RED_POS = 2 , RED_POS_LATE_RUSH = 3 , BLUE_POS = -1 ,
  BLUE_POS_LATE_RUSH = -2 , BLUE_NEG = -3 , SKILLS = 0
}
 

Public Member Functions

void AutoDrive (Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
 Drives the robot autonomously.
 

Static Public Member Functions

static void AutonSwitcher (int autonNum)
 Switches the autonomous program.
 

Static Public Attributes

static AUTON_ROUTINE auton = RED_POS
 Sets the number of the autonomous program to use.
 
static std::string autonName = "Red Positive"
 The name of the autonomous program.
 

Private Member Functions

void RedNeg (Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
 Runs the autonomous path for the far side defensive game strategy.
 
void RedPos (Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
 Runs the autonomous path for the near side offensive game strategy.
 
void RedPosLateGoalRush (Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
 
void BluePos (Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
 Runs the puncher routine for the Skills Challenge.
 
void BluePosLateGoalRush (Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
 
void BlueNeg (Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
 Runs the autonomous path for the far side offensive game strategy. This function executes the autonomous path for the far side offensive game strategy. It contains the specific actions and movements required for this strategy.
 
void Skills (Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
 

Detailed Description

The Autonomous class contains classes and functions related to the robot's autonomous behavior.

We use Lemlib extensively for our documentation. You can find the documentation for Lemlib at Lemlib documentation.

Definition at line 16 of file auton.h.

Member Enumeration Documentation

◆ AUTON_ROUTINE

Enumerator
RED_NEG 
RED_POS 
RED_POS_LATE_RUSH 
BLUE_POS 
BLUE_POS_LATE_RUSH 
BLUE_NEG 
SKILLS 

Definition at line 18 of file auton.h.

Member Function Documentation

◆ AutoDrive()

void Autonomous::AutoDrive ( Intake & intake,
Latch & latch,
Sweeper & sweeper,
DistanceSensor & distance,
LadyBrown & ladybrown )

Drives the robot autonomously.

This function drives the robot autonomously based on the selected autonomous program. It takes a reference to a Puncher object and a boolean value indicating whether to use autonomous mode.

Parameters
puncherA reference to the Puncher object.
autonoA boolean value indicating whether to use autonomous mode.

Definition at line 583 of file autons.cpp.

584 {
585 // Keep the switcher running while the controller down button has not been pressed and the time period is not
586 // autonomous Compare the current auton value to run the auton routine
587 switch (Autonomous::auton) {
588 case RED_NEG:
589 Autonomous::autonName = "Red Negative";
590 RedNeg(intake, latch, distance, ladybrown);
591 break;
592 case RED_POS:
593 Autonomous::autonName = "Red Positive";
594 RedPos(intake, latch, sweeper, distance, ladybrown);
595 break;
597 Autonomous::autonName = "Red Positive Late Rush";
598 RedPosLateGoalRush(intake, latch, sweeper, distance, ladybrown);
599 break;
600 case BLUE_POS:
601 Autonomous::autonName = "Blue Positive";
602 BluePos(intake, latch, sweeper, distance, ladybrown);
603 break;
604 case BLUE_NEG:
605 Autonomous::autonName = "Blue Negative";
606 BlueNeg(intake, latch, distance, ladybrown);
607 break;
609 Autonomous::autonName = "Blue Positive Late Rush";
610 BluePosLateGoalRush(intake, latch, sweeper, distance, ladybrown);
611 break;
612 case SKILLS:
613 Autonomous::autonName = "Skills";
614 Skills(intake, latch, distance, ladybrown);
615 break;
616 }
617}
void BluePos(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Runs the puncher routine for the Skills Challenge.
Definition autons.cpp:220
void RedPosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Definition autons.cpp:411
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:114
static std::string autonName
The name of the autonomous program.
Definition auton.h:35
void BlueNeg(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Runs the autonomous path for the far side offensive game strategy. This function executes the autonom...
Definition autons.cpp:494
void Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Definition skills.cpp:16
void BluePosLateGoalRush(Intake &intake, Latch &latch, Sweeper &sweeper, DistanceSensor &distance, LadyBrown &ladybrown)
Definition autons.cpp:330
static AUTON_ROUTINE auton
Sets the number of the autonomous program to use.
Definition auton.h:28
void RedNeg(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Runs the autonomous path for the far side defensive game strategy.
Definition autons.cpp:22
Robot::LadyBrown ladybrown
Definition intake.cpp:19

References auton, autonName, BLUE_NEG, BLUE_POS, BLUE_POS_LATE_RUSH, BlueNeg(), BluePos(), BluePosLateGoalRush(), ladybrown, RED_NEG, RED_POS, RED_POS_LATE_RUSH, RedNeg(), RedPos(), RedPosLateGoalRush(), SKILLS, and Skills().

◆ AutonSwitcher()

void Autonomous::AutonSwitcher ( int autonNum)
static

Switches the autonomous program.

This function switches the autonomous program to the next available program. It allows the user to cycle through different autonomous programs during runtime.

Definition at line 619 of file autons.cpp.

619 {
620 switch (autonNum) {
621 case 1:
622 Autonomous::autonName = "Red Negative";
624 break;
625 case 2:
626 Autonomous::autonName = "Red Positive Sweep";
628 break;
629 case 3:
630 Autonomous::autonName = "Red Positive Late Rush";
632 break;
633 case -1:
634 Autonomous::autonName = "Blue Positive Sweep";
636 break;
637 case -2:
638 Autonomous::autonName = "Blue Positive Late Rush";
640 break;
641 case -3:
642 Autonomous::autonName = "Blue Negative";
644 break;
645 case 0:
646 Autonomous::autonName = "Skills";
648 }
649 std::cout << "Current auton: " + Autonomous::autonName << std::endl;
650}

References auton, autonName, BLUE_NEG, BLUE_POS, BLUE_POS_LATE_RUSH, RED_NEG, RED_POS, RED_POS_LATE_RUSH, and SKILLS.

◆ BlueNeg()

void Autonomous::BlueNeg ( Intake & intake,
Latch & latch,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Runs the autonomous path for the far side offensive game strategy. This function executes the autonomous path for the far side offensive game strategy. It contains the specific actions and movements required for this strategy.

Todo
Make the autonomous more fleshed out, building it properly for the competition

Definition at line 494 of file autons.cpp.

494 {
495
496
497 // Blue Negative 4+1 & touch
498 HookMotor.set_zero_position(HookMotor.get_position());
499 colorSensor.set_led_pwm(70);
500 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
501 //Edge of lady brown is 5.5 inches from the alliance wall stake.
502 chassis.setPose(0, 0, -112);
503
505
506 chassis.moveToPose(11, 44, 180, 2000, {.forwards=false, .horizontalDrift=5.5});
507
509 chassis.waitUntilDone();
510 LatchControl.extend();
511 pros::delay(250);
512 chassis.swingToPoint(28, 54.5, lemlib::DriveSide::LEFT, 1500, {.direction=AngularDirection::CCW_COUNTERCLOCKWISE});
513
514 IntakeMotor.move_velocity(600);
515 HookMotor.move_velocity(200);
516 chassis.moveToPoint(28, 54.5, 5000);
517 chassis.turnToPoint(43, 55, 5000);
518
519 chassis.moveToPoint(43, 55, 2500, {.minSpeed = 65}, false);
520 pros::delay(750);
521
522 chassis.turnToPoint(19, 40, 1000, {.forwards=false});
523 chassis.moveToPoint(19, 40, 1000, {.forwards=false});
524 chassis.turnToPoint(38, 39, 1000);
525 chassis.moveToPoint(38, 39, 1000);
526
527 chassis.turnToPoint(-8, 16.5, 1000, {.direction=AngularDirection::CCW_COUNTERCLOCKWISE});
528 chassis.moveToPoint(-8, 16.5, 7500, {.minSpeed=25, .earlyExitRange=10});
529 chassis.waitUntil(10);
530 IntakeLift.extend();
531
532 chassis.moveToPoint(-8, 16.5, 7500, {.maxSpeed=20}, false);
533
534 //IntakeMotor.brake();
535
536
537}
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
Definition ladybrown.cpp:83
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::Optical colorSensor(5)
pros::Motor IntakeMotor(-4, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees)
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Motor HookMotor(3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees)
pros::adi::Pneumatics IntakeLift('D', false)

References Robot::LadyBrown::ATTACK_STATE, Robot::LadyBrown::BASE_STATE, Robot::Globals::chassis(), Robot::Globals::colorSensor(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeLift(), Robot::Globals::IntakeMotor(), ladybrown, and Robot::Globals::LatchControl().

Referenced by AutoDrive().

◆ BluePos()

void Autonomous::BluePos ( Intake & intake,
Latch & latch,
Sweeper & sweeper,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Runs the puncher routine for the Skills Challenge.

This function executes the puncher routine for the Skills Challenge. It takes a reference to a Puncher object and performs the necessary actions for the challenge.

Parameters
puncherA reference to the Puncher object.

Definition at line 220 of file autons.cpp.

220 {
221 bool elims = false;
222 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
223 chassis.setPose(0, 0,12);
224 chassis.moveToPoint(7, 35, 2500, {.minSpeed=45, .earlyExitRange=2});
225 IntakeMotor.move_velocity(600);
226 chassis.waitUntilDone();
227 chassis.turnToHeading(-17.5, 300);
228 SweeperControl.extend();
229 //Use sin for the x, cos for the y
230 chassis.moveToPoint(chassis.getPose().x+3.55, chassis.getPose().y-14, 2000, {.forwards=false, .minSpeed=25});
231 chassis.waitUntilDone();
232 SweeperControl.retract();
233 pros::delay(250);
234
235 chassis.turnToHeading(-170, 1000, {.direction=AngularDirection::CCW_COUNTERCLOCKWISE});
236 std::cout << chassis.getPose().x << " + " << chassis.getPose().y << std::endl;
237 std::cout << chassis.getPose().x << " + " << chassis.getPose().y+8 << std::endl;
238
239 chassis.moveToPoint(chassis.getPose().x, chassis.getPose().y+21, 1500, {.forwards=false}, false);
240 LatchControl.extend();
241 pros::delay(750);
242
243 std::cout << chassis.getPose().x << " + " << chassis.getPose().y << std::endl;
244
245 //chassis.turnToPoint(29, -12, 750, {.forwards=false, .direction=AngularDirection::CCW_COUNTERCLOCKWISE});
246 chassis.moveToPoint(29, -12, 2500, {.forwards=true}, true);
247 chassis.waitUntil(10);
248
249 HookMotor.move_velocity(200);
250 chassis.turnToPoint(4, -14, 1000);
251 chassis.waitUntilDone();
252
253 LatchControl.retract();
254 chassis.moveToPoint(4, -14, 2500);
255 HookMotor.move_velocity(0);
256
257 pros::delay(250);
258 chassis.moveToPose(35, 24, -180, 2500, {.forwards=false, .lead=0.6}, false);
259
260 LatchControl.extend();
261 pros::delay(250);
262 HookMotor.move_velocity(200);
263 pros::delay(250);
264
265 if (!elims) {
266 chassis.moveToPose(48, 38, -135, 2000, {.forwards=false, .horizontalDrift=5.5});
267 chassis.waitUntil(6);
268 HookMotor.move_velocity(0);
269 pros::Task move([&]() { ladybrown.MoveToPoint(LadyBrown::LOAD_STATE); }, "LadyBrownMove");
270
271 }
272 else {
273 pros::delay(150);
274 chassis.moveToPoint(3.5, -3, 1000, {.minSpeed=20, .earlyExitRange=10});
275 chassis.waitUntil(4);
276 IntakeMotor.move_velocity(0);
277 }
278
279
280 //LatchControl.retract();
281
282 // Move to first stake
283
284
285}
pros::adi::Pneumatics SweeperControl('B', false)

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), ladybrown, Robot::Globals::LatchControl(), Robot::LadyBrown::LOAD_STATE, and Robot::Globals::SweeperControl().

Referenced by AutoDrive().

◆ BluePosLateGoalRush()

void Autonomous::BluePosLateGoalRush ( Intake & intake,
Latch & latch,
Sweeper & sweeper,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Definition at line 330 of file autons.cpp.

330 {
331
332 // drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
333 // chassis.setPose(0, 0,0);
334
335 // // Move to first stake
336 // chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
337 // chassis.waitUntilDone();
338 // // Grab the closest MOGO mech
339 // latch.toggle();
340 // pros::delay(250);
341
342 // // Rotate toward blue ring
343 // chassis.turnToPoint(25, -27, 1000);
344 // chassis.waitUntilDone();
345
346 // // Load the ring onto the stake
347 // IntakeMotor.move_velocity(600);
348 // HookMotor.move_velocity(200);
349
350 // // Moves to 2 ring stack
351 // chassis.moveToPoint(25, -27, 1250, {.forwards = true});
352 // chassis.turnToPoint(25, 0, 1000, {.forwards = false});
353 // chassis.waitUntilDone();
354
355 // // Moves goal to corner
356 // chassis.moveToPoint(28, 3, 1250, {.forwards = false});
357 // chassis.waitUntilDone();
358
359 // HookMotor.brake();
360 // latch.toggle();
361
362 // // Move to Third goal
363 // chassis.moveToPoint(25, -30, 1500, {.forwards = true},true);
364 // chassis.turnToPoint(25, -40, 1000, {.forwards = false});
365 // chassis.moveToPoint(25, -38,1000, {.forwards = false});
366
367
368 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
369 //chassis.setPose(0, 0,0);
370
371 chassis.setPose(12, -9, 112);
372
374
375 chassis.moveToPose(0, 28, -180, 2000, {.forwards=false, .horizontalDrift=5.5});
376
377 // Move to first stake
378 //chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
379
381 chassis.waitUntilDone();
382 // Grab the closest MOGO mech
383 latch.toggle();
384 pros::delay(250);
385
386 // Rotate toward blue ring
387 chassis.turnToPoint(-25, 27, 1000);
388 chassis.waitUntilDone();
389
390 // Load the ring onto the stake
391 IntakeMotor.move_velocity(600);
392 HookMotor.move_velocity(200);
393
394 // Moves to 2 ring stack
395 chassis.moveToPoint(-27, 27, 1250, {.forwards = true});
396 chassis.turnToPoint(-19, 0, 1000, {.forwards = false});
397 chassis.waitUntilDone();
398
399 // Moves goal to corner
400 chassis.moveToPoint(0, 18, 1250, {.forwards = false});
401 chassis.waitUntilDone();
402 HookMotor.brake();
403 latch.toggle();
404
405 // Move to Third goal
406 chassis.moveToPoint(-25, 26, 1500, {.forwards = true},true);
407 chassis.turnToPoint(-25, 36, 1000, {.forwards = false});
408 chassis.moveToPoint(-25, 34,1000, {.forwards = false});
409}
void toggle()
Toggles latch state.
Definition latch.cpp:16

References Robot::LadyBrown::ATTACK_STATE, Robot::LadyBrown::BASE_STATE, Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), ladybrown, and Robot::Latch::toggle().

Referenced by AutoDrive().

◆ RedNeg()

void Autonomous::RedNeg ( Intake & intake,
Latch & latch,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Runs the autonomous path for the far side defensive game strategy.

This function executes the autonomous path for the far side defensive game strategy. It contains the specific actions and movements required for this strategy.

Definition at line 22 of file autons.cpp.

22 {
23
24 //
25
26 HookMotor.set_zero_position(HookMotor.get_position());
27 colorSensor.set_led_pwm(70);
28 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
29 //Edge of lady brown is 5.5 inches from the alliance wall stake.
30 chassis.setPose(0, 0, 112);
31
33
34 chassis.moveToPose(-11, 44, 180, 2000, {.forwards=false, .horizontalDrift=5.5});
35
37 chassis.waitUntilDone();
38 LatchControl.extend();
39 pros::delay(250);
40 chassis.swingToPoint(-28, 54.5, lemlib::DriveSide::RIGHT, 1500, { .direction=AngularDirection::CW_CLOCKWISE });
41
42 IntakeMotor.move_velocity(600);
43 HookMotor.move_velocity(200);
44 chassis.moveToPoint(-28, 54.5, 5000);
45 chassis.turnToPoint(-42, 55, 5000);
46
47 chassis.moveToPoint(-42, 55, 2500, {.minSpeed = 75}, false);
48 pros::delay(750);
49
50 chassis.turnToPoint(-19, 40, 1000, {.forwards=false});
51 chassis.moveToPoint(-19, 40, 1000, {.forwards=false});
52 chassis.turnToPoint(-40, 39, 1000);
53 chassis.moveToPoint(-40, 39, 1000);
54
55 // chassis.turnToPoint(7.5, 39, 1000, {.direction=AngularDirection::CW_CLOCKWISE});
56 // chassis.moveToPoint(7.5, 39, 7500, {.minSpeed=25, .earlyExitRange=15});
57 // chassis.waitUntil(18);
58 // IntakeMotor.brake();
59
60 chassis.turnToPoint(9, 16.5, 1000, {.direction=AngularDirection::CW_CLOCKWISE});
61 chassis.moveToPoint(9, 16.5, 7500, {.minSpeed=25, .earlyExitRange=15});
62 chassis.waitUntil(13);
63 IntakeLift.extend();
64
65 // chassis.moveToPoint(9, 16.5, 7500, {.maxSpeed=25});
66
67}

References Robot::LadyBrown::ATTACK_STATE, Robot::LadyBrown::BASE_STATE, Robot::Globals::chassis(), Robot::Globals::colorSensor(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeLift(), Robot::Globals::IntakeMotor(), ladybrown, and Robot::Globals::LatchControl().

Referenced by AutoDrive().

◆ RedPos()

void Autonomous::RedPos ( Intake & intake,
Latch & latch,
Sweeper & sweeper,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Runs the autonomous path for the near side offensive game strategy.

This function executes the autonomous path for the near side offensive game strategy. It contains the specific actions and movements required for this strategy.

Definition at line 114 of file autons.cpp.

114 {
115
116 bool elims = true;
117 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
118 chassis.setPose(0, 0,-12);
119 chassis.moveToPoint(-14, 35, 2500, {.minSpeed=45, .earlyExitRange=2});
120 IntakeMotor.move_velocity(600);
121 chassis.waitUntilDone();
122 //lesser angle due to doinker displacement
123 chassis.turnToHeading(0, 300);
124 SweeperControl.extend();
125 //Use sin for the x, cos for the y
126 chassis.moveToPoint(chassis.getPose().x-3.55, chassis.getPose().y-14, 2000, {.forwards=false, .minSpeed=25});
127 chassis.waitUntilDone();
128 SweeperControl.retract();
129 pros::delay(250);
130 // Same turn to the mogo
131 chassis.turnToHeading(-170, 1000, {.direction=AngularDirection::CCW_COUNTERCLOCKWISE});
132 std::cout << chassis.getPose().x << " + " << chassis.getPose().y << std::endl;
133 std::cout << chassis.getPose().x << " + " << chassis.getPose().y+8 << std::endl;
134
135 chassis.moveToPoint(chassis.getPose().x+8, chassis.getPose().y+21, 1500, {.forwards=false}, false);
136 LatchControl.extend();
137 pros::delay(750);
138
139 std::cout << chassis.getPose().x << " + " << chassis.getPose().y << std::endl;
140
141 //chassis.turnToPoint(29, -12, 750, {.forwards=false, .direction=AngularDirection::CCW_COUNTERCLOCKWISE});
142 chassis.moveToPoint(-29, -12, 2500, {.forwards=true}, true);
143 chassis.waitUntil(10);
144
145 HookMotor.move_velocity(200);
146 chassis.turnToPoint(-2, -14, 1000);
147 chassis.waitUntilDone();
148
149 LatchControl.retract();
150 chassis.moveToPoint(-2, -14, 2500);
151 HookMotor.move_velocity(0);
152
153 pros::delay(250);
154 chassis.moveToPose(-35, 28, -180, 2500, {.forwards=false, .lead=0.6}, false);
155
156 LatchControl.extend();
157 pros::delay(250);
158 HookMotor.move_velocity(200);
159 pros::delay(250);
160
161 if (!elims) {
162 chassis.moveToPose(-48, 38, -135, 2000, {.forwards=false, .horizontalDrift=5.5});
163 chassis.waitUntil(6);
164 HookMotor.move_velocity(0);
165 pros::Task move([&]() { ladybrown.MoveToPoint(LadyBrown::LOAD_STATE); }, "LadyBrownMove");
166
167 }
168 else {
169 pros::delay(150);
170 chassis.moveToPoint(-3.5, -3, 1000, {.minSpeed=20, .earlyExitRange=10});
171 chassis.waitUntil(4);
172 IntakeMotor.move_velocity(0);
173 }
174
175}

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), ladybrown, Robot::Globals::LatchControl(), Robot::LadyBrown::LOAD_STATE, and Robot::Globals::SweeperControl().

Referenced by AutoDrive().

◆ RedPosLateGoalRush()

void Autonomous::RedPosLateGoalRush ( Intake & intake,
Latch & latch,
Sweeper & sweeper,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Definition at line 411 of file autons.cpp.

411 {
412
413 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
414 //chassis.setPose(0, 0,0);
415
416 // Move to first stake
417 // chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
418 // chassis.waitUntilDone();
419 // // Grab the closest MOGO mech
420 // latch.toggle();
421 // pros::delay(250);
422
423 // // Rotate toward blue ring
424 // chassis.turnToPoint(-25, -27, 1000);
425 // chassis.waitUntilDone();
426
427 // // Load the ring onto the stake
428 // IntakeMotor.move_velocity(600);
429 // HookMotor.move_velocity(200);
430
431 // // Moves to 2 ring stack
432 // chassis.moveToPoint(-25, -27, 1250, {.forwards = true});
433 // chassis.turnToPoint(-25, 0, 1000, {.forwards = false});
434 // chassis.waitUntilDone();
435
436 // // Moves goal to corner
437 // chassis.moveToPoint(-28, 3, 1250, {.forwards = false});
438 // chassis.waitUntilDone();
439 // HookMotor.brake();
440 // latch.toggle();
441
442 // // Move to Third goal
443 // chassis.moveToPoint(-25, -30, 1500, {.forwards = true},true);
444 // chassis.turnToPoint(-25, -40, 1000, {.forwards = false});
445 // chassis.moveToPoint(-25, -38,1000, {.forwards = false});
446
447 drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
448 //chassis.setPose(0, 0,0);
449
450 chassis.setPose(-12, -9, -112);
451
453
454 chassis.moveToPose(0, 30, -180, 2000, {.forwards=false, .horizontalDrift=5.5});
455
456 // Move to first stake
457 //chassis.moveToPose(0, -28, 0, 2000, {.forwards = false});
458
460 chassis.waitUntilDone();
461 // Grab the closest MOGO mech
462 latch.toggle();
463 pros::delay(250);
464
465 // Rotate toward blue ring
466 chassis.turnToPoint(25, 27, 1000);
467 chassis.waitUntilDone();
468
469 // Load the ring onto the stake
470 IntakeMotor.move_velocity(600);
471 HookMotor.move_velocity(200);
472
473 // Moves to 2 ring stack
474 chassis.moveToPoint(27, 27, 1250, {.forwards = true});
475 chassis.turnToPoint(19, 0, 1000, {.forwards = false});
476 chassis.waitUntilDone();
477
478 // Moves goal to corner
479 chassis.moveToPoint(10, -7, 1250, {.forwards = false});
480 chassis.waitUntilDone();
481 HookMotor.brake();
482 latch.toggle();
483
484 // Move to Third goal
485 chassis.moveToPoint(25, 26, 1500, {.forwards = true},true);
486 chassis.turnToPoint(25, 36, 1000, {.forwards = false});
487 chassis.moveToPoint(25, 34,1000, {.forwards = false});
488}

References Robot::LadyBrown::ATTACK_STATE, Robot::LadyBrown::BASE_STATE, Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), ladybrown, and Robot::Latch::toggle().

Referenced by AutoDrive().

◆ Skills()

void Autonomous::Skills ( Intake & intake,
Latch & latch,
DistanceSensor & distance,
LadyBrown & ladybrown )
private

Executes the Skills challenge autonomous.

This function controls the robot's actions during autonomous routine 5. It takes references to the Intake and Latch objects as parameters.

Parameters
intakeThe reference to the Intake object.
latchThe reference to the Latch object.

Definition at line 16 of file skills.cpp.

16 {
17
18 // Set pre-constants
19 HookMotor.set_zero_position(HookMotor.get_position());
20 colorSensor.set_led_pwm(70);
21 //drive_.set_brake_mode_all(pros::E_MOTOR_BRAKE_BRAKE);
22 chassis.setPose(-5.25, 7.75, 180);
23
24 //Autonomous routine for the Skills challenge - 60 seconds MAX
25 /* ##############################################*/
26
27 // De-hook into the alliance stake
29
30 // //Move to the center, then turn to and touch the right side Mogo.
31 //chassis.moveToPoint(-5.25, 15, 800, {.forwards = false});
32
33 //NOTE - MOGO INCONSISTENT BECAUSE OF INCORRECT ANGLE
34 chassis.turnToPoint(24, 15.5, 1000, {.forwards = false});
35 //chassis.moveToPoint(17.5, 15, 1850, {.forwards = false, .earlyExitRange=0.5}, false);
36 chassis.moveToPoint(24, 15.5, 2000, {.forwards = false, .minSpeed=25, .earlyExitRange=18});
37 chassis.moveToPoint(25, 15.5, 1000, {.forwards=false, .maxSpeed=30});
38 chassis.waitUntilDone();
39
40 // //Latch the mogo - delays just in case
41 LatchControl.extend();
42 pros::delay(250);
43
44 // //Turn to the above ring - Start intake and hook, and move there
45 chassis.turnToPoint(24, 38.75, 850, {}, true);
47 chassis.waitUntilDone();
48 IntakeMotor.move_velocity(600);
49 HookMotor.move_velocity(200);
50 chassis.waitUntilDone();
51 chassis.moveToPoint(24, 38.75, 1000);
52
53 // Immediately move to the farthest ring. A couple of other things happen while this is going on
54 chassis.moveToPose(48, 90, 0, 2050, {.horizontalDrift = 8, .lead = 0.45, .earlyExitRange=2}, true);
55 //Checks between 10-45 inches of movement for if the hook got stuck on the mogo flower
56 for (int i = 10; i<45; i += 5) {
57 chassis.waitUntil(i);
58 std::cout << "velocity" << HookMotor.get_actual_velocity() << std::endl;
59 //Checks every 5 inches for if the hook gets stuck.
60 while (HookMotor.get_actual_velocity() < 25 && !(colorSensor.get_hue() < 30 && colorSensor.get_hue() > 8)) {
61 //FIX: The hook is lifted back and then hit into the target to ensure fit.
62 HookMotor.move_velocity(-200);
63 pros::delay(150);
64 HookMotor.move_velocity(200);
65 pros::delay(350);
66 }
67 //Lift up the Lady brown to load onto at 40 inches from the last position.
68 }
69
70 chassis.waitUntil(50);
72
73
74
75 //Set the hook to a high-torque rpm to get the best loading possible, waits for the MoveToPose to end.
76 HookMotor.move_velocity(200);
77 chassis.waitUntilDone();
78 //Turn to a point ~1.5 tiles away from the right neutral stake
79 chassis.turnToPoint(41, 61.5, 800, {.forwards=false});
80
81 //Actually move there
82 chassis.moveToPoint(41, 61.5,1500, {.forwards=false}, true);
83
84 chassis.waitUntilDone();
85
86 //Turn to the Neutral wall stake.
87 //chassis.turnToPoint(79, 63.5, 750);
88 chassis.turnToPoint(72, 61.5,800);
89 // Move there
90 chassis.moveToPoint(68, 61.5,1500, {.forwards=true, .maxSpeed=75, .minSpeed=50, .earlyExitRange=6}, true);
91
92 // At 18 inches of movement, stop the intake in advance of the neutral wall stake
93 chassis.waitUntil(18);
94 IntakeMotor.brake();
95 HookMotor.brake();
96
97
98 chassis.waitUntilDone();
99
100 //Allow the robot to settle, then move the lady brown to score on the neutral stake.
101
103 pros::delay(150);
104
105 //Move back to the 5th tile edge, and restart the intake 15 inches into the movement.
106 chassis.moveToPoint(47.5, 61.5, 750, {.forwards = false, .maxSpeed = 75});
107 IntakeMotor.move_velocity(600);
108 chassis.waitUntil(5);
110
111 //Point the robot towards the home side wall, and put the lady brown down.
112 chassis.turnToPoint(47.5, 0, 950);
113 HookMotor.move_velocity(200);
114
115
116 //Go close to the wall, but exit early so that the robot glides to the last ring.
117 chassis.moveToPoint(47.5, -3, 2500, {.forwards = true, .maxSpeed = 50, .earlyExitRange=2});
118
119 //Start the hook at a higher speed rpm
120 HookMotor.move_velocity(200);
121
122 // Start at 10 inches into the movement - schedule a check every 5 inches for if the hook is stuck.
123 chassis.waitUntil(10);
124 for (int i = 12; i<47; i += 5) {
125 chassis.waitUntil(i);
126 std::cout << "velocity" << HookMotor.get_actual_velocity() << std::endl;
127 while (HookMotor.get_actual_velocity() < 25 && !(colorSensor.get_hue() < 30 && colorSensor.get_hue() > 8)) {
128 //FIX: The hook is lifted back and then hit into the target to ensure fit.
129 HookMotor.move_velocity(-200);
130 pros::delay(150);
131 HookMotor.move_velocity(200);
132 pros::delay(350);
133 }
134 }
135
136 chassis.waitUntilDone();
137 //Wait for two seconds at the edge to ensure rings get put onto the mogo.
138 pros::delay(1000);
139
140 //Turn, then Move to the point where the last ring was nudged to collect it for top ring
141 chassis.turnToPoint(61, 17, 1000);
142 chassis.moveToPoint(61, 17, 1000, {.forwards = true, .maxSpeed = 50, .earlyExitRange=4});
143
144
145 //Turn away to position the mogo in the corner, waiting to let the hook put all items onto the mogo.
146 chassis.turnToHeading(-30, 1000, {.direction = AngularDirection::CCW_COUNTERCLOCKWISE}, false);
147 pros::delay(700);
148 //Let the last ring go when the hook gets stuck
149 HookMotor.move_velocity(-200);
150 //Let the mogo go
151 LatchControl.retract();
152
153 //Move back a little to ensure the mogo goes into the corner.
154 chassis.moveToPoint(64.5, 0, 1200, {.forwards = false, .maxSpeed = 70, .earlyExitRange=1.5}, false);
155
156 // Stop the intake and hook.
157 IntakeMotor.brake();
158 HookMotor.brake();
159
160 //Move to the top edge of the first tile, preparing for alignment. Then move back into the wall to use the distance sensor to reorient.
161 chassis.moveToPose(48, 20, -90, 1000, {.forwards = true, .horizontalDrift=9}, false);
162 LatchControl.extend();
163 chassis.moveToPoint(68, 20, 1350, {.forwards = false}, false);
164
165 // Get the distance to the wall using the distance sensor, convert to inches and add the distance to tracking center (5in).
166 // Then, set the new position
167 //float new_x = (float)(72 - 8);
168 float new_x = (float)(72 - 8);
169 std::cout << "Distance: " << new_x << std::endl;
170 std::cout << "Distance: " << (float)(72) / (float)10 / (float)2.54 << std::endl;
171 std::cout << "Distance: " << distance.get_distance() << std::endl;
172 chassis.setPose(new_x, chassis.getPose().y, -90);
173 chassis.moveToPoint(chassis.getPose().x-5, chassis.getPose().y, 600, { .minSpeed=60, .earlyExitRange=2}, false);
174
175 //TODO: ADJUST DISTANCE VALUES FOR RESET
176 // float new_y = ((float)(distance.get_distance()) / (float)10 / (float)2.54 + (float)6.5 - (float)8.75);
177 //chassis.moveToPose(0, 15, -90, 1500, {.horizontalDrift = 8, .minSpeed = 15});
178
179 chassis.turnToPoint(-26, 12.5, 1000, {.forwards=false});
180 LatchControl.retract();
181 chassis.moveToPoint(-26, 12.5, 5000, {.forwards = false, .minSpeed=50, .earlyExitRange=26});
182 chassis.moveToPoint(-26, 12.5, 1000, {.forwards = false, .maxSpeed=45});
183
184 //chassis.moveToPoint(-21, 15, 700, {.forwards = false, .maxSpeed=70}, false);
185 chassis.waitUntilDone();
186 //Latch the mogo - delays just in case
187 LatchControl.extend();
188 pros::delay(250);
189
190 //Turn to the above ring - Start intake and hook, and move there
191 chassis.turnToPoint(-24, 38.75, 850, {}, false);
192 IntakeMotor.move_velocity(600);
193 HookMotor.move_velocity(200);
194 chassis.moveToPoint(-24, 38.75, 1000);
195
196 // Immediately move to the farthest ring. A couple of other things happen while this is going on
197 chassis.moveToPose(-48, 90, 0, 2050, {.horizontalDrift = 8, .lead = 0.54}, true);
198 //Checks between 10-45 inches of movement for if the hook got stuck on the mogo flower
199 for (int i = 10; i<45; i += 5) {
200 chassis.waitUntil(i);
201 std::cout << "velocity" << HookMotor.get_actual_velocity() << std::endl;
202 //Checks every 5 inches for if the hook gets stuck.
203 while (HookMotor.get_actual_velocity() < 25 && !(colorSensor.get_hue() < 30 && colorSensor.get_hue() > 8)) {
204 //FIX: The hook is lifted back and then hit into the target to ensure fit.
205 HookMotor.move_velocity(-200);
206 pros::delay(150);
207 HookMotor.move_velocity(200);
208 pros::delay(350);
209 }
210 //Lift up the Lady brown to load onto at 40 inches from the last position.
211 }
212
213 //Set the hook to a high-torque rpm to get the best loading possible, waits for the MoveToPose to end.
214 chassis.waitUntil(50);
215
216 HookMotor.move_velocity(200);
217
218 chassis.waitUntilDone(); //Turn to a point ~1.5 tiles away from the right neutral stake
220 chassis.turnToPoint(-43, 60.5, 800, {.forwards=false});
221
222 //Actually move there
223 chassis.moveToPoint(-43, 60.5, 1500, {.forwards=false}, true);
224
225
226 // Wait until 20 inches passed to get to the point behind the lady brown - stop the hook here.
227
228
229 chassis.waitUntilDone();
230
231 chassis.turnToPoint(-78, 60.5, 660);
232
233
234 // Move there
235 chassis.moveToPoint(-72.5, 60.5, 1020, {.forwards=true, .maxSpeed=75, .minSpeed=50, .earlyExitRange=6}, true);
236
237 // At 18 inches of movement, stop the intake in advan.;;;78yce of the neutral wall stake
238 chassis.waitUntil(18);
239 IntakeMotor.brake();
240 HookMotor.brake();
241
242 chassis.waitUntilDone();
243
244 //Allow the robot to settle, then move the lady brown to score on the neutral stake.
246
247 //Move back to the 5th tile edge, and restart the intake 15 inches into the movement.
248 chassis.moveToPoint(-47, 60.5, 750, {.forwards = false, .maxSpeed = 75});
249 IntakeMotor.move_velocity(600);
250 chassis.waitUntil(5);
252
253
254 //Point the robot towards the home side wall, and put the lady brown down.
255 chassis.turnToPoint(-47, 0, 950);
256 HookMotor.move_velocity(200);
257
258 //Go close to the wall, but exit early so that the robot glides to the last ring.
259 chassis.moveToPoint(-47, 0, 2750, {.forwards = true, .maxSpeed = 60, .minSpeed=30, .earlyExitRange=4});
260
261 //Start the hook at a higher speed rpm
262 HookMotor.move_velocity(200);
263
264 // Start at 10 inches into the movement - schedule a check every 5 inches for if the hook is stuck.
265 chassis.waitUntil(10);
266 for (int i = 12; i<47; i += 5) {
267 chassis.waitUntil(i);
268 std::cout << "velocity" << HookMotor.get_actual_velocity() << std::endl;
269 while (HookMotor.get_actual_velocity() < 25 && !(colorSensor.get_hue() < 30 && colorSensor.get_hue() > 8)) {
270 //FIX: The hook is lifted back and then hit into the target to ensure fit.
271 HookMotor.move_velocity(-200);
272 pros::delay(150);
273 HookMotor.move_velocity(200);
274 pros::delay(350);
275 }
276 }
277
278 chassis.waitUntilDone();
279 //Wait for two seconds at the edge to ensure rings get put onto the mogo.
280 pros::delay(1000);
281
282 //Turn, then Move to the point where the last ring was nudged to collect it for top ring
283 chassis.turnToPoint(-62, 17, 1000);
284 chassis.moveToPoint(-62, 17, 2000, {.forwards = true, .maxSpeed = 50, .earlyExitRange=4});
285
286
287 //Turn away to position the mogo in the corner, waiting to let the hook put all items onto the mogo.
288 chassis.turnToHeading(30, 1000, {}, false);
289 pros::delay(1000);
290 //Let the last ring go when the hook gets stuck
291 HookMotor.move_velocity(-200);
292 pros::delay(200);
293 //Let the mogo go
294 LatchControl.retract();
295
296 //Move back a little to ensure the mogo goes into the corner.
297 chassis.moveToPoint(-62.5, 2, 1000, {.forwards = false, .maxSpeed = 50, .earlyExitRange=1.5}, false);
298
299 // Stop the intake and hook.
300 IntakeMotor.brake();
301 HookMotor.brake();
302
303 //Move to the top edge of the first tile, preparing for alignment. Then move back into the wall to use the distance sensor to reorient.
304 chassis.moveToPoint(-15, 110.5, 7000, {.forwards = true, .maxSpeed = 100, .minSpeed=40, .earlyExitRange=6}, true);
305 //chassis.moveToPoint(70, 132.5, 1500);
306
307 chassis.moveToPose(-70, 128, -75, 5000);
308
309 chassis.moveToPoint(-6, 114, 3000, {.forwards=false}, false);
310
311 SweeperControl.extend();
312
313 chassis.turnToPoint(68, 125, 1000);
314
315 chassis.moveToPoint(68, 125, 3000, {.forwards=true, .minSpeed=30, .earlyExitRange=6});
316
317 chassis.waitUntil(10);
318 SweeperControl.retract();
319}

References Robot::LadyBrown::ATTACK_STATE, Robot::LadyBrown::BASE_STATE, Robot::Globals::chassis(), Robot::Globals::colorSensor(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), ladybrown, Robot::Globals::LatchControl(), Robot::LadyBrown::LOAD_STATE, and Robot::Globals::SweeperControl().

Referenced by AutoDrive().

Member Data Documentation

◆ auton

Autonomous::AUTON_ROUTINE Autonomous::auton = RED_POS
static

Sets the number of the autonomous program to use.

This function allows the user to specify the autonomous program to be executed by the robot. The autonomous program number determines the specific actions and movements the robot will perform.

Parameters
autonThe number of the autonomous program to use.

Definition at line 28 of file auton.h.

Referenced by AutoDrive(), autonomous(), and AutonSwitcher().

◆ autonName

std::string Autonomous::autonName = "Red Positive"
static

The name of the autonomous program.

This variable stores the name of the autonomous program currently selected. It is handled by the switching functions and the screen.

Definition at line 35 of file auton.h.

Referenced by AutoDrive(), and AutonSwitcher().


The documentation for this class was generated from the following files: