Control: PID, LQR and Geometric Control

A steady 1 N wind hits a hovering drone. With no feedback it is 4.5 m away three seconds later. Proportional feedback alone swings wider each time. Add damping and it holds, 0.25 m off. Add an integral and it comes back to 0.00 m.

Pick a controller, set the wind, and press Play. Watch the teal drone tilt into the pink wind. Then we build, piece by piece, state space and poles, PD and PID, LQR, the rotor mixer, flatness, the cascade and attitude control on SO(3).

You need Lectures 1 and 2 (rotation matrices, RWB, the hat map), F = ma and a little Python. We build the rest from zero.

Lecture 3 of 14 in our follow-along of MIT 16.485, Visual Navigation for Autonomous Vehicles (VNAV, taught by Luca Carlone). Every idea is re-taught here in our own words and devices. Previous: Lecture 2, Lie groups. Next: Lecture 4, trajectory optimisation.

Hold a drone in the wind

1.00 N

Illustrative drone, simulated here: 1 kg, two rotors 0.25 m from the centre, at most 10 N each. The wind starts at 1 s and stays. Outer gains kp = 4, kd = 3, ki = 2; the attitude loop is 10 times faster. Side view: y points into the screen, so a positive pitch looks clockwise.

Chapter 0

The Hovering Problem

Set the thrust from a model and watch a heavier battery pull the drone down

The estimator says where the drone is. The planner says where it should be. Neither one spins a rotor. Control is the part that turns the gap between the two into rotor commands, many times a second.

The simplest plan needs no sensor at all. The drone weighs 1 kg, so the rotors push 9.81 N and it hovers. This is open-loop control: the command comes from the model alone. Now swap in a battery that is 50 g heavier.

Hover with a wrong mass

The controller believes the drone weighs 1 kg. Add mass with the slider, then switch between open loop and feedback. The teal curve is the height; yellow is the target.

50 g

Illustrative 1D model. Feedback here is kp = 4, kd = 3 on the measured height and climb rate (Chapter 2).

Work the number. The rotors still push 9.81 N, but the weight is 1.05 × 9.81 = 10.30 N. The net force is 0.49 N down, so the drone sinks at 0.467 m/s². After 2 s it has fallen 0.93 m, and it keeps going.

Closed-loop control, or feedback, measures the height and pushes back on the gap. The same 50 g now costs 0.12 m of sag, and the drone stops there. The model was wrong in both cases. Feedback did not need it to be right.

Symptom: a drone that hovered on the bench drifts down, or sideways, in the field.

Measure: log thrust and height. A constant command with a changing height means no loop closes on that axis.

Fix: feed the measured state back. Keep the model as a feedforward guess, not as the whole command.

