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 "MCL.h"
#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_longgoal_auton (int power=12000, Color allianceColor=Color::RED)
 
void intake_to_basket ()
 
void resting_state (bool trapDoor_commanded=false)
 
void matchload_state (bool state)
 
void longgoal_prep ()
 
void reset_odometry ()
 
void matchload_wiggle (int time=1000, int speed=100)
 
void MCL_reset (bool x=true, bool y=true)
 
void fusion_loop_fn (void *ignore)
 
void enable_fused_odometry (bool enable)
 
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)
 

Variables

pros::Task * fusionTask = nullptr
 

Function Documentation

◆ enable_fused_odometry()

void enable_fused_odometry ( bool enable)

Definition at line 170 of file autonFunctions.cpp.

170 {
171 if (enable) {
172 if (fusionTask == nullptr) {
173 fusionTask = new pros::Task(fusion_loop_fn, NULL, "MCL_Fusion");
174 }
175 } else {
176 if (fusionTask != nullptr) {
177 fusionTask->remove();
178 delete fusionTask;
179 fusionTask = nullptr;
180 }
181 }
182}
pros::Task * fusionTask
void fusion_loop_fn(void *ignore)

References fusion_loop_fn(), and fusionTask.

◆ fusion_loop_fn()

void fusion_loop_fn ( void * ignore)

Definition at line 148 of file autonFunctions.cpp.

148 {
149 const uint32_t LOOP_DELAY_MS = 10;
150 uint32_t start_time = pros::millis();
151
152 const float MCL_GAIN = 0.05f;
153
154 while (true) {
155 lemlib::Pose odomPose = chassis.getPose(true);
156
157 MCL::particle_mutex.take();
158 float target_x = MCL::X;
159 float target_y = MCL::Y;
160 MCL::particle_mutex.give();
161
162 float new_x = odomPose.x + (target_x - odomPose.x) * MCL_GAIN;
163 float new_y = odomPose.y + (target_y - odomPose.y) * MCL_GAIN;
164 chassis.setPose(new_x, new_y, odomPose.theta);
165
166 pros::Task::delay_until(&start_time, LOOP_DELAY_MS);
167 }
168}
lemlib::Chassis chassis
double Y
Definition MCL.cpp:10
const double LOOP_DELAY_MS
Definition MCL.cpp:37
double X
Definition MCL.cpp:10
pros::Mutex particle_mutex
Definition MCL.cpp:31

References chassis, MCL::particle_mutex, MCL::X, and MCL::Y.

Referenced by enable_fused_odometry().

◆ intake()

void intake ( int power = 12000)

Definition at line 12 of file autonFunctions.cpp.

13{
14 intakeMotor.move_voltage(power);
15 topMotor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
16 topMotor.brake();
17}
pros::Motor topMotor(7, pros::v5::MotorGears::blue)
pros::Motor intakeMotor(18, pros::v5::MotorGears::blue)

References intakeMotor(), and topMotor().

Referenced by awp_auton(), carry_auton(), intake_to_basket(), left_auton(), opcontrol(), right_auton(), score_longgoal(), and score_midgoal().

◆ intake_stop()

void intake_stop ( )

Definition at line 46 of file autonFunctions.cpp.

47{
48 intakeMotor.move_voltage(0);
49 topMotor.move_voltage(0);
50}

References intakeMotor(), and topMotor().

Referenced by awp_auton(), carry_auton(), left_auton(), matchload_counter(), resting_state(), and right_auton().

◆ intake_to_basket()

void intake_to_basket ( )

Definition at line 80 of file autonFunctions.cpp.

81{
82 intake();
83 topMotor.move_voltage(-6000);
84}
void intake(int power=12000)

References intake(), and topMotor().

Referenced by opcontrol().

◆ longgoal_prep()

void longgoal_prep ( )

Definition at line 112 of file autonFunctions.cpp.

113{
114
115}

◆ matchload_counter()

void matchload_counter ( int balls,
int time_ms )

Definition at line 195 of file autonFunctions.cpp.

196{
197 pros::Task counter_task([=]() {
198 int count = 0;
199 uint32_t start_time = pros::millis();
200 while(pros::millis() - start_time < time_ms && count < balls)
201 {
202 start_time = pros::millis();
203 if(frontDistance.get_object_size() <= 70)
204 {
205 count++;
206 }
207 pros::Task::delay_until(&start_time, 10);
208 }
209 intake_stop();
210 pros::Task::current().remove();
211 });
212}
void intake_stop()
pros::Distance frontDistance(13)

References frontDistance(), and intake_stop().

◆ matchload_state()

void matchload_state ( bool state)

Definition at line 97 of file autonFunctions.cpp.

98{
99 if(state && !matchload.is_extended())
100 {
101 matchload.extend();
102 }
103 else if(matchload.is_extended())
104 {
105 matchload.retract();
106 }
107 else {
108 std::cout << "Matchload state unchanged\n" << std::endl;
109 }
110}
pros::adi::Pneumatics matchload('B', false)

References matchload().

