Lesson 05 · Part 2 · Sensing
IMU and tilt
Mission: Estimate how far a drone is tilted from a gyro and an accelerometer, and blend them so each one covers the other’s weakness.
The interactive version of this lesson needs JavaScript. Below are its steps as text.
Steps
1. A gyro measures turning, not tilt
Press the button. The drone is held still at 10 degrees of roll. Three estimates are plotted: the gyro alone, the accelerometer alone, and a blend.
Why it matters: A gyro measures rate of turn in degrees per second. To get an angle you add up the rate over time, which is where errors build.
2. Predict the gyro drift
Predict first, then run. The gyro bias is 1 degree per second, and the simulation lasts 20 seconds.
Why it matters: A bias of 1 degree per second is added to the angle every second. Over 20 seconds that is 20 degrees, which is why a gyro alone cannot hold an angle.
3. Gyro bias, live
Drag the gyro bias slider (degrees per second), then press Run.
Why it matters: The drift is the bias times the time. A bigger bias makes the gyro alone useless faster.
4. Accelerometer noise, live
Drag the accelerometer noise slider (m/s² standard deviation), then press Run. Watch the grey accelerometer line.
Why it matters: The accelerometer reads gravity, so it has no drift, but any shake adds noise. Its estimate is good on average and poor at any instant.
5. The complementary blend
Press Run for the blend with its default setting (98 % gyro, 2 % accelerometer each step).
Why it matters: The blend trusts the gyro over short times and the accelerometer over long times. The gyro’s drift is corrected slowly by the accelerometer, and its noise is smoothed.
6. Your reading: a sensor datasheet
Open the Notebook tab. Find the gyro bias or noise spec on any IMU datasheet (for example the BMI088 used on the Crazyflie 2.1), and enter one number with its unit.
Why it matters: Sensor datasheets give bias and noise with units, and the units matter. A number in degrees per second is not comparable with one in radians per second.
Go deeper
The maths in this lesson
gyro only φ̂ = φ̂_prev + (p + b)·Δt (b is the bias) accelerometer φ_acc = atan2(a_y, a_z) blend φ̂ = α·(φ̂_prev + p·Δt) + (1 − α)·φ_acc, α = 0.98
The steady error of the blend is roughly α·b·Δt/(1 − α), so it is bounded and small. The gyro-only error grows without limit.
Model limits
- The drone is held still at 10 degrees, so the accelerometer sees only gravity. In flight, thrust adds an acceleration and this simple tilt estimate is wrong; real flight needs more.
- The IMU here runs at 100 Hz; the flight loop runs faster.
- The bias, noise and blend values are simulation choices, not Crazyflie specifications.