|
LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
|
This tutorial covers the autonomous configuration surface — the three files that, between them, decide what runs in autonomous, how the robot moves while running it, and what state the mechanisms start in. Once you understand the split, adding a new auton is mechanical.
| File | Job |
|---|---|
include/autons.hpp | Declare every auton function — one line each. |
src/autons.cpp | Write the actual auton bodies, plus default_constants() and default_positions(). |
src/auton_config.cpp | Register each auton with the brain-screen picker. |
A new auton needs touches in all three. Skip any one and either it won't compile, won't appear on the screen, or won't be callable from other code.
1. Declare it in autons.hpp:
2. Write it in autons.cpp:
3. Register it in auton_config.cpp:
That's the whole loop. Recompile, flash, the button shows up on the brain.
Called once from initialize(), before any auton runs. default_constants() is where every PID gain, exit condition, slew rate, and odom knob lives. It's the only place these should be set in code — anything you pid_*_constants_set() elsewhere will silently override the global tune for the rest of the match, which is almost never what you want.
The full set of knobs, with what each one actually does:
The format is (kP, kI, kD) for every one. See PID Tuning for the full tuning workflow — the short version is "kP for response, kD for damping, kI almost always zero."
A motion exits when either:
small_error for small_timeout, orbig_error for big_timeout.Plus two failsafes: velocity_timeout (motors stalled) and mech_timeout (gave up entirely). Tighter exit conditions = more accurate but slower. Loose ones = fast and chainable.
How close the robot must be before pid_wait_quick_chain() exits and queues the next motion. Larger = exit sooner, fluider transitions, less final accuracy. These are the secret to autons that look fast.
Format: (distance_to_ramp_over, starting_speed). The motor output is clamped to start at starting_speed and ramp linearly up to whatever the PID is asking for, over the given distance. Stops the wheels from slipping on launch.
See Odom Motion for what each of these knobs feels like in practice.
Three structs: geometry, feedforward + velocity P, default trajectory constraints. The numbers come from the characterization routines. The defaults will drive but won't track cleanly until you've replaced them with measured values.
Called once from initialize(), before the match. Every piston the robot has should be in here, in the state you want at the buzzer. Forgetting one isn't a compile error — it's a piston that starts in whatever state it happened to be in when you powered on, which on a match field is "extended into another robot."
This file does one thing: tell the brain-screen picker which buttons exist. See UI Config for what each button looks like on screen and what the description shows up as.
Order matters — the first registered button is selected by default on boot. Put your most-likely competition pick first.
Tuning routines often take parameters or call into namespaces. Wrap them in a lambda:
The lambda is itself a void() — same signature as a regular auton, so the selector doesn't care.
Goal: add a 15-point AWP auton called "Right AWP."
**autons.hpp:**
**autons.cpp:**
**auton_config.cpp:**
Compile, flash, button appears on the brain. Done.
auton_config.cpp is opt-in — the function existing isn't enough.autons.cpp. The linker will catch a missing body, so this is more often "the body has a `return;` at the top from earlier
debugging."default_constants(). The panel is a scratchpad.subsystems.hpp but forgot to add a line for it in default_positions(). Add every piston, every time.slew_drive_constants_set is for. Bumping the starting speed up too high makes a fresh battery slip; too low makes a tired battery feel sluggish. The default of 30 is a good compromise.ramsete_configure() in default_constants() to make them permanent.