|
LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
|
Public LightLib odometry / pose-estimation API. More...
Namespaces | |
| namespace | ekf |
| namespace | field |
| namespace | lightcast |
| namespace | paths |
| namespace | units |
| Single source of truth for unit conversions. | |
| namespace | util |
| Misc math, geometry, and unit-conversion helpers. | |
Classes | |
| struct | Auton |
| One registered autonomous routine. More... | |
| class | AutonSelector |
| On-brain auton picker UI. More... | |
| class | Drive |
| Tank-drive chassis class. More... | |
| struct | DriveFF |
| Per-wheel feedforward + simple velocity-loop gains. More... | |
| class | HDrive |
| Tank drive with a single center-mounted strafe wheel (H-drive layout). More... | |
| struct | HermiteSegment |
| One segment of a quintic Hermite spline. More... | |
| class | HoloDrive |
| 4-motor holonomic drive — supports X-Drive and Mecanum configurations. More... | |
| struct | HoloPID |
| Internal PID used by HoloDrive / HDrive. More... | |
| struct | odom |
| One waypoint of an odom-mode movement. More... | |
| struct | PathEvent |
| Mid-path action triggered at a specific input waypoint. More... | |
| class | PID |
| Discrete PID controller with rich exit-condition support. More... | |
| struct | PidConstants |
| Container for one PID's four editable gain values. More... | |
| class | PidTuner |
| Live PID tuner UI driven by LVGL. More... | |
| class | Piston |
| Stateful 3-wire pneumatic piston with toggle helpers. More... | |
| struct | pose |
| 2D pose: position (in) and heading (deg). More... | |
| struct | RamseteConfig |
| RAMSETE controller and chassis-geometry config. More... | |
| class | RotationalSnap |
| Manual-then-snap controller for a motor + rotation-sensor pair. More... | |
| class | slew |
| Slew-rate limiter that ramps speed up linearly over a configurable distance. More... | |
| class | Spline |
| Concatenated quintic Hermite spline with arc-length parameterization. More... | |
| struct | SplineSample |
| Pose / velocity / acceleration sample produced by spline evaluation. More... | |
| class | tracking_wheel |
| Single tracking wheel for odometry. More... | |
| struct | TrajConstraints |
| Kinematic limits used by the trajectory generator. More... | |
| class | Trajectory |
| Time-parameterized trajectory: dense state table + total duration. More... | |
| struct | TrajState |
| One sample of a time-parameterized trajectory. More... | |
| struct | united_odom |
| One waypoint of an odom-mode movement, with okapi units. More... | |
| struct | united_pose |
| 2D pose with okapi units. More... | |
| struct | Waypoint |
| Single 2-D waypoint with optional heading and per-point speed cap. More... | |
Typedefs | |
| using | PoseGetterFn = pose(*)() |
External pose getter used by register_pose_source(). | |
| using | PoseSetterFn = void(*)(pose) |
External pose setter used by register_pose_source(). | |
Enumerations | |
| enum | PidType { PID_DRIVE = 0 , PID_TURN , PID_SWING , PID_HEADING , PID_EKF , PID_COUNT } |
| PID controller categories selectable in the tuner. More... | |
| enum | ConstSlot { KP = 0 , KI , KD , START_I , CONST_COUNT } |
| Index into a PidConstants slot. More... | |
Functions | |
| void | register_pose_source (PoseGetterFn getter, PoseSetterFn setter) |
| Register an external pose source. | |
| double | wrap180 (double a) |
| Normalize an angle in degrees to the half-open interval (-180, 180] so PID always takes the shortest path. | |
| void | reset () |
| Reset all internal pose state to (0, 0, 0). | |
| void | init (OdomSensors sensors, MCLConfig cfg={}) |
| Initialize the estimator. | |
| void | stop () |
| Stop the background odometry task. | |
| void | moveToPoint (float targetX, float targetY, int timeout, float maxSpeed, bool reversed) |
| Drive the chassis to a field-relative point (legacy entry point). | |
| Pose | getPose (bool radians=false) |
| void | setPose (Pose pose, bool radians=false) |
| Overwrite the current pose. | |
| Pose | getSpeed (bool radians=false) |
| Pose | getLocalSpeed (bool radians=false) |
| Pose | estimatePose (float time, bool radians=false) |
Linearly extrapolate the pose time seconds into the future, assuming current velocity holds. | |
| void | update () |
| Force one update step (normally called by the background task). | |
| Pose | getPoseRad () |
| Radian-only pose accessor. | |
| bool | runPath (const char *name, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Run a registered path by name. | |
| bool | runPath (const char *name, std::vector< PathEvent > events, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Variant accepting mid-path event triggers. | |
| void | ramsete_configure (RamseteConfig rc, DriveFF ff, TrajConstraints defaultCons) |
| Configure the RAMSETE follower. | |
| bool | followTrajectory (const Trajectory &traj, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Follow a pre-generated Trajectory. | |
| bool | followTrajectory (const std::vector< Waypoint > &wps, const TrajConstraints &cons, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Generate and follow a trajectory from waypoints. | |
| bool | followTrajectory (const std::vector< Waypoint > &wps, const TrajConstraints &cons, std::vector< PathEvent > events, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Generate-and-follow variant with mid-path event triggers. | |
| bool | runJerryioPath (const char *csv, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Run a waypoint path exported from path.jerryio.com (or any CSV-like text). | |
| bool | runJerryioPath (const char *csv, std::vector< PathEvent > events, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Variant with mid-path event triggers. | |
| bool | runJerryioPathFromSD (const char *filePath, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| Read the CSV from the V5 SD card (e.g. | |
| bool | runJerryioPathFromSD (const char *filePath, std::vector< PathEvent > events, bool reversed=false, int timeoutMs=-1, float poseErrBailIn=8.0f) |
| SD-card variant with mid-path event triggers. | |
| void | autotune_ekf_noise (int sampleMs=10, int durationMs=5000, int warmupMs=500) |
| Stationary EKF process-noise calibration. | |
| void | autotune_mcl_noise (int sampleMs=20, int durationMs=4000, int warmupMs=300) |
| Stationary MCL distance-sensor noise calibration. | |
| Trajectory | generateTrajectory (const std::vector< Waypoint > &wps, const TrajConstraints &cons, bool reversed=false) |
| Generate a time-parameterized trajectory from waypoints. | |
| uint32_t | auton_elapsed () |
| void | wait_until_auton (uint32_t ms) |
Block until ms milliseconds have elapsed since auton started. | |
| void | extras_init (light::Drive *chassis, pros::MotorGroup *leftMotors, pros::MotorGroup *rightMotors) |
| Register the user's drivetrain objects with LightLib. | |
| void | getDriveMotorGroups (pros::MotorGroup **leftOut, pros::MotorGroup **rightOut) |
| Look up the registered drivetrain motor groups. | |
| light::Drive * | getChassis () |
| void | ez_template_print () |
| Prints our branding all over your pros terminal. | |
| void | screen_print (std::string text, int line=0) |
| Prints to the brain screen in one string. | |
| std::string | exit_to_string (exit_output input) |
| Returns a human-readable name for an exit_output code. | |
Characterization routines | |
Each is meant to be run as its own selectable auton. | |
| void | characterize_kV_kA_kS (float maxVoltage=10.0f, float rampVps=0.25f) |
| Identify kV / kA / kS by ramping voltage and recording velocity. | |
| float | characterize_track_width (int rotations=10) |
| Identify the effective track width by spinning in place. | |
| float | characterize_a_lat_max () |
| Identify the maximum sustainable lateral acceleration. | |
| void | characterize_friction (float maxVoltage=10.0f, float stepV=0.5f) |
| Friction-FF auto-ID for the non-trajectory PID controllers. | |
Relay-feedback (Åström–Hägglund) PID auto-tune | |
Each routine runs a bang-bang oscillation around the current pose, measures the steady-state amplitude Ku = 4·h/(π·a), Pu = Tu,
kP = 0.6·Ku, kI = 2·kP/Pu, kD = kP·Pu/8 (Z-N classic PID)
then printfs the result AND calls the matching EZ
| |
| void | autotune_turn_pid (float reliefV=4.0f, int cycles=6, int timeoutMs=15000, int chunkCycles=2, int coolMs=5000) |
| void | autotune_drive_pid (float reliefV=6.0f, int cycles=5, int timeoutMs=15000, int chunkCycles=2, int coolMs=5000) |
| void | autotune_swing_pid (float reliefV=4.0f, int cycles=6, int timeoutMs=15000, int chunkCycles=2, int coolMs=5000) |
| void | autotune_heading_pid (float forwardV=3.0f, float reliefV=2.0f, int cycles=5, int timeoutMs=15000, int chunkCycles=2, int coolMs=5000) |
Variables | |
| PidTuner | pid_tuner |
| Process-wide singleton tuner instance. | |
| AutonSelector | auton_selector |
| Process-wide singleton selector instance. | |
| uint32_t | auton_start_ms |
| Millisecond timestamp captured right before the selected auton routine runs. | |
Public types and enums | |
| enum | e_type { SINGLE = 0 , SPLIT = 1 } |
| Arcade joystick layout. More... | |
| enum | e_swing { LEFT_SWING = 0 , RIGHT_SWING = 1 } |
| Direction for swing-turn motions. More... | |
| enum | exit_output { RUNNING = 1 , SMALL_EXIT = 2 , BIG_EXIT = 3 , VELOCITY_EXIT = 4 , mA_EXIT = 5 , ERROR_NO_CONSTANTS = 6 } |
| Result codes returned by PID::exit_condition. More... | |
| enum | e_mode { DISABLE = 0 , SWING = 1 , TURN = 2 , TURN_TO_POINT = 3 , DRIVE = 4 , POINT_TO_POINT = 5 , PURE_PURSUIT = 6 } |
| Active chassis motion mode. More... | |
| enum | drive_directions { FWD = 0 , FORWARD = FWD , fwd = FWD , forward = FWD , REV = 1 , REVERSE = REV , rev = REV , reverse = REV } |
| Drive direction with multiple spelling aliases. More... | |
| enum | e_angle_behavior { raw = 0 , left_turn = 1 , LEFT_TURN = 1 , counterclockwise = 1 , ccw = 1 , right_turn = 2 , RIGHT_TURN = 2 , clockwise = 2 , cw = 2 , shortest = 3 , longest = 4 } |
| How to choose a turn direction when reaching an absolute heading. More... | |
| typedef struct light::pose | pose |
| 2D pose: position (in) and heading (deg). | |
| typedef struct light::united_pose | united_pose |
| 2D pose with okapi units. | |
| typedef struct light::odom | odom |
| One waypoint of an odom-mode movement. | |
| typedef struct light::united_odom | united_odom |
| One waypoint of an odom-mode movement, with okapi units. | |
| const double | ANGLE_NOT_SET = 0.0000000000000000000001 |
| Sentinel value indicating "no angle specified". | |
| const okapi::QAngle | p_ANGLE_NOT_SET = 0.0000000000000000000001_deg |
| Sentinel value indicating "no angle specified" (united). | |
Public LightLib odometry / pose-estimation API.
Initialize once with init(), then poll getPose() / setPose() from any task. The backing task ticks every 10 ms.
| typedef struct light::odom light::odom |
One waypoint of an odom-mode movement.
| typedef struct light::pose light::pose |
2D pose: position (in) and heading (deg).
| using light::PoseGetterFn = typedef pose (*)() |
External pose getter used by register_pose_source().
| using light::PoseSetterFn = typedef void (*)(pose) |
External pose setter used by register_pose_source().
| typedef struct light::united_odom light::united_odom |
One waypoint of an odom-mode movement, with okapi units.
| typedef struct light::united_pose light::united_pose |
2D pose with okapi units.
| enum light::ConstSlot |
Index into a PidConstants slot.
| Enumerator | |
|---|---|
| KP | Proportional gain. |
| KI | Integral gain. |
| KD | Derivative gain. |
| START_I | Integral activation threshold. |
| CONST_COUNT | |
Definition at line 26 of file pid_tuner.hpp.
| enum light::e_mode |
| enum light::e_swing |
| enum light::e_type |
| enum light::exit_output |
Result codes returned by PID::exit_condition.
| enum light::PidType |
| uint32_t light::auton_elapsed | ( | ) |
| void light::autotune_drive_pid | ( | float | reliefV = 6.0f, |
| int | cycles = 5, |
||
| int | timeoutMs = 15000, |
||
| int | chunkCycles = 2, |
||
| int | coolMs = 5000 |
||
| ) |
| void light::autotune_ekf_noise | ( | int | sampleMs = 10, |
| int | durationMs = 5000, |
||
| int | warmupMs = 500 |
||
| ) |
Stationary EKF process-noise calibration.
Robot must be parked on the field throughout. Per-tick variance of (x, y, theta) over the sample window is integrated to Q values and pushed into the live EKF via setConfig().
| sampleMs | sample period in ms (default 10 — matches odom tick) |
| durationMs | total wall time to sample (ms) |
| warmupMs | discard initial transient before sampling (ms) |
| void light::autotune_heading_pid | ( | float | forwardV = 3.0f, |
| float | reliefV = 2.0f, |
||
| int | cycles = 5, |
||
| int | timeoutMs = 15000, |
||
| int | chunkCycles = 2, |
||
| int | coolMs = 5000 |
||
| ) |
| void light::autotune_mcl_noise | ( | int | sampleMs = 20, |
| int | durationMs = 4000, |
||
| int | warmupMs = 300 |
||
| ) |
Stationary MCL distance-sensor noise calibration.
Robot must be parked with every configured distance sensor pointed at a wall in range. Per-sensor std-dev of raw range readings (in inches) is averaged to set sensorSigmaIn, and outlierGapIn is set to ~3·sigma. Pushed into live MCL via setConfig().
| void light::autotune_swing_pid | ( | float | reliefV = 4.0f, |
| int | cycles = 6, |
||
| int | timeoutMs = 15000, |
||
| int | chunkCycles = 2, |
||
| int | coolMs = 5000 |
||
| ) |
| void light::autotune_turn_pid | ( | float | reliefV = 4.0f, |
| int | cycles = 6, |
||
| int | timeoutMs = 15000, |
||
| int | chunkCycles = 2, |
||
| int | coolMs = 5000 |
||
| ) |
| float light::characterize_a_lat_max | ( | ) |
Identify the maximum sustainable lateral acceleration.
| void light::characterize_friction | ( | float | maxVoltage = 10.0f, |
| float | stepV = 0.5f |
||
| ) |
Friction-FF auto-ID for the non-trajectory PID controllers.
Sweeps voltage open-loop, fits V = kS·sgn(v) + kV·v + kQ·v·|v| in motor- cmd units, and applies the result via chassis.friction_constants_set(). Raw samples are written to /usd/friction_id.csv when an SD card is present.
| void light::characterize_kV_kA_kS | ( | float | maxVoltage = 10.0f, |
| float | rampVps = 0.25f |
||
| ) |
Identify kV / kA / kS by ramping voltage and recording velocity.
| float light::characterize_track_width | ( | int | rotations = 10 | ) |
Identify the effective track width by spinning in place.
| Pose light::estimatePose | ( | float | time, |
| bool | radians = false |
||
| ) |
Linearly extrapolate the pose time seconds into the future, assuming current velocity holds.
| std::string light::exit_to_string | ( | exit_output | input | ) |
Returns a human-readable name for an exit_output code.
| input | the exit_output value |
| void light::extras_init | ( | light::Drive * | chassis, |
| pros::MotorGroup * | leftMotors, | ||
| pros::MotorGroup * | rightMotors | ||
| ) |
Register the user's drivetrain objects with LightLib.
Must be called once in initialize() before screen_task / lib_extras / moveToPoint are used.
Takes pointers rather than externing globals so LightLib can live in the PROS cold package without linker errors.
| chassis | the user's Drive instance |
| leftMotors | left-side motor group |
| rightMotors | right-side motor group |
| void light::ez_template_print | ( | ) |
Prints our branding all over your pros terminal.
| bool light::followTrajectory | ( | const std::vector< Waypoint > & | wps, |
| const TrajConstraints & | cons, | ||
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Generate and follow a trajectory from waypoints.
| wps | waypoint list |
| cons | kinematic limits |
| reversed | drive the path in reverse |
| timeoutMs | wall-time bail in ms (-1 = no timeout) |
| poseErrBailIn | bail if the pose error grows above this many inches |
| bool light::followTrajectory | ( | const std::vector< Waypoint > & | wps, |
| const TrajConstraints & | cons, | ||
| std::vector< PathEvent > | events, | ||
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Generate-and-follow variant with mid-path event triggers.
Events whose index is out of range are skipped (with a printf warning); the path still runs.
| bool light::followTrajectory | ( | const Trajectory & | traj, |
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Follow a pre-generated Trajectory.
| traj | the trajectory to follow |
| timeoutMs | wall-time bail in ms (-1 = no timeout) |
| poseErrBailIn | bail if the pose error grows above this many inches |
| Trajectory light::generateTrajectory | ( | const std::vector< Waypoint > & | wps, |
| const TrajConstraints & | cons, | ||
| bool | reversed = false |
||
| ) |
Generate a time-parameterized trajectory from waypoints.
| wps | ordered waypoint list |
| cons | kinematic limits |
| reversed | true if the robot should drive the path in reverse |
| light::Drive * light::getChassis | ( | ) |
| void light::getDriveMotorGroups | ( | pros::MotorGroup ** | leftOut, |
| pros::MotorGroup ** | rightOut | ||
| ) |
Look up the registered drivetrain motor groups.
Used by RAMSETE / characterization so they command the same motor groups the user registered via extras_init().
| leftOut | out: pointer to the registered left motor group, or nullptr |
| rightOut | out: pointer to the registered right motor group, or nullptr |
| Pose light::getLocalSpeed | ( | bool | radians = false | ) |
| Pose light::getPose | ( | bool | radians = false | ) |
| radians | true for radians, false for degrees. |
|
inline |
Radian-only pose accessor.
RAMSETE and trajectory code MUST use this, never getPose(false). Double-conversion between degrees and radians is the top bug source in ports of this algorithm — centralizing the one radian entry point avoids it.
Definition at line 224 of file odometry.hpp.
| Pose light::getSpeed | ( | bool | radians = false | ) |
| void light::init | ( | OdomSensors | sensors, |
| MCLConfig | cfg = {} |
||
| ) |
Initialize the estimator.
| sensors | sensor bundle (copied) |
| cfg | MCL configuration; defaults are usually fine |
| void light::moveToPoint | ( | float | targetX, |
| float | targetY, | ||
| int | timeout, | ||
| float | maxSpeed, | ||
| bool | reversed | ||
| ) |
Drive the chassis to a field-relative point (legacy entry point).
| targetX | target X, inches |
| targetY | target Y, inches |
| timeout | bail after this many ms |
| maxSpeed | speed cap, 0..127 |
| reversed | drive backwards |
| void light::ramsete_configure | ( | RamseteConfig | rc, |
| DriveFF | ff, | ||
| TrajConstraints | defaultCons | ||
| ) |
Configure the RAMSETE follower.
Call once in initialize() before any followTrajectory / runJerryioPath call.
| rc | controller and chassis geometry |
| ff | wheel feedforward gains |
| defaultCons | default kinematic limits used when none are passed explicitly |
| void light::register_pose_source | ( | PoseGetterFn | getter, |
| PoseSetterFn | setter | ||
| ) |
Register an external pose source.
When registered, all odom_*_get() reads return the externally-supplied pose instead of LightLib's wheel integrator, and odom_*_set() calls forward to the supplied setter. Used internally to route the legacy pid_odom_* motion through the fused EKF / MCL pose estimate.
| getter | function returning the current pose |
| setter | function applying a new pose |
| void light::reset | ( | ) |
Reset all internal pose state to (0, 0, 0).
| bool light::runJerryioPath | ( | const char * | csv, |
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Run a waypoint path exported from path.jerryio.com (or any CSV-like text).
Each non-empty, non-#-commented line has 2 or 3 floats separated by commas, tabs, or whitespace: "x, y" or "x, y, heading_rad". Units are inches and radians (LightLib convention: +Y forward, theta=0 faces +Y, CW+). Uses the TrajConstraints from ramsete_configure(). Extra columns past 3 are ignored, so exports with speed/lookahead fields still work.
| bool light::runJerryioPath | ( | const char * | csv, |
| std::vector< PathEvent > | events, | ||
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Variant with mid-path event triggers.
See PathEvent for index semantics.
| bool light::runJerryioPathFromSD | ( | const char * | filePath, |
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Read the CSV from the V5 SD card (e.g.
"/usd/paths/red_left.csv").
| bool light::runJerryioPathFromSD | ( | const char * | filePath, |
| std::vector< PathEvent > | events, | ||
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
SD-card variant with mid-path event triggers.
| bool light::runPath | ( | const char * | name, |
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Run a registered path by name.
| name | path name (must match a row in kAll[]) |
| reversed | drive the path in reverse |
| timeoutMs | wall-time bail in ms (-1 = no timeout) |
| poseErrBailIn | bail if pose error exceeds this many inches |
| bool light::runPath | ( | const char * | name, |
| std::vector< PathEvent > | events, | ||
| bool | reversed = false, |
||
| int | timeoutMs = -1, |
||
| float | poseErrBailIn = 8.0f |
||
| ) |
Variant accepting mid-path event triggers.
See PathEvent.
| void light::screen_print | ( | std::string | text, |
| int | line = 0 |
||
| ) |
Prints to the brain screen in one string.
Splits input between lines with '
' or when text longer then 32 characters.
| text | input string |
| line | starting line to print on, defaults to 0 |
| void light::setPose | ( | Pose | pose, |
| bool | radians = false |
||
| ) |
Overwrite the current pose.
| void light::stop | ( | ) |
Stop the background odometry task.
| void light::update | ( | ) |
Force one update step (normally called by the background task).
| void light::wait_until_auton | ( | uint32_t | ms | ) |
Block until ms milliseconds have elapsed since auton started.
If that point is already in the past, returns immediately.
| ms | wall-clock target, in ms since auton start |
| double light::wrap180 | ( | double | a | ) |
Normalize an angle in degrees to the half-open interval (-180, 180] so PID always takes the shortest path.
| a | input angle in degrees |
| const double light::ANGLE_NOT_SET = 0.0000000000000000000001 |
|
extern |
Process-wide singleton selector instance.
|
extern |
Millisecond timestamp captured right before the selected auton routine runs.
Set by LightLib in autonomous(); read by the helpers below.
| const okapi::QAngle light::p_ANGLE_NOT_SET = 0.0000000000000000000001_deg |
|
extern |
Process-wide singleton tuner instance.