1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
autonFunctions.cpp
Go to the documentation of this file.
1// Copyright 2026 California High Robotics, Team 1516X
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "autonFunctions.h"
5#include "globals.h"
6#include "lemlib/util.hpp"
7#include "pros/misc.h"
8#include "pros/rtos.hpp"
9#include <cmath>
10#include <sys/types.h>
11#include "colorSort.h"
12#include "IntakeAntiJam.h"
13#include "ltv.h"
14
15
16const VelocityControllerConfig config{
175.09498070723,
180.23396112183,
191.22496514644,
200.964796393603,
210.522291806997,
2210.933332351,
2344.6788428062,
24};
25
27 while (true) {
28 jamManager.update();
29 pros::delay(10);
30 }
31}
32
33void intake(int power)
34{
35 if(hood.is_extended()) { hood.retract(); }
36 jamManager.set_velocities((int)power/3, -(int)power/3, power);
37}
38
39void outtake(int power)
40{
41 if(!intake_lift.is_extended()) { intake_lift.extend(); }
42 jamManager.set_velocities(-((int)power/3), ((int)power/3), -power);
43}
44
45void score_longgoal(int power, Color allianceColor)
46{
47 if(!hood.is_extended()) { hood.extend(); }
48 jamManager.set_velocities((int)power/3, -(int)power/3, power);
49}
50
51void intake_stop(bool hood_state)
52{
53 jamManager.stop();
54 if(!hood_state) hood.retract();
55 else hood.extend();
56
57 if(intake_lift.is_extended()) { intake_lift.retract(); }
58}
59
60void score_midgoal(int power)
61{
62 jamManager.set_velocities((int)power/3, (int)power/3, power);
63}
64
65void score_midgoal_auton(int power, Color allianceColor, int time)
66{
67 u_int32_t start_time = pros::millis();
68 if(time != -1) {
69 while(pros::millis() - start_time < (u_int32_t)time) {
70 jamManager.set_velocities((int)power/3, (int)power/3, power);
71 chassis.tank(-20, -20);
72 pros::delay(10);
73 }
74 }
75 chassis.brake();
77}
78
79void score_longgoal_auton(int power, Color allianceColor, int time)
80{
81 u_int32_t start_time = pros::millis();
82 if(!hood.is_extended()) {hood.extend();}
83 if(time != -1) {
84 while(pros::millis() - start_time < (u_int32_t)time) {
85 if(allianceColor != Color::NONE)
86 {
87 Color detected = get_color();
88 if(detected != Color::NONE && detected != allianceColor && color_sort_enable)
89 {
91 jamManager.set_velocities(-200, 600, -200);
92 pros::delay(100);
94 break;
95 }
96 }
97 jamManager.set_velocities((int)power/3, -(int)power/3, power);
98 chassis.tank(-20, -20);
99 pros::delay(10);
100 }
101 }
102 chassis.brake();
103 intake_stop();
104}
106{
107
108}
109
110void matchload_state(bool state)
111{
112 if(state)
113 {
114 if(!matchloader.is_extended()) {matchloader.extend();}
115 }
116 else
117 {
118 if(matchloader.is_extended()) {matchloader.retract();}
119 }
120}
121
122
123void relativeMotion(float expected_x, float expected_y, float expected_theta, float distance, int timeout_ms, bool forw, float earlyExit)
124{
125 lemlib::Pose targetPose(
126 expected_x + distance * std::sin(lemlib::degToRad(expected_theta)),
127 expected_y + distance * std::cos(lemlib::degToRad(expected_theta)),
128 expected_theta
129 );
130
131 chassis.moveToPoint(targetPose.x, targetPose.y, timeout_ms, {.forwards = forw, .earlyExitRange = earlyExit});
132}
133
134double calculateAngle(double robotHeading) {
135 double d1 = frontDistance.get();
136 double d2 = frontDistance2.get() + 10;
137
138 if (d1 > 1800 || d2 > 1800) return -1;
139 double wallAngleDeg = atan2((d1 - d2) * 0.0393701, 10.75) * 180.0 / M_PI;
140
141 if ((robotHeading >= 315 && robotHeading < 360) || (robotHeading >= 0 && robotHeading < 45)) {
142 return wallAngleDeg;
143 }
144 else if (robotHeading >= 45 && robotHeading < 135) {
145 return 90 + wallAngleDeg;
146 }
147 else if (robotHeading >= 135 && robotHeading < 225) {
148 return 180 + wallAngleDeg;
149 }
150 else if (robotHeading >= 225 && robotHeading < 315) {
151 return 270 + wallAngleDeg;
152 }
153
154 return -1;
155}
void relativeMotion(float expected_x, float expected_y, float expected_theta, float distance, int timeout_ms, bool forw, float earlyExit)
void score_midgoal_auton(int power, Color allianceColor, int time)
const VelocityControllerConfig config
void score_longgoal(int power, Color allianceColor)
void intake_to_basket()
void antiJamTask()
void intake(int power)
double calculateAngle(double robotHeading)
void matchload_state(bool state)
void score_midgoal(int power)
void intake_stop(bool hood_state)
void score_longgoal_auton(int power, Color allianceColor, int time)
void outtake(int power)
Color get_color()
Definition colorSort.cpp:8
Chassis chassis(drivebase, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::adi::Pneumatics matchloader('C', false)
IntakeAntiJam jamManager(intakeMotor, outtakeMotor, storageMotor, 55)
pros::adi::Pneumatics intake_lift('A', false)
pros::adi::Pneumatics hood('B', false)
bool color_sort_enable
Definition globals.cpp:104
Color allianceColor
Definition globals.cpp:103
pros::Distance frontDistance(8)