Referenced by awp_auton(), carry_auton(), left_auton(), and right_auton().

◆ matchload_wiggle()

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

Definition at line 122 of file autonFunctions.cpp.

123{
124 u_int32_t start_time = pros::millis();
125 int sign = 1;
126 while(pros::millis() - start_time < time)
127 {
128 leftMotors.move_voltage(3000 * sign);
129 rightMotors.move_voltage(3000 * sign);
130 sign *= -1;
131 pros::delay(speed);
132 }
133 leftMotors.brake();
134 rightMotors.brake();
135}
pros::MotorGroup rightMotors
pros::MotorGroup leftMotors
Definition globals.cpp:20

References leftMotors, and rightMotors.

◆ MCL_reset()

void MCL_reset ( bool x = true,
bool y = true )

Definition at line 137 of file autonFunctions.cpp.

138{
139 MCL::particle_mutex.take();
140 float X = x ? MCL::X : chassis.getPose().x;
141 float Y = y ? MCL::Y : chassis.getPose().y;
142 MCL::particle_mutex.give();
143 chassis.setPose(X, Y, chassis.getPose().theta);
144}

References chassis, MCL::particle_mutex, MCL::X, and MCL::Y.

◆ outtake()

void outtake ( int power = 12000)

Definition at line 19 of file autonFunctions.cpp.

20{
21 intakeMotor.move_voltage(-power);
22}

References intakeMotor().

Referenced by opcontrol(), and score_midgoal().

◆ 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 184 of file autonFunctions.cpp.

185{
186 lemlib::Pose targetPose(
187 expected_x + distance * std::sin(lemlib::degToRad(expected_theta)),
188 expected_y + distance * std::cos(lemlib::degToRad(expected_theta)),
189 expected_theta
190 );
191
192 chassis.moveToPoint(targetPose.x, targetPose.y, timeout_ms, {.forwards = forw, .earlyExitRange = earlyExit});
193}

References chassis.

Referenced by right_auton().

◆ reset_odometry()

void reset_odometry ( )

Definition at line 117 of file autonFunctions.cpp.

118{
119
120}

◆ resting_state()

void resting_state ( bool trapDoor_commanded = false)

Definition at line 88 of file autonFunctions.cpp.

89{
91 if(!trapDoor_commanded)
92 trapDoor.retract();
93 topMotor.set_brake_mode(pros::E_MOTOR_BRAKE_COAST);
94 descore.extend();
95}
pros::adi::Pneumatics trapDoor('A', false)
pros::adi::Pneumatics descore('D', false)

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

Referenced by awp_auton(), left_auton(), opcontrol(), and right_auton().

◆ score_bottomgoal()

void score_bottomgoal ( int power = 12000)

Definition at line 24 of file autonFunctions.cpp.

25{
26 intakeMotor.move_voltage(-power);
27}

References intakeMotor().

◆ score_longgoal()

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

Definition at line 29 of file autonFunctions.cpp.

30{
31 intake(power);
32 if(get_color() != allianceColor && get_color() != Color::NONE && color_sort_enable)
33 {
34 topMotor.move_voltage(-12000);
35 std::cout << "Color Rejected" << std::endl;
36 }
37 else
38 {
39 topMotor.move_voltage(power);
40 std::cout << "Color Accepted" << std::endl;
41 }
42 pros::delay(33);
43
44}
Color get_color()
Definition colorSort.cpp:5
bool color_sort_enable
Definition globals.cpp:94
Color allianceColor
Definition globals.cpp:93

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

Referenced by opcontrol(), and score_longgoal_auton().

◆ score_longgoal_auton()

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

Definition at line 73 of file autonFunctions.cpp.

74{
75 leftMotors.move(-20);
76 rightMotors.move(-20);
78}
void score_longgoal(int power=12000, Color allianceColor=Color::RED)

References allianceColor, leftMotors, rightMotors, and score_longgoal().

Referenced by awp_auton(), carry_auton(), left_auton(), and right_auton().

◆ score_midgoal()

void score_midgoal ( int power = 12000)

Definition at line 52 of file autonFunctions.cpp.

53{
54 if(get_color() != allianceColor && get_color() != Color::NONE && color_sort_enable)
55 {
56 topMotor.move_voltage(-8000);
57 }
58 else {
59 topMotor.move_voltage(12000);
60 }
62 {
63 outtake(8000);
64 topMotor.move_voltage(-12000);
65 pros::delay(300);
66 midgoal_first = false;
67 }
68 intake(power);
69 topMotor.move_voltage(power);
70 if(!trapDoor.is_extended()) trapDoor.extend();
71}
void outtake(int power=12000)
bool midgoal_first
Definition globals.cpp:95

References allianceColor, color_sort_enable, get_color(), intake(), midgoal_first, outtake(), topMotor(), and trapDoor().

Referenced by awp_auton(), and opcontrol().

Variable Documentation

◆ fusionTask

pros::Task* fusionTask = nullptr

Definition at line 146 of file autonFunctions.cpp.

Referenced by enable_fused_odometry().