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 "pros/motors.h"
3#include "robot/auton.h"
4#include "globals.h"
5#include "lemlib/chassis/chassis.hpp"
6#include "main.h" // IWYU pragma: export
7#include "pros/rtos.hpp"
8#include "robot/ladybrown.h"
9#include "robot/sweeper.h"
10#include <iostream>
11
12using namespace Robot;
13using namespace Robot::Globals;
14
15// Skills
16void Autonomous::Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown) {
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
28 ladybrown.MoveToPoint(LadyBrown::ATTACK_STATE, 150, 750);
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);
109 ladybrown.MoveToPoint(LadyBrown::BASE_STATE);
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
219 ladybrown.MoveToPoint(LadyBrown::LOAD_STATE);
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);
251 ladybrown.MoveToPoint(LadyBrown::BASE_STATE);
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}
void Skills(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown)
Definition skills.cpp:16
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
The Latch class represents a latching mechanism.
Definition latch.h:8
Robot::LadyBrown ladybrown
Definition intake.cpp:19
pros::adi::Pneumatics LatchControl('A', false)
pros::Optical colorSensor(5)
pros::Motor IntakeMotor(-4, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees)
pros::adi::Pneumatics SweeperControl('B', false)
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)
Definition auton.h:10