# P, I (and D) gains in a nutshell

| January 30, 2014 | (112) Posted in Tips

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

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

This is awesome!!!!! I had a rough idea of what it was but this is so informative and simple at the same time. Thanks for your contribution! !
theherbp on January 30, 2014
Thanks a lot for that!
Short and precise, really like it.
28th St. Air on January 31, 2014
great article. In the paragraph prior to describing P gain, you mention that "we'll consider only a single motor". I'm a bit confused that you go on to describe that for 1 degree out of level, each motor is driven with T+(P*1) or in the case of 2 degrees, T+(P*2). When you say "each motor", it reads as though you are describing each(all) of the motors on a multirotor, but i think you mean that for each degree a single motor is out of level it is driven T+(P*Degree)??? Otherwise if each motor was driven with the same force it would not level. sorry if I'm over thinking this. :)
Mathieu DD on January 31, 2014
Updated the article. Thanks for pointing it out.
Mathieu DD on January 31, 2014
I should have said "only one axis", as in just pitch or yaw. The resulting equations if you consider all axes at once get too long, because of the interactions. Not that it is really complex, but it would take away from the legibility.
uberjay on January 30, 2014
Awesome! Thanks for this. Perfect timing as I just finished assembling my first multi. :)
Widkin on January 30, 2014
You, sir, are a truly awesome chap for writing this! I have been so annoyed at all the so-called "guides" to PI(D) settings, where no one seems to know what they are talking about. Heck, even the guide from Rolf Bakke (KapteinKuK), creator of the KK board, is confusing and not very helpful. You on the other hand capture the essence of PID theory for RC perfectly. Now I don't have to get my old school books and read up on it to get my KK2 tricopter working.
rogue-insight on January 30, 2014
I've often wondered why D is always dismissed for multicopters. If you use D you can get to a critically damped response. It really helps get rid of wobble. You mentioned there's a mathematical proof that D isn't needed. I'm a mech engr and I took controls in undergrad. I'd like to hear your position on derivative gain.
Mathieu DD on January 30, 2014
Derivative gain is not generally useful on system which present a natural lag. A multicopter is a double integrator system in that we act on the thrust (acceleration) and control the position. These systems have a natural lag that is significant and don't require the additional damping provided by the derivative component.
ljeary on January 30, 2014
FANTASTIC!!! Couldn't find an explanation of what P and I gain where. Seems like most people don't know and just keep changing them till their multicopter are stable. Thanks for taking the time to explain it to us!
optimus79 on February 1, 2014
Great explanation of PID! Every other I read so far was disappointing due to complexity. But I think your's is as simple as it could get. Thanks!!!!
Just a remark. I believe the last title should be "What happens when the D gain is too HIGH" ???
Mathieu DD on February 2, 2014
Oops, you're right. I've updated the article. Thanks for the heads up.
onemoreflite (John Michaels) on January 30, 2014
The most easily understandable explanation I've heard to date! Awesome!
jweymarn on January 30, 2014
This is great! I have a masters degree in engineering so i know PID regulators but this is by far the best explanation you can give outside a lecture class!
SR-71 on February 3, 2014
Thank you
btallis on January 30, 2014
Thank you so much for this write-up. It is very informative, yet clear. I recently bought a OpenPilot Revo board, and it talks about "inner loops", "outer loops", D values, etc. A bit daunting, but after reading your explanation, it makes more sense. Thanks!
Mathieu DD on January 30, 2014
Inner and outer loops are an extension of this. Inner loops are typically faster and control more important function. In your case, likely the attitude (level). Once things are stable within the inner loop, the outer loop controls lower priority variable, likely position in space (GPS or other).
windphile on January 30, 2014
Never mind, I guess you did have formulas but simple ones. I have a big fat book that explains this.

