Capstone: Quadrotor Altitude
Four spinning blades, one number to hold, and gravity pulling the whole time
A quadcopter hovering in place looks effortless, a calm machine resting on nothing. It is the exact opposite. It is falling continuously, and a controller is catching it dozens of times a second by trimming four rotors against gravity. Stop the math for a heartbeat and it drops out of the sky.
This is the capstone for the control chapter, because a quadrotor is everything you've learned wired into one twitchy little aircraft. Holding altitude is the simplest job it has, and even that is pure PID: measure how high you are, compare it to where you want to be, and turn the gap into thrust. The catch is that gravity never stops pulling, so the loop never gets to rest.
Fly it yourself
Below is a side-view quadrotor that bobs in real time as its controller fights to hold 1.0 m. The dashed line is the setpoint. Tune the three gains, hang a heavier payload on it, and slam it with a wind gust to see what survives.
Hover at 1.0 m, gust-resistant
what to try
- Drop Kd to zero. The drone oscillates around the setpoint with no damping: overshoot becomes the next undershoot, forever. This is the double-integrator failure mode P alone can't fix. Bring Kd back to ~3.
- Crank Kp to 18 with Kd = 0. Same problem, but faster: the drone violently oscillates. P-gain determines speed; D-gain determines whether you survive the ride.
- Trigger the wind gust mid-flight. A downward push lasting 0.3s. Without Ki, a steady wind would leave a permanent offset; the integrator kills it. Try Ki = 0 vs Ki = 3 with the gust active.
- Hang a 2 kg payload (mass slider all the way right). The controller was tuned for 1 kg; suddenly the plant is twice as sluggish. Same lesson as Lesson 01: gains tuned for a nominal plant degrade as the real plant deviates.
Watch the drone, not just the trace. With sensible gains it rises, maybe overshoots once, and parks on the dashed line. Now sabotage it: drag Kd to zero and it bounces around the setpoint forever: every overshoot becomes the next undershoot, with nothing to damp the swing. That is the failure mode at the heart of this lesson, and proportional gain alone cannot fix it. You need the derivative term to act as a brake.
Three terms, three jobs, just like the first lesson in this chapter:
- P, proportional. The further the drone is from
1.0 m, the harder it pushes. P sets how fast you climb. Crank it up alone and the drone rockets to the line and blows straight past it. - D, derivative. Reacts to how fast altitude is changing, and brakes before you arrive. D is what turns a violent oscillation into a clean approach. P decides your speed; D decides whether you survive it.
- I, integral. Sums up the lingering error over time. Gravity is a constant downward pull, so a pure P+D controller would hover slightly below the target forever. The integral term is what quietly trims the steady hover thrust and erases that offset.
Why gravity makes the integrator earn its keep
In the PID lesson the integral term was the cleanup crew that mopped up small leftover errors. Here it is doing real, constant labor. Hover is not a state of "no force needed"; it is a state of "exactly enough upward thrust to cancel weight, applied nonstop." P and D both go quiet once the drone is sitting still on the setpoint, because the error and its rate are both zero. Something has to keep commanding that hover thrust, and that something is the integrator: it has accumulated exactly the constant push that balances m g.
Turn the payload slider up and you can feel this directly. The controller was tuned for a 1 kg craft; bolt on a heavy GoPro and the same gains suddenly drive a sluggish, heavier aircraft. It sags, then slowly climbs back as the integrator winds up to find the new, larger hover thrust. The control law didn't change; the world did.
The math: a double integrator and where the gust enters
Strip away the four rotors and altitude obeys Newton's second law: total thrust fights weight :
This is a double integrator: thrust sets acceleration, you integrate once to get velocity, again to get altitude. Two integrators in series means two poles sitting at the origin: the marginal case. That is precisely why proportional gain alone cannot stabilize it: with no damping, P just trades position error for velocity and the drone oscillates forever. The derivative term supplies the missing damping.
Let the controller command the rotor thrust directly, , with no gravity feedforward, so the loop itself has to discover how much thrust hover needs. Close it on the altitude error with the three-term law:
so substituting into gives the plant the controller actually drives:
where is the wind-gust disturbance (a sharp downward shove for a fraction of a second) and is the relentless constant pull underneath everything. The demo integrates this by forward-Euler at . Two things fall out of the algebra. First, the payload slider scales the thrust and disturbance terms by : double the mass and the same gains push half as hard, which is why a heavy craft turns sluggish. Second, and this is the whole reason a quadrotor is the chapter's capstone, at hover , so and both vanish, yet the plant still needs a steady just to hang in the air. Only the term can produce a nonzero output at zero error, so it is mathematically the only term that can hold that constant hover thrust. Switch it off and the drone settles wherever the leftover proportional error balances the weight, permanently below the line.
Key takeaways
- Hovering is active falling: the controller must command a constant upward thrust nonstop, because gravity is a constant disturbance that never relents.
- Altitude is a double integrator, so P alone cannot stabilize it: you need Kd for damping or the drone oscillates forever.
- The integral term trims the steady hover thrust; it is the only term that holds a constant force against a constant load like gravity or a steady wind.
- Real drones nest a fast inner attitude loop inside a slower outer position loop (cascaded control), and this demo is just that outer loop.
A quadrotor is the whole chapter in miniature. Proportional for speed, derivative for the brake, integral for the patient bookkeeping that cancels gravity: three numbers cooperating dozens of times a second to keep a machine suspended on nothing.
It steered a battleship in 1922 and it holds your drone in the air today. The plant keeps changing; the loop does not.