Skip to main content

Module 3 — Sensors & state estimation

The flight controller cannot see the drone — it infers it, 8000 times a second, from noisy chips that each lie in a different way.

🟢 Foundations. Core sensors: gyroscope (rotation rate, °/s — the heartbeat of acro flight), accelerometer (specific force — gives "which way is down" when not accelerating), magnetometer (compass), barometer (altitude from pressure), GNSS (position, ~1–3 m). Each is imperfect: gyros drift, accelerometers shake, compasses lie near current-carrying wires, barometers feel propwash, GPS wanders. Estimation = mixing them so their errors cancel.

🟡 Practitioner. The classic mix is the complementary filter — trust the gyro short-term, the accelerometer long-term:

θ^k=α(θ^k1+ωkΔt)+(1α)θacc,k,α0.98\hat\theta_k = \alpha\left(\hat\theta_{k-1} + \omega_k\,\Delta t\right) + (1-\alpha)\,\theta_{\text{acc},k},\qquad \alpha \approx 0.98

Ten lines of code, runs anywhere, and it is angle mode on simple firmware. Learn sampling discipline: a gyro sampled at 8 kHz can only represent vibrations below the Nyquist frequency 4 kHz; anything faster aliases into fake low-frequency signal the PID loop will chase. This is why soft-mounting and filtering (Module 9) exist.

🔴 Advanced. The industrial answer is the Kalman filter — the statistically optimal blend of a motion model and measurements, each weighted by its uncertainty:

Predict:x^=Fx^,P=FPF+QGain:K=PH(HPH+R)1Update:x^=x^+K(zHx^),P=(IKH)P\begin{aligned} \textbf{Predict:}\quad & \hat{\mathbf x}^- = \mathbf F\hat{\mathbf x},\qquad \mathbf P^- = \mathbf F\mathbf P\mathbf F^\top + \mathbf Q\\[2pt] \textbf{Gain:}\quad & \mathbf K = \mathbf P^-\mathbf H^\top(\mathbf H\mathbf P^-\mathbf H^\top + \mathbf R)^{-1}\\[2pt] \textbf{Update:}\quad & \hat{\mathbf x} = \hat{\mathbf x}^- + \mathbf K(\mathbf z - \mathbf H\hat{\mathbf x}^-),\qquad \mathbf P = (\mathbf I - \mathbf K\mathbf H)\mathbf P^- \end{aligned}

Small R\mathbf R (trusted sensor) → big correction; big Q\mathbf Q (untrusted model) → fast adaptation. ArduPilot's EKF3 and PX4's EKF2 are extended Kalman filters fusing IMU + mag + baro + GNSS (+ optical flow, rangefinder, vision) into position, velocity and attitude — the attitude kept as a quaternion to avoid gimbal lock (Module 12).

⚫ Master. You characterize a gyro with Allan variance (separating white noise from bias instability), tune EKF noise matrices from logs instead of copying defaults, understand observability (why yaw is unobservable without mag or motion), and can implement a working EKF yourself against simulated data.

Mastery checklist

  • Implement a complementary filter on any microcontroller and demo stable angles.
  • Read an EKF innovation log and say which sensor is failing.
  • Explain aliasing with a drawn sine wave and why it forces gyro filtering.

🖼️ Image ideas: macro photo of your FC's IMU chip; Wikimedia Commons "Kalman filter" block diagrams (several PD).

📚 Free resources: "Kalman and Bayesian Filters in Python" by R. Labbe (free, CC-licensed book — the single best resource); ArduPilot EKF documentation; PX4 ECL/EKF docs.