1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
crossBarrierDetection.cpp
Go to the documentation of this file.
1#include "globals.h"
2#include <sys/types.h>
3
4
5const double PITCH_CLIMB_THRESHOLD = 15.0; // Degrees robot tilts up when climbing
6const double PITCH_LEVEL_THRESHOLD = 5.0; // Degrees considered "flat"
7const double CROSSING_TIMEOUT = 3000; // MS to abort if stuck (Safety)
8const double DRIVE_SPEED = 90; // Motor voltage (0-127) for power
9const double HEADING_KP = 2.0; // Strength of heading correction
10
12 double targetHeading = imu.get_heading();
13
14 bool hasClimbed = false;
15 bool hasDropped = false;
16
17 uint32_t startTime = pros::millis();
18 while (true) {
19 u_int32_t currentTime = pros::millis();
20 if (pros::millis() - startTime > CROSSING_TIMEOUT) {
21 chassis.tank(-127, -127);
22 pros::delay(300);
23 chassis.tank(0, 0);
24 break;
25 }
26
27 double currentPitch = imu.get_pitch();
28 double currentHeading = imu.get_heading();
29 double error = targetHeading - currentHeading;
30
31 while (error > 180) error -= 360;
32 while (error < -180) error += 360;
33
34 double turnOffset = error * HEADING_KP;
35
36 chassis.tank(DRIVE_SPEED + turnOffset, DRIVE_SPEED - turnOffset);
37 if (!hasClimbed && currentPitch > PITCH_CLIMB_THRESHOLD) {
38 hasClimbed = true;
39 std::cout << "Status: CLIMBING" << std::endl;
40 }
41
42 if (hasClimbed && !hasDropped && currentPitch < PITCH_LEVEL_THRESHOLD) {
43 hasDropped = true;
44 std::cout << "Status: DROPPING" << std::endl;
45 }
46
47 if (hasClimbed && hasDropped && std::abs(currentPitch) < PITCH_LEVEL_THRESHOLD) {
48 std::cout << "Status: LANDED" << std::endl;
49
50 pros::delay(200);
51 chassis.tank(0, 0);
52 break;
53 }
54 pros::Task::delay_until(&currentTime, 10);
55 }
56}
void crossBarrier()
const double CROSSING_TIMEOUT
const double DRIVE_SPEED
const double PITCH_CLIMB_THRESHOLD
const double PITCH_LEVEL_THRESHOLD
const double HEADING_KP
pros::IMU imu
lemlib::Chassis chassis