2702 Recipes

Localization

How a robot tracks its pose on the field. Odometry math, Kalman filters, WPILib's pose estimators, and factor graphs with GTSAM.

This section explains how a robot keeps track of its pose: where it is on the field and which way it faces. It starts with odometry, builds up to the Kalman filter, looks closely at what WPILib's pose estimators really do, and ends with factor graphs, the approach behind libraries such as GTSAM.

The Vision section explains where vision measurements come from. This section is about what to do with them. If you are new to both, read Why Vision first. It explains why odometry alone drifts and why vision fixes it.

What you need

High-school algebra. Page 2 uses a little probability (averages and standard deviations), and the later pages use vectors and matrices. Each step is explained. Every page has an interactive widget.

Where to start

Read the pages in order. Each one builds on the one before.

Key ideas at a glance

IdeaOne-line summaryPage
Integrate along an arcTurning each step's movement into field coordinates with the start heading is off by several centimeters per meter while spinning. WPILib's pose exponential is not.Localization Basics
Random error grows slowly, bias grows fastRandom odometry noise grows with the square root of distance. A wrong wheel diameter grows with distance.Localization Basics
Track the uncertaintyA Kalman filter keeps a variance next to the estimate, and uses it to decide how far each measurement moves the estimate.Kalman Filters
Gate bad measurementsReject a measurement that is too many standard deviations from the prediction. It fails when the robot was really shoved.Kalman Filters
WPILib's gain is fixedEach vision measurement moves the estimate by σs/(σs+σv)\sigma_s / (\sigma_s + \sigma_v) of the way, however long it has been since the last one.WPILib Pose Estimators
Rate matters as much as trustMore measurements per second pull harder, because the gain applies to every one.WPILib Pose Estimators
Timestamps, in orderUse the capture time, in the right timebase, and add measurements oldest first.WPILib Pose Estimators
Smooth, don't just filterA factor graph keeps the recent trajectory and re-solves it, so a later measurement can fix an earlier mistake.Factor Graphs and GTSAM
Measure in pixelsTag corners as factors carry the true shape of vision uncertainty, instead of a guessed pose standard deviation.Factor Graphs and GTSAM

On this page