The road

  1. State space: write any system as x-dot = Ax + Bu, and read stability from its poles.
  2. Feedback: PD control places the poles (the hero's P and PD buttons).
  3. PID: the integral removes the sag, and windup is its price (the hero's PID button).
  4. LQR: choose the gains by pricing error against effort.
  5. Dynamics: Newton and Euler for a quadrotor, and the mixer from rotor speeds to force and torque.
  6. Flatness: why a quadrotor must tilt to move, and how an acceleration fixes the attitude.
  7. Cascade: a slow position loop on top of a fast attitude loop.
  8. SO(3): the geometric attitude error of Lee, Leok and McClamroch.
  9. Showcase: fly the full stack, click a target, add wind.
  10. Field guide: the laws side by side, code, and the credit.
An open-loop drone sets its thrust to 9.81 N for a 1 kg body, but it carries 50 g more. What happens?

Chapter 1

State Space and Stability

Move a pair of poles and watch the response decay, ring or blow up

To predict a system, list the few numbers that fix its future. For the altitude axis they are the height and the climb rate. That list is the state. What we command, here the thrust beyond the weight, is the input.

Near a hover, most robots obey a linear rule. Call the state vector x, the input u, and two fixed matrices A and B.

Say it aloud

X-dot equals A times x, plus B times u.

ẋ
x-dot how fast each state number changes, per second.
A
A the system matrix: how the state drives its own change. n by n for n state numbers.
x
x the state, here (height z, climb rate z-dot).
B
B the input matrix: how the input pushes the state.
u
u the input, here thrust minus weight, in newtons.
In plain words

Multiply the state x by A and the input u by B. Add them. The sum is the velocity of the state, so you can step it forward in time.

With numbers

Altitude axis of a 1 kg drone: A has rows (0, 1) and (0, 0); B is (0, 1). Take x = (2 m, 0.1 m/s) and u = 0.5 N. Then x-dot = (0.1 m/s, 0.5 m/s²): the height rises at 0.1 m/s, and the climb gains 0.5 m/s each second.

With u = 0, every solution is a mix of modes eλt, one for each eigenvalue λ (lambda) of A. Control engineers call them poles. The real part sets growth or decay. The imaginary part sets how fast it rings.

Move the poles

Left: the pole plane, with the purple pair σ ± jω. Right: the response from a kick of 1. Slide the real part across zero and watch the curve turn.

−0.5
2.0

Exact maths: the response is eσt cos ωt.

Work the number for a mass on a spring: 1 kg, stiffness 4 N/m, no friction. A has rows (0, 1) and (−4, 0), so the poles are ±2j: it rings forever at 2 rad/s. Add friction of 4 N·s/m and both poles sit at −2. That is critical damping, the fastest settle with no overshoot.

The hovering drone is worse than the spring. Its altitude A has both poles at exactly 0. Nothing pulls it back, so a climb rate error of 0.1 m/s becomes 1 m of drift in 10 s. The full planar hover is a chain of four integrators, all poles at 0.

Symptom: a "stable" simulation slowly wanders off when you run it longer.

Measure: print the eigenvalues of A, or of the closed loop. Any real part at or above 0 is not asymptotically stable.

Fix: close a loop that moves every pole into the left half.

A system x-dot = Ax has A with rows (−1, 2) and (0, −3). What does the state do from any start?

Chapter 2

Feedback Moves the Poles

Turn two gains and place the poles of a hovering drone

Feedback makes the input a function of the state: u = −Kx, with a gain matrix K. Then x-dot = (A − BK)x. The poles are now the eigenvalues of A − BK, and we choose K.

One number first. Take x-dot = 2x + u, unstable with its pole at +2. Feed back u = −5x and the pole moves to 2 − 5 = −3. From x = 1, after 1 s, x = e−3 = 0.05.

Now the altitude axis, a mass m pushed by u. Call the error e: the height minus the target height. A PD controller pushes back on the error with a gain kp, the spring. It pushes back on the error rate with a gain kd, the damper: u = −kpe − kdė. The closed loop is a spring and a damper we set by hand.

Say it aloud

Omega-n equals the square root of k-p over m. Zeta equals k-d over two times the square root of k-p times m.

ωn
omega-n the natural frequency: how fast the loop responds, in rad/s.
kp
k-p the proportional gain: newtons per metre of error. The spring.
m
m the mass, 1 kg.
ζ
zeta the damping ratio. Below 1 it overshoots, 1 is critical, above 1 it creeps.
kd
k-d the derivative gain: newtons per metre per second of error rate. The damper.
In plain words

The loop m e-double-dot + k-d e-dot + k-p e = 0 is a spring and damper. Its poles are minus zeta omega-n, plus or minus omega-n times the square root of zeta squared minus one. Raise k-p for speed; raise k-d for damping.

With numbers

m = 1 kg, kp = 4, kd = 2: ωn = 2 rad/s and ζ = 0.5. The poles are −1 ± 1.73j. A 1 m step overshoots by e−πζ/√(1−ζ²) = 16.3%, and settles within 2% after about 4/(ζωn) = 4.0 s.

Tune a PD loop

The drone must climb 1 m. The teal curve is its height; the small panel shows the purple poles. Set kd to 0 to see the hero's P button.

4.0
2.00

Exact maths on a 1 kg double integrator, simulated with a 1 ms step. No actuator limit here.

The simulation agrees: the peak is 1.163 m at 1.81 s, and the height stays within 2% after 4.04 s. Set kd = 4 and ζ = 1: no overshoot.

Symptom: the drone rings around the target and takes long to settle.

Measure: overshoot and settling time of a step. Overshoot above about 20% means ζ below 0.45.

Fix: raise kd until ζ is near 0.7. Raise kp only for speed.

For x-dot = 3x + u with feedback u = −kx, which gains make the loop stable?

Chapter 3

The Integral Term and Windup

Remove a steady sag with memory, then hold the drone down and watch the memory overflow

Back to the heavy battery. A PD loop settles where the spring force kpe balances the missing 0.49 N. With kp = 4 that is 0.12 m low, the sag from Chapter 0. A stiffer spring shrinks it but never removes it.

The fix is memory. Add up the error over time, the integral ∫e dt, and push back on that too. While any sag remains, the sum keeps growing, so the push keeps growing. It stops only when the error is zero.

Say it aloud

U equals minus k-p e, minus k-i times the integral of e d-t, minus k-d e-dot.

u
u the command: thrust beyond the weight, in newtons for this 1 kg drone.
kp
k-p proportional gain, the stiffness: 9 here.
e
e the error: height minus target height, in metres. Negative means too low.
ki
k-i integral gain, the memory: 2 here.
∫e dt
the integral of e d-t the running sum of the error times time, in metre-seconds.
kd
k-d derivative gain, the damping: 5 here.
ė
e-dot how fast the error changes, in m/s.
In plain words

Each tick, add e times the time step to the running sum. Multiply the error, the sum and the error rate by their gains. Add the three and flip the sign: that is the command u.

With numbers

With made-up numbers: the drone is 1 m low, so e = −1, e-dot = 0, and the sum is −0.4 m·s. Then u = 9 × 1 + 2 × 0.4 + 5 × 0 = 9.8 N of extra thrust, with 0.8 N of it from memory.

Memory has a price. Suppose the drone sits on the ground for 3 s while the target is 2 m up. The rotors hit their limit, but the sum keeps growing. On release, that stored push throws the drone far past the target. This is integrator windup.

Hold it down, then let go

A hand holds the 50 g heavy drone on the ground for the first 3 s. The warm curve is the command, clipped at the rotor limit. Toggle the integral and anti-windup.

Illustrative 1D model: kp = 9, ki = 2, kd = 5, command limited to ±9.81 N beyond the weight. Anti-windup here stops adding to the sum while the limit clips the command and the error pushes the same way.

Work the numbers from the device. Without the integral, the drone stops 0.05 m low (0.49 N / 9). With it, but no guard, the sum reaches 6.9 m·s and the drone peaks at 3.40 m, 1.4 m too high. With anti-windup the peak is 2.15 m.

Symptom: after takeoff, a long climb or a stuck gimbal, the vehicle overshoots far more than in step tests.

Measure: log the integral state next to the clipped command. A sum that grows while the command sits at its limit is windup.

Fix: stop integrating while saturated, and clamp the sum to what the actuator can use.

When is integrator windup worst?

Chapter 4

LQR: Price the Error, Price the Effort

Slide one price ratio and let the Riccati equation choose every gain

Two gains are easy to tune by hand. A drone's full state has 12 numbers and 4 inputs, so K has 48 entries. The linear quadratic regulator (LQR) chooses all of them at once. You state what errors and effort cost, and it finds the cheapest K.

Call the price of state error a matrix Q and the price of effort a matrix R. LQR adds both costs over all future time.

Say it aloud

J equals the integral from zero to infinity of x-transpose Q x, plus u-transpose R u, d-t.

J
J the total cost of one run. Smaller is better.
∫0∞ … dt
the integral from zero to infinity add the cost at every instant, forever.
x⊤Qx
x-transpose Q x the state cost. With Q diagonal it is each state number squared, times its price.
u⊤Ru
u-transpose R u the effort cost: each input squared, times its price.
In plain words

At each instant, square the errors and weight them by Q. Square the inputs and weight them by R. Add the two and sum over the whole run. That total is J.

With numbers

Scalar case x-dot = u, Q = R = 1, start at x = 1, gain K. Then x = e−Kt, u = −Kx, and J = (1 + K²)/(2K). K = 0.5 gives 1.25; K = 1 gives 1.00; K = 3 gives 1.67. Too gentle pays in error; too hard pays in effort.

The best K comes from one matrix equation. Call its solution P, a symmetric matrix that prices each starting state.

Say it aloud

K equals R-inverse B-transpose P, where A-transpose P plus P A, minus P B R-inverse B-transpose P, plus Q, equals zero.

K
K the optimal gain; the controller is u = −Kx.
R−1
R-inverse one over the effort price: cheap effort means big gains.
B, B⊤
B, B-transpose the input matrix from Chapter 1.
P
P the Riccati solution. The best cost from a start x0 is x0⊤Px0.
A⊤P + PA
A-transpose P plus P A how the free motion changes the cost.
Q
Q the state price.
In plain words

Solve the second equation, the algebraic Riccati equation, for the P that is positive definite. Then multiply R-inverse, B-transpose and P to get K. SciPy does the solve: solve_continuous_are(A, B, Q, R).

With numbers

Scalar case: A = 0, B = Q = R = 1, so the equation is −P² + 1 = 0 and P = 1. Then K = 1, the minimum of the table above, and the best cost is P x0² = 1.00.

Slide the price of error

The drone starts 1 m above the target. Teal is the height; warm is the thrust. The bar splits the cost into error and effort. Slide right to make error expensive.

10

Exact maths: 1 kg double integrator, Q = diag(q, 0), R = r, gains from the closed form of the Riccati equation, checked against SciPy.

Work the number at q/r = 10. The gains are kp = 3.16 and kd = 2.51, and the best cost is 7.95. Three quarters is error and one quarter effort, at every ratio. For this drone LQR always picks ζ = 0.707.

Symptom: an LQR design saturates the motors on the first gust.

Measure: the peak of u in simulation against the actuator limit.

Fix: raise R, or lower Q on the states that matter less, and re-solve.

You double Q and keep R fixed. What happens to the LQR gain?

Chapter 5

Quadrotor Dynamics and the Mixer

Write Newton and Euler for the drone, then turn force and torque into four rotor speeds

Now the real vehicle, with attitude R = RWB and position p, as in Lecture 1. The body frame is forward, left, up. Every rotor pushes along body z, so the total thrust is one number f along R e3.

Call gravity g, the mass m and the inertia matrix J. Call the body turn rate ω (the gyro reading, ωB in Lecture 2) and the body torque τ.

Say it aloud

M p-double-dot equals minus m g e-3, plus f R e-3. J omega-dot equals minus omega cross J omega, plus tau.

m
m the mass, 1 kg.
p̈
p-double-dot the acceleration, in world numbers, m/s².
g e3
g e-3 gravity, 9.81 m/s², times the world up axis (0, 0, 1).
f
f the total thrust of the four rotors, in newtons.
R e3
R e-3 the body z axis in world numbers: where the thrust points.
J
J the 3 by 3 inertia matrix in the body, here diag(0.01, 0.01, 0.018) kg·m².
ω̇
omega-dot the angular acceleration in the body, rad/s².
ω × Jω
omega cross J omega the gyroscopic term: a spinning body resists a change of axis.
τ
tau the torque from the rotors, in the body, N·m.
In plain words

In world numbers, gravity pulls down and the thrust f pushes along R e-3. In body numbers, the torque tau turns the body, less the gyroscopic term. The attitude then moves by R-dot = R omega-hat.

With numbers

Hover thrust f = 9.81 N, pitched 10°. Sideways: 9.81 × sin 10° = 1.70 m/s². Up: 9.81 × cos 10° − 9.81 = −0.15 m/s², so it also sinks. A pitch torque of 0.05 N·m on Jy = 0.01 gives 5 rad/s².

Rotor i spins at Ωi (capital omega i, rad/s). It gives a thrust cfΩi² (cf = 10−5 N·s²) and a drag torque cdΩi² (cd = 10−6 N·m·s²) against its spin. Rotors 1 to 4 sit front, left, back and right, L = 0.25 m out. Rotors 1 and 3 spin clockwise from above.

Say it aloud

The vector f, tau-x, tau-y, tau-z equals the mixer matrix times the vector of the four rotor speeds squared.

(f, τx, τy, τz)
f, tau-x, tau-y, tau-z total thrust, then roll, pitch and yaw torque in the body.
[ 4 × 4 ]
the mixer matrix row 1 adds the thrusts. Rows 2 and 3 are arm times thrust. Row 4 adds the drag twists, with alternating signs.
Ωi²
capital omega i squared rotor i's speed squared, in (rad/s)².
In plain words

A faster left rotor rolls the right side down; a faster back rotor pitches the nose down. Ask for f and tau, multiply by the inverse matrix, and take square roots. That inverse is the mixer, or control allocation.

With numbers

Hover: each rotor gives 9.81/4 = 2.45 N, so Ω = √(2.45/10−5) = 495.2 rad/s, 4,729 rpm. Add a roll torque of 0.05 N·m: Ω2² − Ω4² = 0.05/(0.25 × 10−5) = 20,000. Rotor 2 goes to 505.2 rad/s and rotor 4 to 485.0.

Mix four rotors

Top view, nose up the screen. Ask for a thrust and torques; the warm discs and bars show each rotor's speed. Push a torque far and one rotor runs out of range.

9.8 N
0.050 N·m
0.000 N·m
0.00 N·m

Illustrative constants cf = 10−5, cd = 10−6, L = 0.25 m, top speed 1,000 rad/s (10 N per rotor). Exact maths.

Symptom: the drone yaws when it should roll, or flips on takeoff.

Measure: command a small roll torque on the bench and check which rotors speed up.

Fix: match the mixer to the real rotor positions and spin directions. One swapped sign flips a row.

The drone must roll with 0.05 N·m at hover. Which rotors change?

Chapter 6

Underactuation and Differential Flatness

Drag an acceleration and watch the attitude and thrust it forces

Six degrees of freedom, four inputs: we call the quadrotor underactuated. It cannot push sideways while level. To go forward, it tilts the thrust forward. So position and attitude move together.

The tie runs the useful way. Pick the acceleration you want, ad. The thrust must supply ad plus the weight, so that one vector fixes both the thrust size and the direction of body z.

Say it aloud

F equals m times the norm of a-d plus g e-3. Z-B-d equals a-d plus g e-3, over its norm.

f
f the thrust size the motion needs, in newtons.
m
m the mass, 1 kg.
ad + g e3
a-d plus g e-3 the wanted acceleration plus 9.81 up: what the thrust alone must supply. ‖ ‖ is its length.
zB,d
z-B-d the desired body z axis, a unit vector in world numbers.
In plain words

Add 9.81 m/s² up to the wanted acceleration a-d. Its length times m is the thrust f. Its direction is where body z must point. A wanted yaw ψ then fixes the other two axes. They lie square to zB,d, with xB as close as it can get to the heading (cos ψ, sin ψ, 0).

With numbers

ad = (2, 0, 0) m/s²: the vector is (2, 0, 9.81), length 10.01. So f = 10.01 N and body z tilts forward by atan(2/9.81) = 11.5°. With ψ = 0, Rd has columns (0.980, 0, −0.200), (0, 1, 0) and (0.200, 0, 0.980).

Ask for an acceleration

Side view. Yellow is the acceleration you ask for; pink is gravity; warm is the thrust the drone must make. The drone tilts to match. Ask to fall faster than gravity and see what breaks.

2.0 m/s²
0.0 m/s²

Exact maths, 1 kg, thrust limit 20 N (two rotors in this side view).

Mellinger and Kumar (ICRA 2011) turned this into a design rule. Position x, y, z and yaw ψ are flat outputs: from them and their derivatives you can rebuild every state and input. The attitude needs the acceleration, the body rate needs the jerk (the rate of acceleration), and the torque needs the snap (the rate of jerk).

Work the rate. At ad = (2, 0, 0), raise the forward acceleration by 1 m/s² each second. The pitch rate must be 0.098 rad/s, 5.6°/s. A path with a jump in jerk asks for a jump in body rate, which needs an infinite torque. That is why Lecture 4 builds smooth, minimum-snap paths.

Symptom: the drone drops or flips when asked to dive fast.

Measure: the vertical part of ad + g e3. At or below zero, the thrust would have to point down.

Fix: limit downward acceleration to well under g, and cap the tilt.

The drone must accelerate left in the world while it faces forward. What must it do?

Chapter 7

Cascaded Control: A Slow Loop on a Fast One

Slow the attitude loop down and watch the position loop lose its footing

The full controller is two loops. The outer position loop turns the position error into a desired force, so a thrust and a desired attitude Rd. The inner attitude loop turns Rd into torques. The mixer turns those into rotor speeds.

Call the position error ex = p − pd and the velocity error ev = v − vd. The outer loop is PD plus two known terms.

Say it aloud

F equals minus k-x e-x, minus k-v e-v, plus m g e-3, plus m a-d. Little f equals F dot R e-3.

F
capital F the force the drone should make, in world numbers. Its direction becomes zB,d.
kx ex
k-x e-x the spring: gain 4 N/m times the position error.
kv ev
k-v e-v the damper: gain 3 N·s/m times the velocity error.
m g e3
m g e-3 cancels the weight before it causes an error.
m ad
m a-d feedforward: the push the planned path needs anyway.
f
little f the thrust we command, in newtons.
R e3
R e-3 where body z points now.
In plain words

Build F from the two errors, the weight and the planned acceleration. Point body z along F by sending Rd to the inner loop (Chapter 6 adds the yaw). Command only the part of F along the current body z: if the drone has not tilted yet, it does not shove the wrong way.

With numbers

A gust left the drone 0.5 m forward of its target, at rest: ex = (0.5, 0, 0). F = (−2, 0, 9.81), so Rd tilts 11.5° back. While still level, f = F · (0, 0, 1) = 9.81 N; once tilted, f = 10.01 N.

This works only if the inner loop is much faster. The outer loop assumes the drone reaches Rd at once. If the attitude lags, the position loop pushes on a tilt that is not there yet.

Slow the inner loop

The drone steps 1 m forward. Teal is its position; the lower trace is its tilt. The slider sets how much faster the attitude loop is than the position loop.

10×

Illustrative planar drone from the hero: outer ωn = 2 rad/s (kx = 4, kv = 3); inner loop ζ = 0.7 at the chosen speed; rotor limits on. Nonlinear simulation, 0.5 ms step.

Work the boundary. Linearise the planar loop. Its poles cross into the right half when the attitude loop is only 2.0 times faster (4.0 rad/s against 2). At 3× it overshoots 12%. At 5× and above it behaves like the ideal PD, 1.02 to 1.03 m peak.

Symptom: raising the position gains makes the drone wobble and then diverge.

Measure: the step-response speed of the attitude loop against the position loop.

Fix: keep the inner loop 5 to 10 times faster. Raise attitude gains first, or lower the position gains.

Why does the position loop output a desired attitude Rd instead of torques?

Chapter 8

Geometric Attitude Control on SO(3)

Track a flip with a rotation-matrix error and watch Euler angles lose it past 90°

The inner loop drives R to Rd. A PD on roll, pitch and yaw differences looks natural, but Lecture 2 showed that Euler angles jump at 90° pitch.

Lee, Leok and McClamroch (CDC 2010) measure the error on SO(3) itself, from the relative rotation Rd⊤R.

Say it aloud

E-R equals one half of R-d-transpose R minus R-transpose R-d, vee. E-omega equals omega minus R-transpose R-d omega-d.

eR
e-R the attitude error, a 3-vector in body numbers. Its length is sin θ for an error angle θ.
Rd⊤R − R⊤Rd
R-d-transpose R minus its transpose twice the skew part of the relative rotation.
∨
vee reads the three numbers of a skew matrix, from Lecture 2.
eω
e-omega the turn-rate error, in body numbers.
ω
omega the body turn rate the gyro reads, rad/s.
R⊤Rdωd
R-transpose R-d omega-d the desired rate ωd, written in the actual body frame.
In plain words

Form R-d-transpose R. If the frames match, its skew part is zero. Otherwise vee of the skew part points along the error axis, length sin θ. Bring the desired rate into the body frame, then subtract.

With numbers

Rd = I and R = Rx(30°): the skew part gives eR = (0.5, 0, 0) = sin 30° along x. At 150° it is also 0.5, and at 180° it is 0: the push fades for errors past 90°.

The torque is a PD on these errors plus two extra terms. Call the attitude gain kR and the rate gain kω.

Say it aloud

Tau equals minus k-R e-R, minus k-omega e-omega, plus omega cross J omega, minus J times omega-hat R-transpose R-d omega-d, minus R-transpose R-d omega-d-dot.

τ
tau the body torque sent to the mixer, N·m.
kR eR
k-R e-R the spring on attitude: 0.4 N·m per unit of eR.
kω eω
k-omega e-omega the damper: 0.08 N·m·s per rad/s of rate error.
ω × Jω
omega cross J omega cancels the gyroscopic term of Chapter 5.
J(…)
J times the bracket feedforward: the torque the desired motion needs, with ω̇d (omega-d-dot) its angular acceleration.
In plain words

Push back on both errors, like a PD. Cancel the gyroscopic term. Add the torque the planned rotation needs, so the PD fixes only what is left.

With numbers

At rest, 30° off in roll, hovering target: τ = −0.4 × (0.5, 0, 0) = (−0.2, 0, 0) N·m. With Jx = 0.01, that is −20 rad/s² back toward level. Near level these gains give ωn = 6.3 rad/s, ζ = 0.63.

Track a flip

The yellow frame flips end over end; the teal drone starts 10° off in roll and must follow. Pick a controller and press Play.

3.0 rad/s

Illustrative rigid body, J = diag(0.01, 0.01, 0.018) kg·m², kR = 0.4, kω = 0.08. Both share the rate and feedforward terms. Exact maths, 1 ms steps on SO(3).

Work the numbers at 3 rad/s. The geometric loop is within 0.1° after 1.5 s. Euler PD tracks until the desired pitch passes 90°. Then the desired yaw and roll jump by 180°, the error jumps, and the drone ends up to 180° off.

Lee et al. prove the attitude loop exponentially stable for any start error under 180°, given a bound on the start rate. With the position loop on top: exponentially stable under 90°, exponentially attractive under 180°. This is their "almost global". No smooth feedback on SO(3) can include every start.

Symptom: an aggressive manoeuvre goes wild as the nose passes vertical.

Measure: plot the Euler angles of Rd. Look for 180° jumps in yaw and roll near 90° pitch.

Fix: compute the error on SO(3) with eR. Keep Euler angles for display.

Why does the geometric controller use eR = ½(Rd⊤R − R⊤Rd)∨ and not Euler angle differences?

Chapter 9

Showcase: Fly the Whole Stack

Click a target and watch an error become a tilt, a torque and two rotor speeds

Here is every piece at once, in the side view of the hero. The position loop of Chapter 7 builds F from the error. Its direction becomes the desired tilt. The attitude loop turns the tilt error into a torque. The mixer of Chapter 5 splits thrust and torque between the front and back rotors.

Nothing commands the tilt directly. Click to the right and watch the drone first lean right, then brake by leaning left. The yellow line is the position error. The thin yellow tick on the drone is Rd, the tilt the outer loop asks for.

Click a target, add wind

Click or tap anywhere on the scene to move the yellow target. The warm bars are the front and back rotor thrusts; they turn red at their limit.

4.0
10×
0.00 N

Illustrative planar drone: 1 kg, Jy = 0.01 kg·m², arms 0.25 m, 10 N per rotor. We set kv for ζ = 0.75 at each kx. ki = 2, summed only within 0.5 m of the target. Attitude loop ζ = 0.7. Real time, 1 ms steps.

Try three things. Set the wind to 2 N with the integral off. The drone hangs 0.5 m downwind: 2 N over kx = 4, as in Chapter 3. Turn the integral on and it walks back. Then drop the inner speed to 2× and click across the screen: the cascade of Chapter 7 wobbles and never settles.

Push kx to 12 and click far away. The thrust bars turn red: the rotors saturate, and the clean PD numbers stop holding. Real flight stacks cap the tilt and the acceleration for exactly this reason.

Chapter 10

Field Guide

Keep the laws, the conventions and the code side by side

Feedback beats a model alone because it measures. A linear system's poles say whether it settles; feedback moves them. PD places a spring and a damper, the integral removes steady sag at the risk of windup, and LQR picks all gains from two prices. A quadrotor has one thrust and three torques, so it tilts to move. The position loop asks for a force, and the force fixes thrust and attitude. A faster loop tracks that attitude on SO(3), and the mixer sets the rotor speeds.

PieceLawNumber on this pageWatch out
Stabilityall poles of A − BK in the left halfhover: 4 poles at 0a pole at 0 drifts
PDωn = √(kp/m), ζ = kd/(2√(kpm))kp 4, kd 2: 16.3% overshootsteady sag d/kp
PIDu = −kpe − ki∫e − kdėwindup peak 3.40 m vs 2.15 m guardedguard the integral
Tuning startZiegler-Nichols: kp = 0.6Ku, ki = 1.2Ku/Tu, kd = 0.075KuTuKu, Tu: gain and period at steady ringinga starting point, retune on hardware
LQRK = R−1B⊤P, Riccati for Pq/r 10: K = (3.16, 2.51)check the peak input
Mixer(f, τ) = M (Ωi²)hover 495.2 rad/srotor order and spin signs
Flatnessf = m‖ad + g e3‖, zB,d along it2 m/s² forward: 11.5°, 10.01 Njerk sets body rate, snap sets torque
CascadeF = −kxex − kvev + mg e3 + m adunstable below 2× inner speedkeep 5 to 10×
AttitudeeR = ½(Rd⊤R − R⊤Rd)∨30° roll: eR = (0.5, 0, 0)|eR| = sin θ, weak near 180°

The conventions on this page

The core, as code

python
import numpy as np
from scipy.linalg import solve_continuous_are

def hat(v): return np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
def vee(M): return np.array([M[2, 1], M[0, 2], M[1, 0]])
g, m = 9.81, 1.0
J = np.diag([0.01, 0.01, 0.018])

class PID:                                     # e = measured - target
    def __init__(s, kp, ki, kd, umax): s.k = (kp, ki, kd); s.umax = umax; s.I = 0.0
    def step(s, e, edot, dt):
        kp, ki, kd = s.k
        u_raw = -kp*e - ki*s.I - kd*edot
        u = np.clip(u_raw, -s.umax, s.umax)
        if u == u_raw or np.sign(e) == np.sign(u_raw):   # anti-windup: no sum that deepens the clip
            s.I += e*dt
        return u

# LQR on the altitude axis
A = np.array([[0., 1], [0, 0]]); B = np.array([[0.], [1/m]])
P = solve_continuous_are(A, B, np.diag([10., 0]), np.array([[1.]]))
print((B.T @ P).ravel())                         # [3.1623 2.5149]

# mixer: rotors front, left, back, right; 1 and 3 clockwise
cf, cd, L = 1e-5, 1e-6, 0.25
Mix = np.array([[cf, cf, cf, cf], [0, L*cf, 0, -L*cf], [-L*cf, 0, L*cf, 0], [cd, -cd, cd, -cd]])
def rotor_speeds(f, tau): return np.sqrt(np.linalg.solve(Mix, np.r_[f, tau]))
print(rotor_speeds(m*g, [0.05, 0, 0]))           # [495.2 505.2 495.2 485.0]

def position_loop(p, v, pd, vd, ad, psi, R, kx=4., kv=3.):
    F = -kx*(p - pd) - kv*(v - vd) + m*g*np.array([0, 0, 1]) + m*ad
    zb = F/np.linalg.norm(F)                          # desired body z
    xc = np.array([np.cos(psi), np.sin(psi), 0])
    yb = np.cross(zb, xc); yb /= np.linalg.norm(yb); xb = np.cross(yb, zb)
    return F @ R[:, 2], np.column_stack([xb, yb, zb])   # thrust f, R_d

def attitude_loop(R, w, Rd, wd, wd_dot, kR=0.4, kw=0.08):   # Lee, Leok, McClamroch 2010
    eR = 0.5*vee(Rd.T @ R - R.T @ Rd)
    ew = w - R.T @ Rd @ wd
    return -kR*eR - kw*ew + np.cross(w, J @ w) - J @ (hat(w) @ R.T @ Rd @ wd - R.T @ Rd @ wd_dot)

f, Rd = position_loop(np.array([0.5, 0, 0]), np.zeros(3), np.zeros(3), np.zeros(3), np.zeros(3), 0., np.eye(3))
print(f, np.degrees(np.arccos(Rd[2, 2])))              # 9.81 N while level, tilt 11.5 deg

Where it sits

This lecture closes the loop on the state the rest of the series estimates. Lecture 4, trajectory optimisation, supplies pd, vd, ad and ψd as smooth minimum-snap paths, the flat outputs this controller needs. The estimators of later lectures supply p, v, R and ω.

Keep going

The takeaway. Measure and push back. Place the poles with PD, remove sag with a guarded integral, and let LQR price the rest. A quadrotor moves by tilting, so a slow position loop asks for a force and a fast loop on SO(3) delivers the attitude.

Now press Present or Teach. Explain from memory why open loop sinks, how kp and kd set ζ, why the integral winds up, and what Q and R trade. Derive the mixer, the thrust and tilt from an acceleration, and eR for a 30° roll. Then go back to the hero and say why each button ends where it does.

Credit

VNAV Lecture 3: Control, PID, LQR and Geometric Control
MIT 16.485 VNAV · Previous: Lie groups · Next: trajectory optimisation · Back to Gleams