Odometry is smooth and fast but drifts. Vision is absolute and drift-free but noisy and occasional (and only when a tag is in view). Fusing them gives the best of both: a pose that updates every loop, stays smooth, and gets pulled back to the truth whenever a tag is seen.
The WPILib pose estimator#
WPILib provides DifferentialDrivePoseEstimator, SwerveDrivePoseEstimator, and MecanumDrivePoseEstimator. They work like odometry but accept vision corrections. Internally they use a Kalman-filter-style approach to blend the two sources by trust.
Two method calls do the work:
update(gyroAngle, wheelMeasurements)every loop — same as odometry, keeping the estimate current and smooth.addVisionMeasurement(visionPose, timestampSeconds)whenever you have a fresh vision pose. The estimator latency-compensates using the timestamp, applying the correction at the moment the image was actually captured.
// every loop
poseEstimator.update(gyro.getRotation2d(), modulePositions);
// when vision has a result
if (mt2 != null && mt2.tagCount > 0) {
poseEstimator.addVisionMeasurement(mt2.pose, mt2.timestampSeconds);
}
Standard deviations: tuning trust#
The crucial tuning knob is standard deviations — how much to trust each source. Smaller standard deviation = more trust. You set the vision trust with setVisionMeasurementStdDevs(VecBuilder.fill(xStdDev, yStdDev, thetaStdDev)) (or pass std devs per measurement in an overload of addVisionMeasurement).
- Trust vision more (smaller std devs) when many/close tags are visible.
- Trust vision less (larger std devs) at long range or with one tag.
- With MegaTag2, teams commonly distrust the vision heading entirely (a huge theta std dev, e.g.
VecBuilder.fill(0.7, 0.7, 9999999)) because the gyro heading is already feeding MegaTag2 — letting vision correct it would be circular.
Filtering bad measurements#
Before calling addVisionMeasurement, reject junk: no tags, the pose is off the field, the robot is rotating too fast, or the pose jumps implausibly far from the current estimate. A single bad vision frame fed in unfiltered can teleport your robot's idea of where it is and ruin an auto routine.
The payoff#
With good fusion, the robot can run vision-assisted autos, line up to score from anywhere on the field, and recover from a bump or wheel slip — all while degrading gracefully to plain odometry whenever no tag is visible. This is the capstone where every sensor in this branch comes together.
the part worth keeping
Key takeaways
- A WPILib pose estimator fuses odometry (update) with vision (addVisionMeasurement) and latency-compensates by timestamp.
- Standard deviations set how much to trust vision vs. odometry; trust vision less at long range or with one tag.
- Filter out bad vision frames (no tags, off-field, too-fast rotation, huge jumps) before feeding them in.
Programming, Controls & SensorsComputer Vision and Pose Estimationlesson 3 of 3
Keep going
Take the quiz+10 XP with an accountMore in Computer Vision and Pose Estimation
where this came from
Sources and corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgWPILib: Pose Estimators
- docs.photonvision.orgPhotonVision: Using WPILib Pose Estimation + PhotonVision
- docs.limelightvision.ioLimelight: MegaTag2 + pose estimator integration
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 15 min readFRC Odometry and Pose Estimation: Field-Centric Control with WPILibHow an FRC robot tracks its field position with WPILib: wheel odometry vs pose estimation, gyro heading, fusing AprilTag vision, and field-centric driving./blogread it
- 20 min readPhotonVision Setup for FRC: Install, Pipelines & AprilTag PosePhotonVision setup for FRC: install it on a Raspberry Pi or Orange Pi coprocessor, build an AprilTag pipeline, run multi-tag pose, and feed swerve odometry./blogread it
- 8 min readFRC Vision: Limelight vs PhotonVision and AprilTag TrackingCompare Limelight and PhotonVision for FRC vision: AprilTag tracking, pose estimation with addVisionMeasurement, MegaTag2, latency, calibration, and cost./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01What does WPILib's SwerveDrivePoseEstimator do?
02If you INCREASE the vision measurement standard deviations passed to the pose estimator, what is the effect?
03Which practice improves robustness when fusing AprilTag vision with odometry?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensorsopenclose
01 / prerequisites
02 / foundations-tools-and-first-program
03 / robot-program-and-command-based
04 / motors-and-control
05 / autonomous-trajectories-simulation
06 / sensing-fundamentals
07 / encoders
08 / gyros-imus-orientation
09 / closed-loop-control
10 / vision-pose-estimation
11 / worked-examples-mini-projects
- Not read yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not read yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not read yet:Mini-Project: A Teleop Swerve Drive Subsystem
- Not read yet:Mini-Project: An Autonomous Routine with PathPlanner
- Not read yet:Mini-Project: Vision-Aligned Scoring with Limelight
12 / common-mistakes-troubleshooting
13 / advanced-techniques-case-studies
- Not read yet:State-Space Control and Kalman Filtering
- Not read yet:Log Replay Architecture with AdvantageKit
- Not read yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not read yet:Robot Coordination, Alerts, and Operator Feedback
- Not read yet:Case Study: Hardening Software Before an Event