1516X Push Back
1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Toggle main menu visibility
Loading...
Searching...
No Matches
crossBarrierDetection.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 "globals.h"
5
#include <sys/types.h>
6
#include <cmath>
7
8
double
PITCH_CLIMB_THRESHOLD
= 8;
9
double
PITCH_LEVEL_THRESHOLD
= 1;
10
const
double
CROSSING_TIMEOUT
= 1200;
11
const
double
DRIVE_SPEED
= 127;
12
const
double
HEADING_KP
= 6.0;
13
const
int
POST_LANDING_TIME
= 200;
14
15
void
crossBarrier
(
int
times = 2,
bool
reverse =
false
,
bool
fullyDrop =
true
) {
16
double
targetHeading =
imu
.get_heading();
17
int
dir = reverse ? -1 : 1;
18
if
(reverse)
19
{
20
PITCH_CLIMB_THRESHOLD
= 8.5;
21
PITCH_LEVEL_THRESHOLD
= 0.5;
22
}
23
24
for
(
int
i = 0; i < times; i++) {
25
bool
hasClimbed =
false
;
26
bool
hasDropped =
false
;
27
28
uint32_t startTime = pros::millis();
29
uint32_t previousTime = pros::millis();
30
31
while
(
true
) {
32
33
if
(pros::millis() - startTime >
CROSSING_TIMEOUT
) {
34
chassis
.tank(0,0);
35
leftMotors
.brake();
36
rightMotors
.brake();
37
return
;
38
}
39
40
double
currentPitch =
imu
.get_roll() * dir;
41
double
currentHeading =
imu
.get_heading();
42
43
double
error = targetHeading - currentHeading;
44
while
(error > 180) error -= 360;
45
while
(error < -180) error += 360;
46
47
double
turnOffset = error *
HEADING_KP
;
48
49
chassis
.tank((
DRIVE_SPEED
* dir) + turnOffset,
50
(
DRIVE_SPEED
* dir) - turnOffset);
51
52
// Detect climb
53
if
(!hasClimbed && currentPitch >
PITCH_CLIMB_THRESHOLD
) {
54
hasClimbed =
true
;
55
}
56
57
// Detect crest
58
if
(hasClimbed && !hasDropped && currentPitch <
PITCH_LEVEL_THRESHOLD
) {
59
hasDropped =
true
;
60
}
61
62
// --- LANDING LOGIC ---
63
if
(hasClimbed && hasDropped) {
64
if
(i == 1 && times > 1)
65
matchloader
.retract();
66
67
// FULLY DROP MODE
68
if
(fullyDrop && std::abs(currentPitch) <
PITCH_LEVEL_THRESHOLD
) {
69
70
uint32_t clearStartTime = pros::millis();
71
while
(pros::millis() - clearStartTime <
POST_LANDING_TIME
) {
72
73
currentHeading =
imu
.get_heading();
74
error = targetHeading - currentHeading;
75
while
(error > 180) error -= 360;
76
while
(error < -180) error += 360;
77
78
turnOffset = error *
HEADING_KP
;
79
80
chassis
.tank((
DRIVE_SPEED
* dir) + turnOffset,
81
(
DRIVE_SPEED
* dir) - turnOffset);
82
83
pros::delay(10);
84
}
85
86
chassis
.tank(0, 0);
87
leftMotors
.brake();
88
rightMotors
.brake();
89
break
;
90
}
91
92
// ANGLED PARK MODE
93
if
(!fullyDrop && currentPitch < -
PITCH_LEVEL_THRESHOLD
) {
94
95
chassis
.tank(0, 0);
96
97
// use hold instead of brake to prevent rocking forward
98
leftMotors
.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
99
rightMotors
.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);
100
101
break
;
102
}
103
}
104
105
pros::Task::delay_until(&previousTime, 10);
106
}
107
108
if
(i < times - 1)
109
pros::delay(200);
110
}
111
}
PITCH_LEVEL_THRESHOLD
double PITCH_LEVEL_THRESHOLD
Definition
crossBarrierDetection.cpp:9
CROSSING_TIMEOUT
const double CROSSING_TIMEOUT
Definition
crossBarrierDetection.cpp:10
DRIVE_SPEED
const double DRIVE_SPEED
Definition
crossBarrierDetection.cpp:11
crossBarrier
void crossBarrier(int times=2, bool reverse=false, bool fullyDrop=true)
Definition
crossBarrierDetection.cpp:15
HEADING_KP
const double HEADING_KP
Definition
crossBarrierDetection.cpp:12
POST_LANDING_TIME
const int POST_LANDING_TIME
Definition
crossBarrierDetection.cpp:13
PITCH_CLIMB_THRESHOLD
double PITCH_CLIMB_THRESHOLD
Definition
crossBarrierDetection.cpp:8
chassis
Chassis chassis(drivebase, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
matchloader
pros::adi::Pneumatics matchloader('C', false)
imu
pros::Imu imu(16)
leftMotors
lemlib::Drivetrain drivebase & leftMotors
Definition
globals.cpp:21
rightMotors
pros::MotorGroup rightMotors({17, 19, -18}, pros::MotorGears::blue)
src
auton
crossBarrierDetection.cpp
Generated on
for 1516X Push Back by
1.17.0