HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
Chassis Class Reference

The main Chassis controller class. More...

#include <chassis.h>

Public Types

enum class  CurveDirection { Auto , CW , CCW }
 Automatic, clockwise, or counter-clockwise rotation preference. More...
 
enum class  AvoidanceMode { Off , On }
 Status of the Obstacle Avoidance subsystem. More...
 
enum class  SwingSide { Right , Left }
 Determines which side to lock during a swing turn. More...
 

Public Member Functions

 Chassis (pros::Motor fl, pros::Motor fr, pros::Motor bl, pros::Motor br, pros::Imu imu_sensor, ChassisConfig config)
 Construct a new Chassis object.
 
void calibrate ()
 Calibrates sensors (e.g.
 
void setXGains (std::vector< ScheduledGain > steps)
 Provide scheduled gains for the X-axis translation controller.
 
void setYGains (std::vector< ScheduledGain > steps)
 Provide scheduled gains for the Y-axis translation controller.
 
void setThetaGains (std::vector< ScheduledGain > steps)
 Provide scheduled gains for the rotational (Theta) controller.
 
void setPose (float x, float y, float theta=0.0f)
 Manually reset the robot's odometry position.
 
void setPose (Pose pose)
 Reset the robot's odometry position to a Pose object.
 
Pose getPose (bool radians=false)
 Get the current odometry pose of the robot.
 
XDriveVoltages calculateHolonomic (float vx, float vy, float vt)
 Calculate the individual motor voltages for a holonomic movement command.
 
void setMotorVoltages (XDriveVoltages v)
 Command the base motors with a set of voltages.
 
void brake ()
 Instructs all motors to brake using their configured brake mode.
 
void driveControl (float forward, float sideways, float rotation, DriveCurves drivecurves, bool fieldCentric, float headingOffset=0.0f, DriveCorrection correction={})
 Main driver control mapping logic.
 
void followPath (const std::vector< PathPoint > &path, float lookahead_inches, MoveParams params=defaultParams, HeadingMode headingMode=HeadingMode::FollowPath, float holdAngleDeg=0.0f, bool reversed=false)
 Autonomously follow a path defined by points.
 
void turnToHeading (float targetDeg, MoveParams params=defaultParams)
 Autonomously turn the robot to face a specific heading.
 
void turnToPoint (float tx, float ty, MoveParams params=defaultParams)
 Autonomously turn the robot to face a specific coordinate.
 
void moveToPoint (float tx, float ty, MoveParams params=defaultParams, bool angleCorrection=true)
 Autonomously drive directly to a coordinate on the field.
 
void moveRelative (float forward, float sideways, MoveParams params=defaultParams, bool holdHeading=true)
 Move a relative distance using X and Y offsets.
 
void moveDistance (float distance, MoveParams params={}, bool holdHeading=true)
 Drive straight for a specified distance.
 
void strafeDistance (float distance, MoveParams params=defaultParams, bool holdHeading=true)
 Strafe for a specified distance.
 
void moveToPose (float tx, float ty, float targetThetaDeg, MoveParams params=defaultParams)
 Move the robot to an exact X, Y, and Theta simultaneously.
 
void curveCircle (float targetThetaDeg, float radius, MoveParams params=defaultParams, CurveDirection direction=CurveDirection::Auto)
 Drive in a circular arc until reaching a specified heading.
 
void waitUntilDone ()
 Blocks the current thread until the current motion is finished.
 
void cancelAllMotions ()
 Halts all running background motions in the motion handler queue.
 
void odometryTask ()
 Infinite loop function typically passed to a background PROS task to update position continuously.
 
float getDistanceTraveled (bool convertToMeters=false)
 Retrieves the total distance traveled during a motion segment.
 
void cancelMotion ()
 Cancels the currently executing autonomous motion.
 
void waitUntil (float distance)
 Wait until a certain linear distance has been covered during a motion command.
 
void setEKFGains (float xProcessNoise, float yProcessNoise, float thetaProcessNoise, float measurementNoise)
 Set specific internal Extended Kalman Filter variables manually.
 
void setVelocityCalculations (bool state)
 Toggles whether to calculate velocities via odometry (computationally heavier).
 
bool detectCollision ()
 Detect sudden impact indicating a potential collision using acceleration delta.
 
void openLoop (float forward, float sideways, float rotation)
 Apply direct open-loop power to the drivetrain without PID.
 
void addObstacle (float x, float y, float radius)
 Add an obstacle to the avoidance system.
 
void removeObstacle (size_t index)
 Remove an obstacle by index.
 
void clearObstacles ()
 Clears all current obstacles from memory.
 
void setAvoidanceMode (AvoidanceMode mode)
 Enables or disables the obstacle avoidance system globally.
 
void setAvoidanceParams (float safetyMargin, float clearance)
 Tunes the obstacle avoidance distance thresholds.
 
void setPotentialFieldParams (float ka, float kr, float influenceRadius)
 Configures Artificial Potential Field parameters.
 
void setRobotDimensionsAvoidance (float width, float height)
 Set robot dimensions used specifically for avoidance calculations.
 
float radToDeg (float rad)
 Utility: Convert Radians to Degrees.
 
float degToRad (float deg)
 Utility: Convert Degrees to Radians.
 
void setEKFstate (bool state)
 Toggle the internal EKF feature entirely.
 
void addTrackingWheel (TrackingWheelConfig config)
 Register a tracking wheel with the odometry module.
 
void clearTrackingWheels ()
 Unregisters all external tracking wheels.
 
template<typename F >
void move (F updateFunction, MoveParams params=defaultParams, bool fieldCentric=true, float headingOffset=0.0f, DriveCorrection correction={})
 Generic templated loop to accept external calculation functions.
 
void setMoveParams (MoveParams params)
 Sets global default move parameters.
 
void swingTurn (float targetThetaDeg, SwingSide lockedSide, MoveParams params=defaultParams)
 Execute a swing turn where one side of the robot is held stationary.
 
void getControllerInput (pros::Controller master)
 Reads inputs from the standard PROS controller into the drive control method.
 
void logReplayData (pros::Controller master, int timeout_ms=50)
 Logs the driver's movements in real time to enable playback features.
 
void disableReplayDataLogging ()
 Stops driver motion logging.
 
void runDriverReplay (std::vector< PathPoint > data, float lookahead)
 Playback previously recorded driver inputs autonomously.
 

Public Attributes

MotionHandler motion
 Background task handler instance.
 

Friends

void odomTaskTrampoline (void *)
 

Detailed Description

The main Chassis controller class.

Integrates odometry, PID tuning via scheduling, autonomous movement APIs, driver control functions, obstacle avoidance, and path following algorithms.

Definition at line 33 of file chassis.h.

Member Enumeration Documentation

◆ CurveDirection

enum class Chassis::CurveDirection
strong

Automatic, clockwise, or counter-clockwise rotation preference.

Enumerator
Auto 
CW 
CCW 

Definition at line 145 of file chassis.h.

◆ AvoidanceMode

enum class Chassis::AvoidanceMode
strong

Status of the Obstacle Avoidance subsystem.

Enumerator
Off 
On 

Definition at line 150 of file chassis.h.

◆ SwingSide

enum class Chassis::SwingSide
strong

Determines which side to lock during a swing turn.

Enumerator
Right 
Left 

Definition at line 445 of file chassis.h.

Constructor & Destructor Documentation

◆ Chassis()

Chassis::Chassis ( pros::Motor  fl,
pros::Motor  fr,
pros::Motor  bl,
pros::Motor  br,
pros::Imu  imu_sensor,
ChassisConfig  config 
)

Construct a new Chassis object.

Parameters
flFront left motor.
frFront right motor.
blBack left motor.
brBack right motor.
imu_sensorIMU sensor for heading.
configThe hardware configuration.

Member Function Documentation

◆ calibrate()

void Chassis::calibrate ( )

Calibrates sensors (e.g.

resets IMU, zeros encoders).

◆ setXGains()

void Chassis::setXGains ( std::vector< ScheduledGain steps)

Provide scheduled gains for the X-axis translation controller.

Parameters
stepsA vector of ScheduledGain objects.

◆ setYGains()

void Chassis::setYGains ( std::vector< ScheduledGain steps)

Provide scheduled gains for the Y-axis translation controller.

Parameters
stepsA vector of ScheduledGain objects.

◆ setThetaGains()

void Chassis::setThetaGains ( std::vector< ScheduledGain steps)

Provide scheduled gains for the rotational (Theta) controller.

Parameters
stepsA vector of ScheduledGain objects.

◆ setPose() [1/2]

void Chassis::setPose ( float  x,
float  y,
float  theta = 0.0f 
)

Manually reset the robot's odometry position.

Parameters
xX coordinate.
yY coordinate.
thetaHeading angle in degrees.

◆ setPose() [2/2]

void Chassis::setPose ( Pose  pose)

Reset the robot's odometry position to a Pose object.

Parameters
poseThe Pose object representing the new position and heading.

◆ getPose()

Pose Chassis::getPose ( bool  radians = false)

Get the current odometry pose of the robot.

Parameters
radiansTrue to return heading in radians, false for degrees.
Returns
Pose The current pose.

◆ calculateHolonomic()

XDriveVoltages Chassis::calculateHolonomic ( float  vx,
float  vy,
float  vt 
)

Calculate the individual motor voltages for a holonomic movement command.

Parameters
vxDesired X velocity.
vyDesired Y velocity.
vtDesired rotational velocity.
Returns
XDriveVoltages Structure containing the voltages for the 4 motors.

◆ setMotorVoltages()

void Chassis::setMotorVoltages ( XDriveVoltages  v)

Command the base motors with a set of voltages.

Parameters
vStruct containing voltages.

◆ brake()

void Chassis::brake ( )

Instructs all motors to brake using their configured brake mode.

◆ driveControl()

void Chassis::driveControl ( float  forward,
float  sideways,
float  rotation,
DriveCurves  drivecurves,
bool  fieldCentric,
float  headingOffset = 0.0f,
DriveCorrection  correction = {} 
)

Main driver control mapping logic.

Maps forward, sideways, and rotational input to motor commands. Allows for field-centric or robot-centric control modes with customizable curves.

Parameters
forwardForward translation input (typically from a joystick).
sidewaysSideways translation input.
rotationRotational input.
drivecurvesOptional curves to smooth inputs.
fieldCentricTrue if driver inputs map to absolute field axes instead of relative to the robot heading.
headingOffsetAn offset to adjust the definition of "forward" for field-centric mode.
correctionConfiguration for maintaining heading.

◆ followPath()

void Chassis::followPath ( const std::vector< PathPoint > &  path,
float  lookahead_inches,
MoveParams  params = defaultParams,
HeadingMode  headingMode = HeadingMode::FollowPath,
float  holdAngleDeg = 0.0f,
bool  reversed = false 
)

Autonomously follow a path defined by points.

Parameters
pathA vector of path points to follow.
lookahead_inchesPure-pursuit lookahead distance.
paramsMovement parameters and constraints.
headingModeDefines how the heading behaves while traversing the path.
holdAngleDegA specific angle to hold if HeadingMode::HoldAngle is selected.
reversedIf true, the robot traverses the path in reverse.

◆ turnToHeading()

void Chassis::turnToHeading ( float  targetDeg,
MoveParams  params = defaultParams 
)

Autonomously turn the robot to face a specific heading.

Parameters
targetDegThe target heading in degrees.
paramsMovement parameters.

◆ turnToPoint()

void Chassis::turnToPoint ( float  tx,
float  ty,
MoveParams  params = defaultParams 
)

Autonomously turn the robot to face a specific coordinate.

Parameters
txTarget X coordinate.
tyTarget Y coordinate.
paramsMovement parameters.

◆ moveToPoint()

void Chassis::moveToPoint ( float  tx,
float  ty,
MoveParams  params = defaultParams,
bool  angleCorrection = true 
)

Autonomously drive directly to a coordinate on the field.

Parameters
txTarget X coordinate.
tyTarget Y coordinate.
paramsMovement parameters.
angleCorrectionIf true, actively adjusts heading to face the point while moving.

◆ moveRelative()

void Chassis::moveRelative ( float  forward,
float  sideways,
MoveParams  params = defaultParams,
bool  holdHeading = true 
)

Move a relative distance using X and Y offsets.

Parameters
forwardDistance to move forward.
sidewaysDistance to move sideways.
paramsMovement parameters.
holdHeadingActively maintain heading while translating.

◆ moveDistance()

void Chassis::moveDistance ( float  distance,
MoveParams  params = {},
bool  holdHeading = true 
)

Drive straight for a specified distance.

Parameters
distanceDistance in inches.
paramsMovement parameters.
holdHeadingActively maintain heading while translating.

◆ strafeDistance()

void Chassis::strafeDistance ( float  distance,
MoveParams  params = defaultParams,
bool  holdHeading = true 
)

Strafe for a specified distance.

Parameters
distanceDistance in inches.
paramsMovement parameters.
holdHeadingActively maintain heading while translating.

◆ moveToPose()

void Chassis::moveToPose ( float  tx,
float  ty,
float  targetThetaDeg,
MoveParams  params = defaultParams 
)

Move the robot to an exact X, Y, and Theta simultaneously.

Parameters
txTarget X coordinate.
tyTarget Y coordinate.
targetThetaDegTarget heading.
paramsMovement parameters.

◆ curveCircle()

void Chassis::curveCircle ( float  targetThetaDeg,
float  radius,
MoveParams  params = defaultParams,
CurveDirection  direction = CurveDirection::Auto 
)

Drive in a circular arc until reaching a specified heading.

Parameters
targetThetaDegThe final heading of the arc.
radiusThe radius of the curved path.
paramsMovement parameters.
directionWhether to turn clockwise or counter-clockwise.

◆ waitUntilDone()

void Chassis::waitUntilDone ( )

Blocks the current thread until the current motion is finished.

◆ cancelAllMotions()

void Chassis::cancelAllMotions ( )

Halts all running background motions in the motion handler queue.

◆ odometryTask()

void Chassis::odometryTask ( )

Infinite loop function typically passed to a background PROS task to update position continuously.

◆ getDistanceTraveled()

float Chassis::getDistanceTraveled ( bool  convertToMeters = false)

Retrieves the total distance traveled during a motion segment.

Parameters
convertToMetersIf true, returns value in meters rather than inches.
Returns
float Distance traveled.

◆ cancelMotion()

void Chassis::cancelMotion ( )

Cancels the currently executing autonomous motion.

◆ waitUntil()

void Chassis::waitUntil ( float  distance)

Wait until a certain linear distance has been covered during a motion command.

Useful for triggering events mid-way through a path or moveToPoint call.

Parameters
distanceThe distance threshold.

◆ setEKFGains()

void Chassis::setEKFGains ( float  xProcessNoise,
float  yProcessNoise,
float  thetaProcessNoise,
float  measurementNoise 
)

Set specific internal Extended Kalman Filter variables manually.

Parameters
xProcessNoiseNoise in the X dimension.
yProcessNoiseNoise in the Y dimension.
thetaProcessNoiseNoise in heading dimension.
measurementNoiseIMU noise characteristic.

◆ setVelocityCalculations()

void Chassis::setVelocityCalculations ( bool  state)

Toggles whether to calculate velocities via odometry (computationally heavier).

Parameters
stateTrue to enable.

◆ detectCollision()

bool Chassis::detectCollision ( )

Detect sudden impact indicating a potential collision using acceleration delta.

Returns
true if collision detected.

◆ openLoop()

void Chassis::openLoop ( float  forward,
float  sideways,
float  rotation 
)

Apply direct open-loop power to the drivetrain without PID.

Parameters
forwardLinear power.
sidewaysStrafe power.
rotationRotational power.

◆ addObstacle()

void Chassis::addObstacle ( float  x,
float  y,
float  radius 
)

Add an obstacle to the avoidance system.

Parameters
xX coordinate.
yY coordinate.
radiusAvoidance radius.

◆ removeObstacle()

void Chassis::removeObstacle ( size_t  index)

Remove an obstacle by index.

Parameters
indexThe index.

◆ clearObstacles()

void Chassis::clearObstacles ( )

Clears all current obstacles from memory.

◆ setAvoidanceMode()

void Chassis::setAvoidanceMode ( AvoidanceMode  mode)

Enables or disables the obstacle avoidance system globally.

Parameters
modeAvoidanceMode::On or AvoidanceMode::Off.

◆ setAvoidanceParams()

void Chassis::setAvoidanceParams ( float  safetyMargin,
float  clearance 
)

Tunes the obstacle avoidance distance thresholds.

Parameters
safetyMarginPadding to treat the obstacle as larger than its radius.
clearanceRequired distance from the padded radius.

◆ setPotentialFieldParams()

void Chassis::setPotentialFieldParams ( float  ka,
float  kr,
float  influenceRadius 
)

Configures Artificial Potential Field parameters.

Parameters
kaAttraction to goal.
krRepulsion from obstacles.
influenceRadiusDistance at which an obstacle begins pushing the robot away.

◆ setRobotDimensionsAvoidance()

void Chassis::setRobotDimensionsAvoidance ( float  width,
float  height 
)

Set robot dimensions used specifically for avoidance calculations.

Parameters
widthRobot width.
heightRobot height.

◆ radToDeg()

float Chassis::radToDeg ( float  rad)

Utility: Convert Radians to Degrees.

Parameters
radRadians.
Returns
float Degrees.

◆ degToRad()

float Chassis::degToRad ( float  deg)

Utility: Convert Degrees to Radians.

Parameters
degDegrees.
Returns
float Radians.

◆ setEKFstate()

void Chassis::setEKFstate ( bool  state)

Toggle the internal EKF feature entirely.

Parameters
stateTrue to run EKF, false for raw basic odometry.

◆ addTrackingWheel()

void Chassis::addTrackingWheel ( TrackingWheelConfig  config)

Register a tracking wheel with the odometry module.

Parameters
configThe hardware configuration for the tracking wheel.

◆ clearTrackingWheels()

void Chassis::clearTrackingWheels ( )

Unregisters all external tracking wheels.

◆ move()

template<typename F >
void Chassis::move ( updateFunction,
MoveParams  params = defaultParams,
bool  fieldCentric = true,
float  headingOffset = 0.0f,
DriveCorrection  correction = {} 
)
inline

Generic templated loop to accept external calculation functions.

Template Parameters
FLambda type.
Parameters
updateFunctionThe function doing calculations and returning motor voltages.
paramsMovement boundaries.
fieldCentricTreat update inputs as field centric.
headingOffsetGlobal heading offset.
correctionCorrection params.

Definition at line 431 of file chassis.h.

◆ setMoveParams()

void Chassis::setMoveParams ( MoveParams  params)

Sets global default move parameters.

Parameters
paramsParameters to use as default.

◆ swingTurn()

void Chassis::swingTurn ( float  targetThetaDeg,
SwingSide  lockedSide,
MoveParams  params = defaultParams 
)

Execute a swing turn where one side of the robot is held stationary.

Parameters
targetThetaDegThe target heading.
lockedSideWhich side of the drive train to hold zero power to.
paramsMovement parameters.

◆ getControllerInput()

void Chassis::getControllerInput ( pros::Controller  master)

Reads inputs from the standard PROS controller into the drive control method.

Parameters
masterThe PROS Controller object.

◆ logReplayData()

void Chassis::logReplayData ( pros::Controller  master,
int  timeout_ms = 50 
)

Logs the driver's movements in real time to enable playback features.

Parameters
masterThe controller to read from.
timeout_msInterval to poll and log.

◆ disableReplayDataLogging()

void Chassis::disableReplayDataLogging ( )

Stops driver motion logging.

◆ runDriverReplay()

void Chassis::runDriverReplay ( std::vector< PathPoint data,
float  lookahead 
)

Playback previously recorded driver inputs autonomously.

Parameters
dataRecorded sequence of PathPoints or equivalent macro.
lookaheadFollow lookahead parameter for smoothing playback tracking.

Friends And Related Symbol Documentation

◆ odomTaskTrampoline

void odomTaskTrampoline ( void *  )
friend

Member Data Documentation

◆ motion

MotionHandler Chassis::motion

Background task handler instance.

Definition at line 262 of file chassis.h.