In an earlier article I wrote about PID and how this basic principle is applied all around us. From cars to drones. Not everyone could immediately picture it, which is understandable. That is why this time I made a special blog: an interactive one. This time you get to take control yourself.
In the fictional example below you will set a PID that controls the drone rotors. Your goal is to keep a drone in the air. You work with four settings. Three of them are the PID settings. The fourth is the desired altitude at which the drone flies.
The goal is to keep the drone flying at the chosen altitude, regardless of outside influences such as wind. How well that works depends on you. You set the PID so the drone automatically and stably stays at the right height.
The drone reports its current altitude via a GPS chip. The desired altitude is set by you, up to 3000 meters above the ground.
To help you tune the PID I made a PID monitor. It shows in a graph what is happening. The red line is the actual altitude of the drone. The green line is the desired altitude. The blue line is the signal that the PID sends to the rotors.
A well tuned PID reaches the chosen altitude in a smooth curve and corrects gently for wind changes. A poorly tuned PID overshoots the target and then drops back down, causing a strong oscillation. Your challenge is to adjust the PID so the drone holds its altitude neatly, even in the wind.
Your controls
[P] Proportional | |
---|---|
[I] Integral | |
[D] Derivative |
Desired altitude | |
---|---|
Altitude now | - |
Rotor control | 0% |
Your PID monitor
Notes
- Start the simulation. The drone begins on the ground, at 0 meters altitude.
- Start the rotors. The PID becomes active and the drone takes off.
- Stop the rotors, and the drone slowly drops back to the ground.
- Stop and restart the rotors after you change the PID values or the desired altitude.
- If you stop and restart the entire simulation, the drone starts again from the ground.
Example settings
- With P=3 / I=2 / D=0.01the drone overshoots the target, but quickly corrects toward the right altitude. It never reaches it exactly though.
- With P=1 / I=0 / D=0the drone takes off, but does not reach the set altitude of 80 meters. It stays just below it.
- With P=1 / I=2 / D=0the drone overshoots 80 meters. It wobbles a bit, but slowly gets closer to the correct altitude.
- With P=1 / I=2 / D=1the signal becomes very messy. The corrections are too strong and too frequent.
- With P=3 / I=0.2 / D=0.1it gets much closer to a useful PID setting.
Finally
Hopefully this interactive example helped to make clear what a PID actually does. You might even recognize the behavior of a hobby drone in the graph, because they really use one. Just like countless other devices around us. A PID is a software solution that ensures systems behave stably in changing conditions. Feel free to play with it some more and discover the effect of different settings yourself.