D3 · Lesson 3 · PID control and tuning
The proportional, integral and derivative terms and what each does, a drone holding altitude as a mass under PD control with its natural frequency and damping, overshoot and settling, the integral term that removes steady droop, and Ziegler–Nichols tuning
More than nine in ten industrial control loops are PID controllers: three terms, three knobs. The proportional term pushes in proportion to the error, the integral term keeps pushing harder for as long as any error remains, and the derivative term brakes when the error is changing fast. A quadcopter holding its altitude is a good place to see them work, because the drone is a mass with almost no friction: thrust accelerates it, and without the derivative term it would bounce up and down forever around its setpoint.
- A 1.2 kg drone told to climb 1 m. Its altitude controller adds thrust to the hover thrust: proportional to the height error, minus a damping term proportional to the climb rate.
- The drone behaves as a mass on a spring () with a damper (): natural frequency , damping ratio .
- Too little and it overshoots and bounces; too much and it creeps up slowly. ζ around 0.7 is a common compromise.
Predict
With = 4.8 N/m and = 2.4 N·s/m, the 1.2 kg drone has ζ = 0.5. By how much does it overshoot a 1 m climb?
A second-order system overshoots by of the step: = 0.163, or 16 cm. Raising to 3.36 N·s/m gives ζ = 0.7 and an overshoot of only 4.6%.
Name it
The three terms
- Proportional: reacts to the present error. More responds faster but, on a plant like the drone, oscillates more.
- Integral: reacts to accumulated past error, so it keeps growing until the error is zero. It removes steady-state error (lesson 2) but adds overshoot and can wind up when the actuator saturates.
- Derivative: reacts to the error's rate of change, a prediction of where it's heading, which adds damping. It amplifies sensor noise, so it's filtered, and it's often applied to the measurement instead of the error to avoid a jolt when the setpoint jumps.
The drone
With mass m, PD control on the altitude gives , a second-order system with
overshoot and a 2% settling time of about .
A constant disturbance force , such as thrust lost as the battery sags, leaves a steady altitude error of under PD control. Adding the integral term drives it to zero.
Ziegler–Nichols tuning
Raise alone until the loop oscillates steadily. That ultimate gain and the oscillation's period give a starting point:
with and . The result is aggressive, with about 25% overshoot, and is usually softened by hand.
Worked example
The drone's battery sags and it loses 0.24 N of thrust. Under PD control with = 4.8 N/m, how far does it sink? What fixes it?
Show the solution
- How far it sinks.
- The fix. An integral term keeps adding thrust while any error remains, so it settles back at the setpoint.
Answer it sinks 0.05 m, and an integral term brings it back to the setpoint.
Worked example
A loop oscillates steadily at = 10 with period 2 s. What PID gains does Ziegler–Nichols suggest?
Show the solution
- Proportional gain.
- Integral gain. so s⁻¹.
- Derivative gain. so s.
Answer = 6, = 6 s⁻¹ and = 1.5 s.
Worked example
The sagging drone sits 0.05 m low when an integral term with = 6 N/(m·s) is switched on. At first, how fast does the integral's force grow, and roughly how long until it makes up the lost 0.24 N?
Show the solution
- How fast the force grows.
- Time to make up 0.24 N. If the error stayed put:
- What really happens. The drone rises as the force builds, the error shrinks, and the last of the correction comes more slowly.
Answer the integral's force grows at 0.3 N/s at first, so it makes up the 0.24 N in roughly 0.8 s.
Check
A 1.2 kg drone's altitude loop has = 2 N/m. What's its natural frequency?
Write units the way you normally would: 1.5 rad/s and 1500 mrad/s are the same answer.
Check
The same drone (1.2 kg, = 2 N/m) has = 2.5 N·s/m. What's its damping ratio?
Check
A second-order loop has damping ratio 0.4. By what percentage does it overshoot a step?
Check
A disturbance force of 0.3 N acts on a drone under PD altitude control with = 2 N/m. How far does it settle from its setpoint?
Write units the way you normally would: 1.5 cm, 15 mm and 0.015 m are the same answer.
Check
A loop oscillates steadily at an ultimate gain of 10 with period 0.5 s. What derivative gain does Ziegler–Nichols suggest?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A PD-controlled drone with = 2 N/m loses 0.24 N of thrust; then an integral term with = 6 N/(m·s) is added.
(a)
How far does it sink under PD alone?
Write units the way you normally would: 1.5 m, 1500 mm and 0.0015 km are the same answer.
(b)
At what rate does the integral's force grow at first?
Check
A loop oscillates steadily at gain 10 with period 0.5 s. Ziegler–Nichols PID sets , and .
(a)
What is ?
(b)
What is ?
(c)
What is ?
Explain why
What does each term of a PID controller contribute?
The proportional term pushes in proportion to the present error, giving a fast response, but on its own it leaves a steady error whenever a constant effort is needed and can make a lightly damped plant oscillate. The integral term accumulates the error over time and keeps increasing its push for as long as any error persists, which drives the steady-state error to zero but tends to add overshoot. The derivative term responds to how fast the error is changing, anticipating where it's heading and braking the motion before it overshoots, which adds damping; because it amplifies rapid changes, it's filtered and often applied to the measurement to ignore sudden setpoint changes.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.