|
HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
|
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 *) |
The main Chassis controller class.
Integrates odometry, PID tuning via scheduling, autonomous movement APIs, driver control functions, obstacle avoidance, and path following algorithms.
|
strong |
|
strong |
|
strong |
| 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.
| fl | Front left motor. |
| fr | Front right motor. |
| bl | Back left motor. |
| br | Back right motor. |
| imu_sensor | IMU sensor for heading. |
| config | The hardware configuration. |
| void Chassis::calibrate | ( | ) |
Calibrates sensors (e.g.
resets IMU, zeros encoders).
| void Chassis::setXGains | ( | std::vector< ScheduledGain > | steps | ) |
Provide scheduled gains for the X-axis translation controller.
| steps | A vector of ScheduledGain objects. |
| void Chassis::setYGains | ( | std::vector< ScheduledGain > | steps | ) |
Provide scheduled gains for the Y-axis translation controller.
| steps | A vector of ScheduledGain objects. |
| void Chassis::setThetaGains | ( | std::vector< ScheduledGain > | steps | ) |
Provide scheduled gains for the rotational (Theta) controller.
| steps | A vector of ScheduledGain objects. |
| void Chassis::setPose | ( | float | x, |
| float | y, | ||
| float | theta = 0.0f |
||
| ) |
Manually reset the robot's odometry position.
| x | X coordinate. |
| y | Y coordinate. |
| theta | Heading angle in degrees. |
| void Chassis::setPose | ( | Pose | pose | ) |
| Pose Chassis::getPose | ( | bool | radians = false | ) |
Get the current odometry pose of the robot.
| radians | True to return heading in radians, false for degrees. |
| XDriveVoltages Chassis::calculateHolonomic | ( | float | vx, |
| float | vy, | ||
| float | vt | ||
| ) |
Calculate the individual motor voltages for a holonomic movement command.
| vx | Desired X velocity. |
| vy | Desired Y velocity. |
| vt | Desired rotational velocity. |
| void Chassis::setMotorVoltages | ( | XDriveVoltages | v | ) |
Command the base motors with a set of voltages.
| v | Struct containing voltages. |
| void Chassis::brake | ( | ) |
Instructs all motors to brake using their configured brake mode.
| 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.
| forward | Forward translation input (typically from a joystick). |
| sideways | Sideways translation input. |
| rotation | Rotational input. |
| drivecurves | Optional curves to smooth inputs. |
| fieldCentric | True if driver inputs map to absolute field axes instead of relative to the robot heading. |
| headingOffset | An offset to adjust the definition of "forward" for field-centric mode. |
| correction | Configuration for maintaining heading. |
| 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.
| path | A vector of path points to follow. |
| lookahead_inches | Pure-pursuit lookahead distance. |
| params | Movement parameters and constraints. |
| headingMode | Defines how the heading behaves while traversing the path. |
| holdAngleDeg | A specific angle to hold if HeadingMode::HoldAngle is selected. |
| reversed | If true, the robot traverses the path in reverse. |
| void Chassis::turnToHeading | ( | float | targetDeg, |
| MoveParams | params = defaultParams |
||
| ) |
Autonomously turn the robot to face a specific heading.
| targetDeg | The target heading in degrees. |
| params | Movement parameters. |
| void Chassis::turnToPoint | ( | float | tx, |
| float | ty, | ||
| MoveParams | params = defaultParams |
||
| ) |
Autonomously turn the robot to face a specific coordinate.
| tx | Target X coordinate. |
| ty | Target Y coordinate. |
| params | Movement parameters. |
| void Chassis::moveToPoint | ( | float | tx, |
| float | ty, | ||
| MoveParams | params = defaultParams, |
||
| bool | angleCorrection = true |
||
| ) |
Autonomously drive directly to a coordinate on the field.
| tx | Target X coordinate. |
| ty | Target Y coordinate. |
| params | Movement parameters. |
| angleCorrection | If true, actively adjusts heading to face the point while moving. |
| void Chassis::moveRelative | ( | float | forward, |
| float | sideways, | ||
| MoveParams | params = defaultParams, |
||
| bool | holdHeading = true |
||
| ) |
Move a relative distance using X and Y offsets.
| forward | Distance to move forward. |
| sideways | Distance to move sideways. |
| params | Movement parameters. |
| holdHeading | Actively maintain heading while translating. |
| void Chassis::moveDistance | ( | float | distance, |
| MoveParams | params = {}, |
||
| bool | holdHeading = true |
||
| ) |
Drive straight for a specified distance.
| distance | Distance in inches. |
| params | Movement parameters. |
| holdHeading | Actively maintain heading while translating. |
| void Chassis::strafeDistance | ( | float | distance, |
| MoveParams | params = defaultParams, |
||
| bool | holdHeading = true |
||
| ) |
Strafe for a specified distance.
| distance | Distance in inches. |
| params | Movement parameters. |
| holdHeading | Actively maintain heading while translating. |
| void Chassis::moveToPose | ( | float | tx, |
| float | ty, | ||
| float | targetThetaDeg, | ||
| MoveParams | params = defaultParams |
||
| ) |
Move the robot to an exact X, Y, and Theta simultaneously.
| tx | Target X coordinate. |
| ty | Target Y coordinate. |
| targetThetaDeg | Target heading. |
| params | Movement parameters. |
| void Chassis::curveCircle | ( | float | targetThetaDeg, |
| float | radius, | ||
| MoveParams | params = defaultParams, |
||
| CurveDirection | direction = CurveDirection::Auto |
||
| ) |
Drive in a circular arc until reaching a specified heading.
| targetThetaDeg | The final heading of the arc. |
| radius | The radius of the curved path. |
| params | Movement parameters. |
| direction | Whether to turn clockwise or counter-clockwise. |
| void Chassis::waitUntilDone | ( | ) |
Blocks the current thread until the current motion is finished.
| void Chassis::cancelAllMotions | ( | ) |
Halts all running background motions in the motion handler queue.
| void Chassis::odometryTask | ( | ) |
Infinite loop function typically passed to a background PROS task to update position continuously.
| float Chassis::getDistanceTraveled | ( | bool | convertToMeters = false | ) |
Retrieves the total distance traveled during a motion segment.
| convertToMeters | If true, returns value in meters rather than inches. |
| void Chassis::cancelMotion | ( | ) |
Cancels the currently executing autonomous motion.
| 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.
| distance | The distance threshold. |
| void Chassis::setEKFGains | ( | float | xProcessNoise, |
| float | yProcessNoise, | ||
| float | thetaProcessNoise, | ||
| float | measurementNoise | ||
| ) |
Set specific internal Extended Kalman Filter variables manually.
| xProcessNoise | Noise in the X dimension. |
| yProcessNoise | Noise in the Y dimension. |
| thetaProcessNoise | Noise in heading dimension. |
| measurementNoise | IMU noise characteristic. |
| void Chassis::setVelocityCalculations | ( | bool | state | ) |
Toggles whether to calculate velocities via odometry (computationally heavier).
| state | True to enable. |
| bool Chassis::detectCollision | ( | ) |
Detect sudden impact indicating a potential collision using acceleration delta.
| void Chassis::openLoop | ( | float | forward, |
| float | sideways, | ||
| float | rotation | ||
| ) |
Apply direct open-loop power to the drivetrain without PID.
| forward | Linear power. |
| sideways | Strafe power. |
| rotation | Rotational power. |
| void Chassis::addObstacle | ( | float | x, |
| float | y, | ||
| float | radius | ||
| ) |
Add an obstacle to the avoidance system.
| x | X coordinate. |
| y | Y coordinate. |
| radius | Avoidance radius. |
| void Chassis::removeObstacle | ( | size_t | index | ) |
Remove an obstacle by index.
| index | The index. |
| void Chassis::clearObstacles | ( | ) |
Clears all current obstacles from memory.
| void Chassis::setAvoidanceMode | ( | AvoidanceMode | mode | ) |
Enables or disables the obstacle avoidance system globally.
| mode | AvoidanceMode::On or AvoidanceMode::Off. |
| void Chassis::setAvoidanceParams | ( | float | safetyMargin, |
| float | clearance | ||
| ) |
Tunes the obstacle avoidance distance thresholds.
| safetyMargin | Padding to treat the obstacle as larger than its radius. |
| clearance | Required distance from the padded radius. |
| void Chassis::setPotentialFieldParams | ( | float | ka, |
| float | kr, | ||
| float | influenceRadius | ||
| ) |
Configures Artificial Potential Field parameters.
| ka | Attraction to goal. |
| kr | Repulsion from obstacles. |
| influenceRadius | Distance at which an obstacle begins pushing the robot away. |
| void Chassis::setRobotDimensionsAvoidance | ( | float | width, |
| float | height | ||
| ) |
Set robot dimensions used specifically for avoidance calculations.
| width | Robot width. |
| height | Robot height. |
| float Chassis::radToDeg | ( | float | rad | ) |
Utility: Convert Radians to Degrees.
| rad | Radians. |
| float Chassis::degToRad | ( | float | deg | ) |
Utility: Convert Degrees to Radians.
| deg | Degrees. |
| void Chassis::setEKFstate | ( | bool | state | ) |
Toggle the internal EKF feature entirely.
| state | True to run EKF, false for raw basic odometry. |
| void Chassis::addTrackingWheel | ( | TrackingWheelConfig | config | ) |
Register a tracking wheel with the odometry module.
| config | The hardware configuration for the tracking wheel. |
| void Chassis::clearTrackingWheels | ( | ) |
Unregisters all external tracking wheels.
|
inline |
Generic templated loop to accept external calculation functions.
| F | Lambda type. |
| updateFunction | The function doing calculations and returning motor voltages. |
| params | Movement boundaries. |
| fieldCentric | Treat update inputs as field centric. |
| headingOffset | Global heading offset. |
| correction | Correction params. |
| void Chassis::setMoveParams | ( | MoveParams | params | ) |
Sets global default move parameters.
| params | Parameters to use as default. |
| void Chassis::swingTurn | ( | float | targetThetaDeg, |
| SwingSide | lockedSide, | ||
| MoveParams | params = defaultParams |
||
| ) |
Execute a swing turn where one side of the robot is held stationary.
| targetThetaDeg | The target heading. |
| lockedSide | Which side of the drive train to hold zero power to. |
| params | Movement parameters. |
| void Chassis::getControllerInput | ( | pros::Controller | master | ) |
Reads inputs from the standard PROS controller into the drive control method.
| master | The PROS Controller object. |
| void Chassis::logReplayData | ( | pros::Controller | master, |
| int | timeout_ms = 50 |
||
| ) |
Logs the driver's movements in real time to enable playback features.
| master | The controller to read from. |
| timeout_ms | Interval to poll and log. |
| void Chassis::disableReplayDataLogging | ( | ) |
Stops driver motion logging.
| void Chassis::runDriverReplay | ( | std::vector< PathPoint > | data, |
| float | lookahead | ||
| ) |
Playback previously recorded driver inputs autonomously.
| data | Recorded sequence of PathPoints or equivalent macro. |
| lookahead | Follow lookahead parameter for smoothing playback tracking. |
|
friend |
| MotionHandler Chassis::motion |