Integrating an accelerometer
Why integrating acceleration to get velocity and position drifts: a constant bias b gives a velocity error b·t and a position error b·t²/2, white noise adds a random walk, and a small orientation error leaks gravity into the horizontal axis.
What it demonstrates
Why integrating acceleration to get velocity and position drifts: a constant bias b gives a velocity error b·t and a position error b·t²/2, white noise adds a random walk, and a small orientation error leaks gravity into the horizontal axis.
How it works
A robot moves along a line with a known acceleration profile. A simulated 200 Hz accelerometer reports the true acceleration plus a constant bias, Gaussian white noise and g·sin(δ) from an orientation error δ (the part of gravity that is not subtracted correctly).
The true and the measured accelerations are integrated with the same semi-implicit Euler scheme, so every difference between the curves comes from sensor error. The random numbers come from a seeded generator (mulberry32), so a run is reproducible and the unit tests can check the statistics.
Adjustable parameters
- True motion: still, shuttle, start–stop
- Bias b (−0.2 to 0.2 m/s²)
- White noise σ per sample (0–0.3 m/s²)
- Orientation error (0–3°)
- Noise seed
Known limitations
- One axis. Real dead reckoning is 3-D, and orientation errors also grow over time because the gyro drifts.
- Bias is constant here. Real biases change with temperature and time (see the bias-drift slider in the next experiment).
- No corrections such as zero-velocity updates, leg odometry or external position fixes, which is exactly what real estimators add.
Equations
Core update rule
// lib/sim/ch04-sensors.ts — one 5 ms sample
aTrue = trueAccel(profile, t);
aMeas = aTrue + bias + g * Math.sin(tiltError) + noise * gaussian(rng);
vTrue += aTrue * dt; pTrue += vTrue * dt;
vEst += aMeas * dt; pEst += vEst * dt; // same integrator, so error = sensor errorExplained in Chapter 4: Sensors & Data