Skip to main content

Module 4 — Control theory & the steering/flight controller

The reason a quad — an unstable system by nature — feels locked-in is a 60-year-old algorithm running very, very fast.

🟢 Foundations. Open loop: command and hope. Closed loop: measure the error e=setpointmeasuremente = \text{setpoint} - \text{measurement} and push against it. The workhorse is PID:

u(t)=Kpe(t)+Ki ⁣0tedτ+Kddedtu(t) = K_p\,e(t) + K_i\!\int_0^t e\,d\tau + K_d\,\frac{de}{dt}

  • P is the spring — pushes proportionally to error. Too much → oscillation.
  • I is the memory — removes steady offset (wind, unbalanced frame). Too much → slow wallowing, windup.
  • D is the damper — resists rate of change, adds braking. Too much → amplifies noise, hot motors.

In your quad this runs on rotation rate, thousands of times per second: stick position = desired °/s, gyro = actual °/s.

🟡 Practitioner. Real firmware uses the discrete form, with two production details: the derivative is taken on the measurement (so stick steps don't spike D) and the integrator is clamped (anti-windup):

float pid_step(float sp, float meas, float dt) {
float e = sp - meas;
integ += Ki * e * dt;
integ = clamp(integ, -I_MAX, I_MAX); // anti-windup
float d = -(meas - meas_prev) / dt; // derivative on measurement
meas_prev = meas;
return Kp * e + integ + Kd * d; // (+ feedforward, see below)
}

Modern firmwares add feedforward — a term proportional to the setpoint's rate of change, so the quad starts responding before error even builds. Control is cascaded: outer loops output setpoints for inner, faster loops:

Acro mode = rate loop only. Angle mode adds the angle loop. GPS modes stack all of them.

🔴 Advanced. Move to the frequency domain. A second-order closed loop behaves like a mass–spring–damper with natural frequency ωn\omega_n and damping ratio ζ\zeta; step-response overshoot is

Mp=eπζ/1ζ2M_p = e^{-\pi\zeta/\sqrt{1-\zeta^2}}

(ζ=0.7\zeta = 0.7 → ≈ 4.6 % overshoot — the "crisp but not bouncy" feel). Learn transfer functions, Bode plots, and gain/phase margin: every filter you add (Module 9) delays the signal, eats phase margin, and pushes the loop toward oscillation — the deepest tradeoff in quad tuning. Understand why D-term is a differentiator and thus a high-pass amplifier of noise.

⚫ Master. Beyond PID: LQR (optimal state feedback), MPC (optimize a trajectory over a horizon each step), and INDI — incremental nonlinear dynamic inversion, which uses measured angular acceleration to cancel model error and powers modern autonomous drone-racing research. You perform system identification on your own quad (inject a frequency sweep, fit a transfer function from the blackbox) and design gains instead of guessing them.

Mastery checklist

  • Predict, before flying, what doubling D does to noise and to propwash handling — and be right.
  • Sketch the Bode consequence of adding a 100 Hz lowpass to the D-term.
  • Implement rate-mode PID on a microcontroller and stabilize a bench gimbal with it.

🖼️ Image ideas: your own blackbox step-response screenshots; Wikimedia Commons "PID controller" block diagrams (PD versions exist).

📚 Free resources: Brian Douglas "Control System Lectures" (YouTube); Betaflight docs "PID tuning"; ArduPilot dev docs on attitude control; MIT OCW 6.302.