A lot of people say a lot of things about setting P and I gains for multicopters. While a lot is true for some cases, it seems a lot of people do not really understand how these gains work to keep you plane or multicopter in the air.
There are whole books dedicated to control theory that go into a lot of detail on PID or PI control loops and these gains, for the theoretical (poles, imaginary numbers...) to the practical, but my goal here is to keep it simple and applied to multicopters.
So, for the sake of explanation, we'll assume that the only objective of the control loop (the logic that uses the P and I gains) is to keep the multicopter level (centered sticks). From there, it is easy to understand that moving the sticks simply moves the desired position (attitude) and the control loop will aim for that instead of level.
Also, we'll consider only a single axis, pitch for example. The same is duplicated 3 times for pitch, roll and yaw. For a tri-, hexa- or octo-copter, then the logic is a little more complicated in terms of the contribution of each motor to correct the attitude, but the same logic applies for the P and I gains.
What is the P gain
The P gain stands for Proportional. This is the gain that applies to how much we are out-of level.
- If we are level, then each motor is driven with the current throttle position (T).
- If we are 1 degree out of level, then each motor is driven with T + (P * 1).
- If we are 2 degrees out of level, then each motor is driven with T + (P * 2).
What happens when the P gain is too LOW
If the P gain is way too low, then we simply will not be increasing the thrust enough to level the multicopter back. It will want to flip over.
If the P gain is slightly too low, then it will be controllable, but drift excessively. It will take a longer time to get back to level.
What happens when the P gain is too HIGH
If the P gain is too high, the multicopter will wobble (oscillate) because it will compensate too much when going out of level and overshoot, meaning it will go back to level quickly, but then continue and get back out of level the other way, and so on.
Be careful to make sure the P gain is not too high not only trying to fly level, but also when the stick inputs change, when there are gusts of wind or when coming down vertically, in the turbulence of your propellers. If the P gain is just a bit on the high side, it will be rock solid flying level, but then get out of control when you try any aggressive manoeuvre.
What is the I gain
The I gain stands for Integral, which is a fancy way of saying "over time". This is the gain that applies to how long we are out-of level.
- If we are level, then each motor is driven with the current throttle position (T).
- If we are 1 degree out of level, then each motor is driven with T + (P * 1).
- If we are 1 degree out of level for 0.5 second, then each motor is driven with T + (P * 1) + (I * 0.5).
If you hold your multicopter in your hands and tilt it, the corresponding motor should spin up. This is the P gain. If you hold it there and the motor speed keeps increasing, this is the I gain's contribution.
Note that how the I gain is implemented can vary, but the effect described here is valid nonetheless.
What happens when the I gain is too LOW
If the I gain is way too low (or 0), then the multicopter may not be able to get back to level and drift if an external force (like wind) is applied. This is not a major problem and this is why you should start tweaking the gains with I set to 0.
What happens when the I gain is too HIGH
If the I gain is too high, the effects are similar to having the P gain to high, but even more dramatic. The multicopter will wobble (oscillate) because it will compensate too much when going out of level and overshoot, meaning it will go back to level quickly, but then continue and get back out of level the other way, and so on.
The effect will be more dramatic because the I gain applies over time, so it will take longer to realize it is past level and reduce (and reverse, by then) its effect.
If the I gain is just a bit on the high side, your multicopter will be stable, but you'll notice that if you try to move in one direction (forward hopefully) for some time it will tend to gradually level off and automatically pitch back when you center the controls. While stable, this will make it more difficult to precisely control the final position of your multicopter when you stop.
What is the D gain
Some controllers may have an additional D gain. It is not extremely useful for multicopters (the mathematical proof of this is outside the scope of this article), but may be present in some controllers
The D gain stands for Derivative, which is a fancy way of saying "over speed". This gain works differently than the previous two in that it will work against them to prevent the problems (oscillations) that occur if they (the P and the I gains) are too high, while still keeping the benefits of their high values: stability and speedy recovery. This can be seen as a damping factor.
- If we are level, then each motor is driven with the current throttle position (T).
- If we are 1 degree out of level, then each motor is driven with T + (P * 1).
- If we are 1 degree out of level for 0.5 second, then each motor is driven with T + (P * 1) + (I * 0.5).
- If we are 1 degree out of level for 0.5 second but in the process of getting back to level at a speed of 2 degrees per second, then each motor is driven with T + (P * 1) + (I * 0.5) - (D * 2).
In plain English: If you are out of level, the P and I gains kick in to bring it back. As you multicopter start moving back to level (but not there yet), the D gain will turn down the throttle to partially cancel out the P and I gains' effect so that it doesn't overshoot and start wobbling.
What happens when the D gain is too LOW
If the D gain is low (or doesn't exist), then the multicopter will wobble if the P and I gains are too high.
What happens when the D gain is too HIGH
If the D gain is too high, then while stable, your multicopter will feel like there is a big delay between your stick inputs and the corresponding reaction (remember: damping).
What about auto-leveling?
The overall logic described above applies to both the stabilization and auto-leveling, and to anything that uses PID really, but the specific behaviors described in the "What happens when..." sections refer mainly to the stabilization. This is what we would call the "fast loop". The behaviors for the auto-leveling are similar, but will be on a longer time frame (slow "rocking" oscillations for example).
You can think of the stabilization and auto-leveling as two nested loops. The stabilization is the inner, fast, loop which needs to adjust and compensate any deviation from the desired position (being stable) very fast. The auto-level is a secondary, slower loop that will modify the "desired position" input of the inner stabilization loop in order to get achieve a secondary goal, being level.
As you can imagine, because of the nested condition of the control loops, without the inner loop (stabilization) working well, the outer-loop can't do much since it depends on it.
Correspondingly, setting the gains of the auto-leveling is a much less sensitive affair, since its reaction time is much longer (being the slower, outside loop). The P gain will affect how quickly the multicopter snaps back to level, while the I gain should be increased only if the multicopter fails to reach a level state in some conditions (doesn't correct enough).
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
PID control is robust and well (better) understood. If it is hard to have accurate info on PID, imagine a hobbyist tuning a state-space controller.
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Short and precise, really like it.
Log In to reply
One question though. Do you have a methodology or a link to another article you could share on setting the PID gains. Appreciate there is an element of trial and error but I assume there is an order by which to adjust things to tune it up.
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Just a remark. I believe the last title should be "What happens when the D gain is too HIGH" ???
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Cheers Rob
Log In to reply
You don't sound like you needed this article to help explain PID :) Your comment and article definitely make for a more advanced reference on the subject. I didn't want to get into the the design at the sensor level (why D is hard to tame in discrete time (digital) systems). Most multicopter controllers, to my knowledge, do not allow the user to modify sensor filtering parameters, so that's why I left it out.
Thanks for your comment.
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Log In to reply
Great article, had to look a while to find this quality of info. I wonder however, if the P gains described here refer to stabilization P gains or auto-level P gains. Or to both? And if so, what is the difference between both? For example, on my KK 2.15 firmwire version 1.6 I have the PI editor, with PI gains and limits, but I also have the auto-level option, with a separate P gain and limit.
cheerio
-b
Log In to reply
You can think of the stabilization and auto-leveling as two nested loops. The stabilization is the inner, fast, loop which needs to adjust and compensate any deviation from the desired position (being stable) very fast. The auto-level is a secondary, slower loop that will modify the "desired position" of the inner stabilization loop in order to get achieve a secondary goal, being level.
As you can imagine, because of the nested condition of the control loops, without the inner loop (stabilization) working well, the outer-loop can't do much since it depends on it.
Correspondingly, setting the gains of the auto-leveling is a much less sensitive affair, since its reaction time is much longer (being the slower, outside loop). The P gain will affect how quickly the multicopter snaps back to level, while the I gain should be increased only if the multicopter fails to reach a level state in some conditions (doesn't correct enough).
Great question. I'll update the article to include this.
Log In to reply
For example - I've found that if the yaw gain is too high the quad gains altitude when yawing. I have never seen an oscillation when yawing, so the physical symptoms are somehow different than pitch and roll.
It would be helpful to have an expert point them out to help less experienced people. Especially when you have a quad that has no magnetometer - how does it know which direction it's facing, so what does the yaw gain actually do?
Log In to reply
Log In to reply
My question is how influence Flight controler vertical positon on o.e 250-300 mm size quad on PIDs and how I must cahange PIDs.
I suppouse that if controller is in level with mothors or maybe in center of gravity of multicopter it is ok.
BUT what if its vertical position is lower than above 2 points ? o.e. R 7-8 cm lower then motor levels.
Then fc don't moves in central point of quad, than rather on some radius R on the sphere around central point. How does this influence on PIDs, calculations, and informations from Gyros, and Accel.. I have some ideas about it, but I would like to read some opinions...
Log In to reply
Log In to reply
Log In to reply
Log In to reply