1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
autonFunctions.cpp File Reference
#include "main.h"
#include "globals.h"
#include "pros/misc.h"
#include "lemlib/api.hpp"
#include "lemlib/util.hpp"
#include "pros/motors.h"
#include "pros/rtos.hpp"
#include <cmath>
#include "colorSort.h"

Go to the source code of this file.

Functions

void intake (int power=12000)
void outtake (int power=12000)
void score_bottomgoal (int power=12000)
void score_longgoal (int power=12000, Color allianceColor=Color::RED)
void intake_stop ()
void score_midgoal (int power=12000)
void score_midgoal_auton (int power=12000, Color allianceColor=Color::RED, int time=-1)
void score_longgoal_auton (int power=12000, Color allianceColor=Color::RED, int time=-1)
void intake_to_basket ()
void resting_state (bool trapDoor_commanded=false)
void matchload_state (bool state)
void matchload_wiggle (int time=1000, int speed=100)
void relativeMotion (float expected_x, float expected_y, float expected_theta, float distance, int timeout_ms, bool forw=true, float earlyExit=0)
void matchload_counter (int balls, int time_ms)
void alignToGoal (double targetAngle)
double calculateAngle (double robotHeading)

Function Documentation

◆ alignToGoal()

void alignToGoal ( double targetAngle)

Definition at line 256 of file autonFunctions.cpp.

256 {
257
258 pros::Task([=]() {
259
260 double currentTheta = chassis.getPose().theta;
261 double error = std::remainder(targetAngle - currentTheta, 360.0);
262 if (std::abs(error) > 5.0) {
263 std::cout << "Error big enough to activate alignment " << error << std::endl;
264 if (error > 0) {
265 leftMotors.move(-100);
266 rightMotors.move(0);
267 } else {
268 leftMotors.move(0);
269 rightMotors.move(-100);
270 }
271 pros::delay(std::clamp((int)error * 100, 300, 1000));
272 }
273
274 leftMotors.brake();
275 rightMotors.brake();
276 chassis.tank(0,0);
277 pros::Task::current().remove();
278 });
279}
pros::MotorGroup rightMotors
lemlib::Chassis chassis
pros::MotorGroup leftMotors
Definition globals.cpp:22

References chassis, leftMotors, and rightMotors.

◆ calculateAngle()

double calculateAngle ( double robotHeading)

Definition at line 281 of file autonFunctions.cpp.

281 {
282 double d1 = frontDistance.get();
283 double d2 = frontDistance2.get() + 10;
284
285 if (d1 > 1800 || d2 > 1800) return -1;
286 double wallAngleDeg = atan2((d1 - d2) * 0.0393701, 10.75) * 180.0 / M_PI;
287
288 if ((robotHeading >= 315 && robotHeading < 360) || (robotHeading >= 0 && robotHeading < 45)) {
289 return wallAngleDeg;
290 }
291 else if (robotHeading >= 45 && robotHeading < 135) {
292 return 90 + wallAngleDeg;
293 }
294 else if (robotHeading >= 135 && robotHeading < 225) {
295 return 180 + wallAngleDeg;
296 }
297 else if (robotHeading >= 225 && robotHeading < 315) {
298 return 270 + wallAngleDeg;
299 }
300
301 return -1;
302}
pros::Distance frontDistance(14)
pros::Distance frontDistance2(17)

References frontDistance(), and frontDistance2().

◆ intake()

void intake ( int power = 12000)

Definition at line 11 of file autonFunctions.cpp.

12{
13 intakeFunnel.extend();
14 intakeMotor.move_voltage(power);
15 topMotor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
16 topMotor.brake();
17}
pros::Motor intakeMotor(18, pros::v5::MotorGears::blue)
pros::Motor topMotor(19, pros::v5::MotorGears::blue)
pros::adi::Pneumatics intakeFunnel('B', true)

References intakeFunnel(), intakeMotor(), and topMotor().

Referenced by awp_auton(), elim_auton(), intake_to_basket(), left_auton(), opcontrol(), right_auton(), score_longgoal(), score_midgoal_auton(), and skills_auton().

◆ intake_stop()

void intake_stop ( )

Definition at line 56 of file autonFunctions.cpp.

57{
58 intakeMotor.move_voltage(0);
59 topMotor.move_voltage(0);
60}

References intakeMotor(), and topMotor().

Referenced by elim_auton(), left_auton(), matchload_counter(), resting_state(), right_auton(), score_longgoal_auton(), and skills_auton().

