Skip to content
Physical AI
All experiments

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.

Loading simulation…

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

ameas=atrue+b+gsin⁡δ+nk,nk∼N(0,σ2)a_{meas} = a_{true} + b + g\sin\delta + n_k, \quad n_k \sim \mathcal N(0, \sigma^2)
v^(t)−v(t)=(b+gsin⁡δ) t+∑knk Δt\hat v(t) - v(t) = (b + g\sin\delta)\,t + \sum_k n_k\,\Delta t
p^(t)−p(t)≈12(b+gsin⁡δ) t2,std⁡[v^−v]=σΔt t\hat p(t) - p(t) \approx \tfrac12 (b + g\sin\delta)\,t^2, \qquad \operatorname{std}[\hat v - v] = \sigma\sqrt{\Delta t\, t}

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 error

Explained in Chapter 4: Sensors & Data