bradquick Registered User Thread OP

Discussion PID Explained



https://www.rcgroups.com/forums/show....php?t=1375728



Unfortunately, the author's explanation of terms is incorrect. The following is an attempt to explain how PID works in a way that multi-rotor pilots will understand and be able to apply to their setups.



PID stand for Proportional, Derivative, Integral. Each of these represents a multiplier for one of the three terms that are added up to generate the final output.



Error - First, let's define the Error as the difference between our desired position and our current position. On a multi-rotor, our desired position may be level (angle of zero), but our current position may be 10 degrees. The error is then 10 degrees. If our desired position is rolled 5 degrees, but our current position is at -5 degrees, this is also 10 degrees of error.



P - Proportional. The P multiplier is pretty simple. It simply gets multiplied by the current Error. So the farther away we are from where we want to be, the larger the output. This is the main driving factor that moves us toward eliminating the Error, or getting us to the desired position. So, generally, we want P to be as high as possible because it will get us there faster.



The problem is that when we increase P too high, we get overshoot. This means that we move quickly toward our target, but even as we get close to our target and have built up a high rate of speed, we are still driving toward our target (but a lower amount because our Error is now smaller), so when we get to our target, we are going too fast and we fly right past our target. Once we are past the target, our Error is in the opposite direction, so the output reverses and we drive back in the other direction. You can see how this causes oscillation.



D - Derivative. Derivative is a fancy term for velocity (for our purposes). The D term is multiplied by the rate of change of the Error, or how fast we are approaching our target. It works in the negative direction, so as the velocity increases, the D term tries to slow us down by working in the opposite direction.



So, you are hovering in a level position. You suddenly throw the stick so that you will roll to 10 degrees. You now have a large Error, so the P term kicks in and drives the machine toward the 10 degrees. As it picks up speed along the way, the D term works to slow it down. As we approach our 10 degree target, the Error is now smaller, so our P term isn't doing much and our D term is slowing us down. This allows us to get to our target without overshooting.



As you can see, the D term allows us to use a larger P term without excessive overshoot.



So, we want as high a D term as possible, but if we get too high, the system becomes unstable (sometimes, violently so).



We have one remaining problem. Let's say our target angle is zero degrees (level flight) and our current angle is 1 degree and our velocity is zero. Our P term doesn't do much because the Error is small. Our D term doesn't do anything because there is no rotational velocity. This means that the aircraft feels a little mushy and doesn't hold it's position well.



I - Integral. The integral error is simply our Error added up over time. Using the example in the paragraph above, our Error is 1 degree. If our P term isn't large enough to close this 1 degree gap, then the next time through the loop, we add another 1 degree to the integral error, so now it's 2 degrees. The next time through, it's 3 degrees, then 4, etc. Eventually, the integral error gets high enough that we generate a large enough output to drive the Error to zero. As you might imagine, the integral error can grow quickly. This is why I multipliers are very small.



By it's nature, the I term will cause overshoot. Too much I will generate too much overshoot and can also create violent instability.



My general tuning procedure is this:



- Turn I to zero.



- Increase P until you can see it overshoot and correct itself.



- Increase D to eliminate the overshoot. If oscillations become worse then you have too much D and will have to back off both P and D.



- Keep going back and forth between increasing P and D until you have to back off because D is making things worse.



- Finally, increase I until you see signs of instability (oscillations), then back off.



The further you back off on the values from their unstable points, the less "crisp" your aircraft will feel, but you'll also have less chance of getting into a situation where the aircraft will go violently out of control.



I hope this is helpful. I know there are a lot of people out there that struggle with PID tuning. While searching, I came across this blog:Unfortunately, the author's explanation of terms is incorrect. The following is an attempt to explain how PID works in a way that multi-rotor pilots will understand and be able to apply to their setups.PID stand for Proportional, Derivative, Integral. Each of these represents a multiplier for one of the three terms that are added up to generate the final output.Error - First, let's define the Error as the difference between our desired position and our current position. On a multi-rotor, our desired position may be level (angle of zero), but our current position may be 10 degrees. The error is then 10 degrees. If our desired position is rolled 5 degrees, but our current position is at -5 degrees, this is also 10 degrees of error.P - Proportional. The P multiplier is pretty simple. It simply gets multiplied by the current Error. So the farther away we are from where we want to be, the larger the output. This is the main driving factor that moves us toward eliminating the Error, or getting us to the desired position. So, generally, we want P to be as high as possible because it will get us there faster.The problem is that when we increase P too high, we get overshoot. This means that we move quickly toward our target, but even as we get close to our target and have built up a high rate of speed, we are still driving toward our target (but a lower amount because our Error is now smaller), so when we get to our target, we are going too fast and we fly right past our target. Once we are past the target, our Error is in the opposite direction, so the output reverses and we drive back in the other direction. You can see how this causes oscillation.D - Derivative. Derivative is a fancy term for velocity (for our purposes). The D term is multiplied by the rate of change of the Error, or how fast we are approaching our target. It works in the negative direction, so as the velocity increases, the D term tries to slow us down by working in the opposite direction.So, you are hovering in a level position. You suddenly throw the stick so that you will roll to 10 degrees. You now have a large Error, so the P term kicks in and drives the machine toward the 10 degrees. As it picks up speed along the way, the D term works to slow it down. As we approach our 10 degree target, the Error is now smaller, so our P term isn't doing much and our D term is slowing us down. This allows us to get to our target without overshooting.As you can see, the D term allows us to use a larger P term without excessive overshoot.So, we want as high a D term as possible, but if we get too high, the system becomes unstable (sometimes, violently so).We have one remaining problem. Let's say our target angle is zero degrees (level flight) and our current angle is 1 degree and our velocity is zero. Our P term doesn't do much because the Error is small. Our D term doesn't do anything because there is no rotational velocity. This means that the aircraft feels a little mushy and doesn't hold it's position well.I - Integral. The integral error is simply our Error added up over time. Using the example in the paragraph above, our Error is 1 degree. If our P term isn't large enough to close this 1 degree gap, then the next time through the loop, we add another 1 degree to the integral error, so now it's 2 degrees. The next time through, it's 3 degrees, then 4, etc. Eventually, the integral error gets high enough that we generate a large enough output to drive the Error to zero. As you might imagine, the integral error can grow quickly. This is why I multipliers are very small.By it's nature, the I term will cause overshoot. Too much I will generate too much overshoot and can also create violent instability.My general tuning procedure is this:- Turn I to zero.- Increase P until you can see it overshoot and correct itself.- Increase D to eliminate the overshoot. If oscillations become worse then you have too much D and will have to back off both P and D.- Keep going back and forth between increasing P and D until you have to back off because D is making things worse.- Finally, increase I until you see signs of instability (oscillations), then back off.The further you back off on the values from their unstable points, the less "crisp" your aircraft will feel, but you'll also have less chance of getting into a situation where the aircraft will go violently out of control.I hope this is helpful.