An error budget

Predicting how far out you will be before you drive, which is what covariance is for.

U3.6Odometry and driftUniversity25 min

Do this lesson in the simulator

Before driving, an engineer can usually say how far out the robot will be at the end. That prediction is an error budget: each source of error, how much it contributes, and the total.

It is worth doing because it tells you what to fix. Spending a week on the noise when the bias is five times larger is a week wasted, and the budget shows that before the week starts.

A budget for a 2 m straight run

Source Size What it costs over 200 cm
gyro bias, uncalibrated 0.19 deg/s over 10 s = 1.9 deg by the end 200 * 0.017 = 3.3 cm sideways
gyro bias, calibrated 0.025 deg/s left over = 0.25 deg by the end about 0.4 cm sideways
flow scale 3 percent 6 cm along
flow noise 0.7 cm/s, 100 steps about 0.7 cm, random walk
slip a guess: 1 percent 2 cm, direction unknown

The sizes are this robot's. Its gyro reads about 0.19 deg/s when still. The 4 second average from U3.4 measures -0.17, which leaves 0.025 deg/s behind after calibration. Its flow sensor reads about 3 percent high going forwards.

The heading rows use half the final heading error, because a bias makes the heading error grow steadily from nothing: on average over the run it is about 1 degree, not 1.9. That is why the bias term grows with the square of the time: the same bias over a one minute run is 36 times as much, about 1.2 m sideways.

Error against the length of the run: the scale error grows in a straight line, the bias error with the square of the time01020304050600255075100125length of the run, s (at 20 cm/s)error at the end, cmthe 2 m runequal at 18 s1193616red: gyro bias 0.19 deg/s, sidewaysplain: scale 3 percent, alonggreen: bias calibrated, 0.025 deg/s
The table's rows, run for longer. At 10 s the scale costs 6 cm and the bias 3.3, but the scale grows in a straight line and the bias with the square of the time, so they are equal at 18 s and by a minute the bias costs 119 cm against 36. Calibrated, the bias costs 16 cm in a minute.

Read that table and two things stand out. Over 2 m the scale error is already the biggest term, so it is the thing to attack. The bias comes second, but only because the run is short: over a minute it costs 1.2 m against 36 cm of scale. Calibrating the gyro costs a few seconds of standing still, so do it every time.

Adding the pieces up

Independent errors add in quadrature, not directly: the total is the square root of the sum of the squares. Two 3 cm errors make about 4.2 cm, not 6, because they are unlikely to be at their worst in the same direction at once.

from bugbot import *
import math
connect()

pieces = {"heading": 0.4, "scale": 6.0, "noise": 0.7, "slip": 2.0}
total = math.sqrt(sum(v * v for v in pieces.values()))
for name, v in pieces.items():
    print(name.ljust(8), v, "cm")
print("total    ", round(total, 1), "cm")

Run this in the simulator

Note what quadrature does to the small terms. The noise contributes 0.7 cm on its own and changes the total by less than a millimetre. Anything much smaller than the largest term is not worth working on, which is the most useful thing a budget tells you.

Each piece of the budget drawn as a square of its size; the total is the square whose area is all of theirs togetherscale6 cmarea 36slip2 cmarea 4noise0.7 cmarea 0.49heading0.4 cmarea 0.16total6.4 cmarea 40.65=
Squaring and adding is adding areas. The scale's square alone is 36 of the total's 40.65; the other three together only add the thin green rim round it. The noise's square, 0.49, moves the total by less than a millimetre.

This is covariance, informally

A budget is a statement about a distribution: not "I will be 6.4 cm out" but "I will be within about 6.4 cm, most of the time, and further out mainly along the direction I drove".

That last part matters. The error is not a circle. Scale error stretches along the direction of travel, heading error throws you sideways, and after a long straight the uncertainty is a long thin ellipse rather than a disc. A filter that carries a full covariance matrix carries exactly that ellipse, and that is the machinery of U6.5.

Where the robot may end up after the 2 m run: a long ellipse along the drive, inside the disc a single number suggeststhe 2 m runacross: ±2.2 cmalong: ±6.4 cmdashed: a disc of 6.4 cmthe end of the run,magnified
The same budget split by direction. The scale works only along the drive and the heading only across it; the noise and the slip can go either way, so they widen both. That makes about ±6.4 cm along and ±2.2 cm across: an ellipse 3 times as long as it is wide, not the 6.4 cm disc.

Task: an error budget

Print what you expect the dead reckoning error to be over your run, as predicted error:, before you drive. Then drive at least 90 cm and print actual error:, the real gap between odometry() and position().

from bugbot import *
import math
connect()

DISTANCE = 100.0

Challenges

  1. Run the same thing at set_noise(3) and see which line of the budget you should have tripled.
  2. Budget a run with four corners in it. What changes?
  3. Repeat the run ten times and compare the spread of the actual errors with your predicted number.