1516X Push Back 1.0
1516X's robot code for the 2025-2026 VEX Robotics Competition
Loading...
Searching...
No Matches
crossBarrierDetection.cpp File Reference
#include "globals.h"
#include <sys/types.h>

Go to the source code of this file.

Functions

void crossBarrier ()
 

Variables

const double PITCH_CLIMB_THRESHOLD = 15.0
 
const double PITCH_LEVEL_THRESHOLD = 5.0
 
const double CROSSING_TIMEOUT = 3000
 
const double DRIVE_SPEED = 90
 
const double HEADING_KP = 2.0
 

Function Documentation

◆ crossBarrier()

void crossBarrier ( )

Definition at line 11 of file crossBarrierDetection.cpp.

11 {
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}
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

References chassis, CROSSING_TIMEOUT, DRIVE_SPEED, HEADING_KP, imu, PITCH_CLIMB_THRESHOLD, and PITCH_LEVEL_THRESHOLD.

Variable Documentation

◆ CROSSING_TIMEOUT

const double CROSSING_TIMEOUT = 3000

Definition at line 7 of file crossBarrierDetection.cpp.

Referenced by crossBarrier().

◆ DRIVE_SPEED

const double DRIVE_SPEED = 90

Definition at line 8 of file crossBarrierDetection.cpp.

Referenced by crossBarrier().

◆ HEADING_KP

const double HEADING_KP = 2.0

Definition at line 9 of file crossBarrierDetection.cpp.

Referenced by crossBarrier().

◆ PITCH_CLIMB_THRESHOLD

const double PITCH_CLIMB_THRESHOLD = 15.0

Definition at line 5 of file crossBarrierDetection.cpp.

Referenced by crossBarrier().

◆ PITCH_LEVEL_THRESHOLD

const double PITCH_LEVEL_THRESHOLD = 5.0

Definition at line 6 of file crossBarrierDetection.cpp.

Referenced by crossBarrier().