◆ intake_to_basket()

void intake_to_basket ( )

Definition at line 167 of file autonFunctions.cpp.

168{
169 intake();
170 topMotor.move_voltage(-8000);
171}
void intake(int power=12000)

References intake(), and topMotor().

◆ matchload_counter()

void matchload_counter ( int balls,
int time_ms )

Definition at line 228 of file autonFunctions.cpp.

229{
230 pros::Task counter_task([=]() {
231 int count = 0;
232 uint32_t start_time = pros::millis();
233 while(pros::millis() - start_time < time_ms && count < balls)
234 {
235 start_time = pros::millis();
236 if(frontDistance.get_object_size() <= 70)
237 {
238 count++;
239 }
240 pros::Task::delay_until(&start_time, 10);
241 }
242 intake_stop();
243 pros::Task::current().remove();
244 });
245}
void intake_stop()

References frontDistance(), and intake_stop().

◆ matchload_state()

void matchload_state ( bool state)

Definition at line 181 of file autonFunctions.cpp.

182{
183 if(state)
184 matchload.extend();
185 else if(!state)
186 matchload.retract();
187}
pros::adi::Pneumatics matchload('E', false)

References matchload().

Referenced by awp_auton(), elim_auton(), left_auton(), right_auton(), and skills_auton().

◆ matchload_wiggle()

void matchload_wiggle ( int time = 1000,
int speed = 100 )

Definition at line 190 of file autonFunctions.cpp.

191{
192 uint32_t startTime = pros::millis();
193 double initialHeading = chassis.getPose().theta;
194 double targetHeading = std::round(initialHeading / 90.0) * 90.0;
195 bool flip = false;
196
197 while ((pros::millis() - startTime) < time) {
198 if (flip) {
199 leftMotors.move(-speed);
200 rightMotors.move(speed);
201 } else {
202 leftMotors.move(speed);
203 rightMotors.move(-speed);
204 }
205 flip = !flip;
206 pros::delay(100);
207 }
208
209 leftMotors.brake();
210 rightMotors.brake();
211 pros::delay(50);
212 chassis.turnToHeading(targetHeading, 800);
213}

References chassis, leftMotors, and rightMotors.

◆ outtake()

void outtake ( int power = 12000)

Definition at line 19 of file autonFunctions.cpp.

20{
21 if(intakeFunnel.is_extended())
22 {
23 intakeFunnel.retract();
24 pros::delay(100);
25 intakeMotor.move_voltage(12000);
26 pros::delay(300);
27 }
28 topMotor.move_voltage(-12000);
29 if(low_ramp_down_time >= 1000)
30 intakeMotor.move_voltage( -12000);
31 else
32 intakeMotor.move_voltage(-power);
33}
int low_ramp_down_time
Definition globals.cpp:100

References intakeFunnel(), intakeMotor(), low_ramp_down_time, and topMotor().

Referenced by opcontrol(), and right_auton().

◆ relativeMotion()

void relativeMotion ( float expected_x,
float expected_y,
float expected_theta,
float distance,
int timeout_ms,
bool forw = true,
float earlyExit = 0 )

Definition at line 217 of file autonFunctions.cpp.

218{
219 lemlib::Pose targetPose(
220 expected_x + distance * std::sin(lemlib::degToRad(expected_theta)),
221 expected_y + distance * std::cos(lemlib::degToRad(expected_theta)),
222 expected_theta
223 );
224
225 chassis.moveToPoint(targetPose.x, targetPose.y, timeout_ms, {.forwards = forw, .earlyExitRange = earlyExit});
226}

References chassis.

Referenced by skills_auton().

◆ resting_state()

void resting_state ( bool trapDoor_commanded = false)

Definition at line 173 of file autonFunctions.cpp.

174{
175 intake_stop();
176 if(!trapDoor_commanded)
177 trapDoor.retract();
178 topMotor.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
179}
pros::adi::Pneumatics trapDoor('A', false)

References intake_stop(), topMotor(), and trapDoor().

Referenced by opcontrol().

◆ score_bottomgoal()

void score_bottomgoal ( int power = 12000)

Definition at line 35 of file autonFunctions.cpp.

36{
37 intakeMotor.move_voltage(-power);
38}

References intakeMotor().

◆ score_longgoal()

void score_longgoal ( int power = 12000,
Color allianceColor = Color::RED )

Definition at line 40 of file autonFunctions.cpp.

