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)
 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)
 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 295 of file autons.cpp.

296 {
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}
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 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
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

References auton, autonName, BLUE_NEG, BLUE_POS, BLUE_POS_LATE_RUSH, BlueNeg(), BluePos(), BluePosLateGoalRush(), 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 331 of file autons.cpp.

331 {
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}

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 )
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 277 of file autons.cpp.

277 {
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}
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::Motor HookMotor(7, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees)
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), 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 81 of file autons.cpp.

81 {
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}
void MoveToPoint(LadyBrown::LADYBROWN_STATE state, int max_error=150, int timeout=1000)
Definition ladybrown.cpp:72
void toggle()
Toggles latch state.
Definition latch.cpp:16
pros::adi::Pneumatics SweeperControl('B', false)

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), Robot::LadyBrown::LOAD_STATE, Robot::LadyBrown::MoveToPoint(), Robot::Globals::SweeperControl(), and Robot::Latch::toggle().

Referenced by AutoDrive().

◆ BluePosLateGoalRush()

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

Definition at line 124 of file autons.cpp.

124 {
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}

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), and Robot::Latch::toggle().

Referenced by AutoDrive().

◆ RedNeg()

void Autonomous::RedNeg ( Intake & intake,
Latch & latch,
DistanceSensor & distance )
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 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}

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), 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 39 of file autons.cpp.

39 {
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}

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), Robot::LadyBrown::LOAD_STATE, Robot::LadyBrown::MoveToPoint(), Robot::Globals::SweeperControl(), and Robot::Latch::toggle().

Referenced by AutoDrive().

◆ RedPosLateGoalRush()

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

Definition at line 199 of file autons.cpp.

199 {
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}

References Robot::Globals::chassis(), Robot::Globals::drive_(), Robot::Globals::HookMotor(), Robot::Globals::IntakeMotor(), 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 13 of file skills.cpp.

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

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

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: