1516X Push Back
1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Toggle main menu visibility
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
16
const
VelocityControllerConfig
config
{
17
5.09498070723,
18
0.23396112183,
19
1.22496514644,
20
0.964796393603,
21
0.522291806997,
22
10.933332351,
23
44.6788428062,
24
};
25
26
void
antiJamTask
() {
27
while
(
true
) {
28
jamManager
.update();
29
pros::delay(10);
30
}
31
}
32
33
void
intake
(
int
power)
34
{
35
if
(
hood
.is_extended()) {
hood
.retract(); }
36
jamManager
.set_velocities((
int
)power/3, -(
int
)power/3, power);
37
}
38
39
void
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
45
void
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
51
void
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
60
void
score_midgoal
(
int
power)
61
{
62
jamManager
.set_velocities((
int
)power/3, (
int
)power/3, power);
63
}
64
65
void
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();
76
intake_stop
();
77
}
78
79
void
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
{
90
intake_stop
();
91
jamManager
.set_velocities(-200, 600, -200);
92
pros::delay(100);
93
intake_stop
();
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
}
105
void
intake_to_basket
()
106
{
107
108
}
109
110
void
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
123
void
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
134
double
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
}
relativeMotion
void relativeMotion(float expected_x, float expected_y, float expected_theta, float distance, int timeout_ms, bool forw, float earlyExit)
Definition
autonFunctions.cpp:123
score_midgoal_auton
void score_midgoal_auton(int power, Color allianceColor, int time)
Definition
autonFunctions.cpp:65
config
const VelocityControllerConfig config
Definition
autonFunctions.cpp:16
score_longgoal
void score_longgoal(int power, Color allianceColor)
Definition
autonFunctions.cpp:45
intake_to_basket
void intake_to_basket()
Definition
autonFunctions.cpp:105
antiJamTask
void antiJamTask()
Definition
autonFunctions.cpp:26
intake
void intake(int power)
Definition
autonFunctions.cpp:33
calculateAngle
double calculateAngle(double robotHeading)
Definition
autonFunctions.cpp:134
matchload_state
void matchload_state(bool state)
Definition
autonFunctions.cpp:110
score_midgoal
void score_midgoal(int power)
Definition
autonFunctions.cpp:60
intake_stop
void intake_stop(bool hood_state)
Definition
autonFunctions.cpp:51
score_longgoal_auton
void score_longgoal_auton(int power, Color allianceColor, int time)
Definition
autonFunctions.cpp:79
outtake
void outtake(int power)
Definition
autonFunctions.cpp:39
get_color
Color get_color()
Definition
colorSort.cpp:8
chassis
Chassis chassis(drivebase, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
matchloader
pros::adi::Pneumatics matchloader('C', false)
jamManager
IntakeAntiJam jamManager(intakeMotor, outtakeMotor, storageMotor, 55)
intake_lift
pros::adi::Pneumatics intake_lift('A', false)
hood
pros::adi::Pneumatics hood('B', false)
color_sort_enable
bool color_sort_enable
Definition
globals.cpp:104
allianceColor
Color allianceColor
Definition
globals.cpp:103
frontDistance
pros::Distance frontDistance(8)
src
auton
autonFunctions.cpp
Generated on
for 1516X Push Back by
1.17.0