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).
0 comments