Pose Estimation Contract
Easydifficulty
The follower needs a trustworthy input
A path follower can correct only the error it is shown. If the pose source swaps axes, reports degrees where the controller expects radians, or is one loop stale, a correct controller will confidently drive the wrong way.
Choose one maintained localization stack, configure and tune it using its own documentation, then adapt it once at your code boundary:
Do not combine both stacks. Each owns its own coordinate conventions and update lifecycle; convert one stack's output into the contract below.
The contract
At the start of every OpMode loop, call update() exactly once. Every controller in that loop then
reads the same immutable PoseSample, so pose, velocity, and timestamp cannot come from different sensor
updates:
// The only interface a follower may see.
interface PoseSource {
void update(); // refresh sensors and estimate; ONCE per loop
PoseSample getSample(); // one coherent pose + fieldVelocity + timestamp
}
Refreshing is kept separate from reading on purpose. How many times per loop is update() called, and
how many times might followers, telemetry, and a logger each call getSample()?Show solution
update() once, getSample() as many times as anyone asks. Fusing them into one method would make
every read a refresh, so each consumer would get a different estimate and the sensor work
would run several times per loop for no benefit. Splitting them makes the sample immutable within a
loop, which is the whole contract.
Select one length unit for the adapter, such as metres or inches, and name it in the adapter and telemetry. Do not mix the two inside a calculation. The spatial convention is the one used throughout Control Lab:
- field points toward the far wall;
- field points left;
- heading is radians, counter-clockwise positive, with errors wrapped to ;
- velocity is field-frame length per second;
- an origin reset defines the pose at a physically marked start location.
sample.timestampSeconds() must advance after update(). Log its age; if the estimate is stale, stop or use
an explicitly designed fallback instead of feeding old state into the follower.
Five-motion contract check
Mark the robot's start pose on the field, raise it safely if the selected setup requires that, and log pose plus velocity while performing these checks slowly:
- Stationary: pose and velocity remain nearly still; noise is visible but does not steadily run away.
- Forward: driving through the robot's front increases field when it begins at heading zero.
- Left: translating left increases field .
- Counter-clockwise: turning left increases heading before it wraps at the seam.
- Return: returning to the marked start reveals accumulated position and heading drift.
Some slip and drift are expected. Record them rather than hiding them: a follower cannot repair a pose source whose axes, scale, freshness, or drift are wrong.
Encoder geometry, device wiring, wheel-delta integration, pose exponential integration, and estimator derivation are outside Control Lab's current scope. Follow the chosen library's maintained setup guide, then test only the adapter contract here.
Connect it to the loop
void loop() {
poseSource.update(); // ONCE, at the top
PoseSample sample = poseSource.getSample();
// The age of the estimate, worth logging every loop.
log(loopClockNow() - sample.timestampSeconds());
follower.update(sample); // every consumer gets THIS sample
}
What breaks if each consumer calls About 0.7 inches — comparable to the position tolerance a follower is trying to hit. Two followers in
the same loop would then be correcting toward targets that disagree by roughly their own tolerance, and
the disagreement grows linearly with speed, so it is worst exactly when the robot is moving fastest and
the corrections matter most. One getSample() for itself? At 60 inches per second, how far
apart are two readings taken 12 ms apart?Show solution
update() per loop makes the disagreement structurally impossible.
Next, adopt the shared Pose2d, Vector2d, and completion outcome, then
build the basic PID-to-Point follower.
Sources and further reading
- Road Runner tuning: maintained setup and tuning sequence for the Road Runner stack.
- Pedro Pathing localization: maintained localization setup for Pedro Pathing.
- Conventions & Notation: Control Lab's frame, angle, and unit conventions.