1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
skills.cpp
Go to the documentation of this file.
1#include "electronic/distance.h"
2#include "robot/auton.h"
3#include "globals.h"
4#include "lemlib/chassis/chassis.hpp"
5#include "main.h" // IWYU pragma: export
6#include "pros/rtos.hpp"
7#include <iostream>
8
9using namespace Robot;
10using namespace Robot::Globals;
11
12// Skills
13void Autonomous::Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown) {
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}
void Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Definition skills.cpp:13
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
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)
pros::Optical colorSensor(4)
Definition auton.h:10