stang513 on January 30, 2014
Very informative however I do have to agree with rogue-insight. I am an aerospace undergrad and currently I am studying system modeling. The Damping gain may not be useful in calm flight conditions however, in a situation with significant outside forces that could cause oscillations to get out of control even with the P and I gains dialed in the D gain could cut recovery time significantly.
MentalWhiplash on January 31, 2014
Bravo! This is the first truly comprehensive explanation I've seen. My engineering mindset has never been satisfied with other explanations, especially since the vast majority of them are put up by people who do not truly understand the underlying concepts. This has made my day.
Autarch on February 2, 2014
excellent. thanks for the much needed simplified explanation.
This is GREAT! I have struggled to find a good explanation of PIDs. Thank you so much for taking the time to explain these concepts in what is probably the simplest way possible. I am definitely bookmarking this article!!!
windphile on January 30, 2014
Great Explanation without formulas.
Tactical Ex on January 30, 2014
I haven't even considered multi-copters yet but I found this article very informative and interesting. Thanks for the info, I'm sure when I finally get around to building a multi-rotor I'll be much more prepared!
Great article! Clears up alot of confusion!! Thanks!!!
rogue-insight on January 30, 2014
Have you heard of anyone using alternative control loop algorithms, instead of the classical PID? I"m thinking things like state-space, adaptive control, or fuzzy logic controllers.
Mathieu DD on January 30, 2014
The problem is that advanced control strategies can be much better, but require more accurate tuning of their parameters. Because of the variety of the systems out there, it would be VERY difficult to have an all-purpose controller use these strategies. I don't think you would appreciate a board having to perform a system identification on your brand new quad (impulse, ramp response) . Can you say CRASH! Also, limited processing power of on-board microcontrollers doesn't help.

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.
sailorJohn on January 30, 2014
Just a plain THANK YOU!
Crashpilot1000 on February 3, 2014
Well done! I tried to explain P & I here some time ago: http://forum.flitetest.com/showthread.php?6258-P-and-I&p=71089&viewfull=1#post71089 maybe it's a worthwhile addition to your explanation. Since the D part is not based on accumulating error (like I) but looking at the errorCHANGE it is more affected by sensor inaccuracies/disturbances. So if you can't dial in a decent D you can bet everything on the fact that you have too much vibrations in your copter and/or the filtering of sensordata has to be increased (without going too much out of phase...)
Cheers Rob
Mathieu DD on May 3, 2015
Hi,

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.

Christian Jeppesen on January 30, 2014
Thanks for sharing, very useful :D.
jpleaner on January 30, 2014
Great article! I work with PID loops as an engineer in the air conditioning controls industry and that explanation is defi Italy transferable to A/C control as well.
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.
koreysmith123 on January 31, 2014
Hello. I made a video about PID tuning yesterday. It's a very simple video, but it might help some. http://www.youtube.com/watch?v=LtocGBngSrA
Dingo on January 31, 2014
thank you this is so helpfull
ghostrider03z on January 30, 2014
I've never seen an article get 35 ratings averaging 4.95 in a few hours...you sir, did a fantastic job explaining this. It would be awesome if you did an article explaining limits
grackle on April 20, 2014
Excellent article!

popshere on September 13, 2014
Wonderful article. This helped me setup my tricopter. Now what are the limit values doing? I guess they set a maximum value on the combined change in thrust? Although this would only impact I gain's time impact?

joerenteria on October 16, 2014
I created an account just to say thanks for such a great explanation...
Mathieu DD on October 18, 2014
Thank you for the feedback. Have a great flight!
aGGreSSiv on November 19, 2014
I created an account too, just to say thanks for such a great explanation.. :)
babipsylon on May 3, 2015
hi
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
Mathieu DD on May 3, 2015
The overall logic applies to both, and to anything that uses PID really, but the specific behaviors described in the "What happens when..." sections refers 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" 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.
jerryzito on March 26, 2015
I have been looking everywhere for an explanation like that. Excellent work. Can you tell me when I should adjust gains in PI editor and Self-Level?
Paul'R on May 22, 2015
It would be great if you could expand this article to explain how the Yaw Gain affects flight - either too low or too high.

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?
Amorgos on August 6, 2015
I am also unsure about how Yaw PID gains effect flight. I cannot find the answer anywhere! Anyone know?
boha on July 31, 2015
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...
Jug5y on March 24, 2016
Awesome guide, thank you so much!