LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
drive_utils.hpp File Reference

Header-only drive helpers built on top of light::Drive: More...

#include <algorithm>
#include <cmath>
#include "LightLib/drive/drive.hpp"
#include "LightLib/path/field_map.hpp"
#include "LightLib/drive/odometry.hpp"
#include "LightLib/util/util.hpp"
#include "okapi/api/units/QLength.hpp"
#include "pros/distance.hpp"
#include "subsystems.hpp"

Go to the source code of this file.

Functions

void drive_until_distance (okapi::QLength target, pros::Distance &sensor, int speed=127, int timeout_ms=10000)
 Drive forward (or reverse) until a distance sensor reads at or below target.
 
void distance_reset (light::Drive &chassis, pros::Distance &sensor, double offset_fwd, double offset_side, bool fix_x, bool faces_positive=false, double field_size_in=light::field::FIELD_SIZE_IN)
 Re-zero one odom axis (x or y) using a wall-facing distance sensor.
 
void drive_distance_reset (light::Drive &chassis, double known_coord, bool fix_x)
 Re-zero one odom axis from a known field coordinate (e.g.
 
void angle_reset (light::Drive &chassis, pros::Distance &front_sensor, pros::Distance &rear_sensor, double separation)
 Correct heading from front- and rear-mounted distance sensors looking at the same parallel wall.
 

Detailed Description

Header-only drive helpers built on top of light::Drive:

Definition in file drive_utils.hpp.

Function Documentation

◆ angle_reset()

void angle_reset ( light::Drive chassis,
pros::Distance &  front_sensor,
pros::Distance &  rear_sensor,
double  separation 
)
inline

Correct heading from front- and rear-mounted distance sensors looking at the same parallel wall.

The angular offset is atan2(rear − front, separation) and is applied to the IMU's stored offset.

Parameters
chassisthe drivetrain (IMU is reset on it)
front_sensorforward-mounted distance sensor
rear_sensorrear-mounted distance sensor on the same side
separationdistance between the two sensors along the robot, inches

Definition at line 154 of file drive_utils.hpp.

◆ distance_reset()

void distance_reset ( light::Drive chassis,
pros::Distance &  sensor,
double  offset_fwd,
double  offset_side,
bool  fix_x,
bool  faces_positive = false,
double  field_size_in = light::field::FIELD_SIZE_IN 
)
inline

Re-zero one odom axis (x or y) using a wall-facing distance sensor.

Reads the sensor, projects its measurement through the current heading to the axis of interest, and updates the odom pose with light::setPose. Bails silently if the sensor returns PROS_ERR.

Parameters
chassisthe drivetrain (used for IMU heading)
sensorwall-facing distance sensor
offset_fwdsensor offset in inches along the robot's forward axis
offset_sidesensor offset in inches along the robot's lateral axis
fix_xtrue = correct X, false = correct Y
faces_positivetrue if the sensor faces the positive end of the field axis
field_size_infield size used to flip the coordinate when faces_positive

Definition at line 86 of file drive_utils.hpp.

◆ drive_distance_reset()

void drive_distance_reset ( light::Drive chassis,
double  known_coord,
bool  fix_x 
)
inline

Re-zero one odom axis from a known field coordinate (e.g.

when robot is pinned against a wall whose coordinate is known a priori).

Parameters
chassisthe drivetrain (used for IMU heading)
known_coordthe known field-frame coordinate, inches
fix_xtrue = set X, false = set Y

Definition at line 126 of file drive_utils.hpp.

◆ drive_until_distance()

void drive_until_distance ( okapi::QLength  target,
pros::Distance &  sensor,
int  speed = 127,
int  timeout_ms = 10000 
)
inline

Drive forward (or reverse) until a distance sensor reads at or below target.

The PID is given an arbitrarily large 5000 in target — the sensor triggers the real stop. Falls back to pid_wait_quick_chain() on timeout.

Parameters
targetdistance threshold (with units)
sensordistance sensor used for the stop trigger
speedsigned drive speed, ±127. Negative = reverse.
timeout_msbail after this many ms if the threshold is never crossed

Definition at line 41 of file drive_utils.hpp.