41{
42 intake(power);
43 if(get_color() != allianceColor && get_color() != Color::NONE && color_sort_enable)
44 {
45 topMotor.move_voltage(-8000);
46 std::cout << "Color Rejected" << std::endl;
47 }
48 else
49 {
50 topMotor.move_voltage(power);
51 std::cout << "Color Accepted" << std::endl;
52 }
53
54}
Color get_color()
Definition colorSort.cpp:5
bool color_sort_enable
Definition globals.cpp:97
Color allianceColor
Definition globals.cpp:96

References allianceColor, color_sort_enable, get_color(), intake(), and topMotor().

Referenced by opcontrol().

◆ score_longgoal_auton()

void score_longgoal_auton ( int power = 12000,
Color allianceColor = Color::RED,
int time = -1 )

Definition at line 133 of file autonFunctions.cpp.

134{
135 leftMotors.move(-50);
136 rightMotors.move(-50);
137 u_int32_t startTime = pros::millis();
139 {
140 blockBlocker.extend();
141 scoringBand.extend();
142 }
143 if(time != -1)
144 {
145 while(pros::millis() - startTime < time)
146 {
147 if(get_color() != allianceColor && get_color() != Color::NONE && color_sort_enable)
148 {
149 topMotor.move_voltage(-10000);
150 intakeMotor.move_voltage(12000);
151 }
152 else
153 {
154 topMotor.move_voltage(power);
155 intakeMotor.move_voltage(power);
156 }
157 }
158 }
159 intake_stop();
160 chassis.tank(0,0);
161 if(blockBlocker.is_extended()) blockBlocker.retract();
162 if(scoringBand.is_extended()) scoringBand.retract();
163}
pros::adi::Pneumatics blockBlocker('G', false)
pros::adi::Pneumatics scoringBand('C', false)

References allianceColor, blockBlocker(), chassis, color_sort_enable, get_color(), intake_stop(), intakeMotor(), leftMotors, rightMotors, scoringBand(), and topMotor().

Referenced by awp_auton(), elim_auton(), left_auton(), right_auton(), and skills_auton().

◆ score_midgoal()

void score_midgoal ( int power = 12000)

Definition at line 62 of file autonFunctions.cpp.

63{
65 {
67 {
68 midgoal_first = false;
69 trapDoor.extend();
70 intakeMotor.move_voltage(12000);
71 topMotor.move_voltage(6000);
72 }
74 {
75 midgoal_first = false;
76 trapDoor.extend();
77 intakeMotor.move_voltage(12000);
78 topMotor.move_voltage(6000);
79 }
80 }
81 if(get_color() != allianceColor && get_color() != Color::NONE && color_sort_enable)
82 {
83 topMotor.move_voltage(-8000);
84 }
85 else {
86 if (ramp_up_time >= 1200)
87 {
88 topMotor.move_voltage(8000);
89 intakeMotor.move_voltage(12000);
90 }
91 if (ramp_up_time >= 800)
92 {
93 topMotor.move_voltage(5000); // Prev: 4000
94 intakeMotor.move_voltage(12000);
95 }
96 else if(ramp_up_time >= 400)
97 {
98 topMotor.move_voltage(6000);
99 intakeMotor.move_voltage(12000);
100 }
101 else {
102 topMotor.move_voltage(10000);
103 intakeMotor.move_voltage(12000);
104 }
105 }
106 //if (ramp_up_time >= 1600)
107 //{
108 // topMotor.move_voltage(4000);
109 //}
110 //topMotor.move_voltage(10000);
111
112}
int ramp_up_time
Definition globals.cpp:99
bool midgoal_first
Definition globals.cpp:98

References allianceColor, color_sort_enable, get_color(), intakeMotor(), midgoal_first, ramp_up_time, topMotor(), and trapDoor().

Referenced by opcontrol().

◆ score_midgoal_auton()

void score_midgoal_auton ( int power = 12000,
Color allianceColor = Color::RED,
int time = -1 )

Definition at line 114 of file autonFunctions.cpp.

115{
116 intake(12000);
117 chassis.tank(-35, -35);
118 topMotor.move_velocity(330);
119 pros::delay(250);
120 topMotor.move_velocity(300);
121 pros::delay(400);
122 topMotor.move_velocity(300);
123 pros::delay(400);
124 topMotor.move_velocity(270);
125 pros::delay(550);
126 topMotor.move_velocity(270);
127 pros::delay(400);
128 topMotor.move_velocity(240);
129 pros::delay(1400);
130
131}

References allianceColor, chassis, intake(), and topMotor().

Referenced by skills_auton().