In this article, I'm hoping to explain what PID is, what it is used for and how to tune it. PID has become a way of life for the RC Industry, especially with quadcopters. So what is PID?
First, let’s break it down into each letter...
- P - Proportional (Kp). This is the gain that corrects what has already happened. Using a quad as an example, let’s say the quad is at a 45º angle, and it wants an angle of 0º or flat. The Proportional gain is going to sense the quad is located at 45º and is going to give as much input as the gain allows to return to 0º. In doing so though, it is going to overshoot its target since there is nothing there to stop it. And once it overshoots, it starts correcting again. The further from 0º the quad is, the more input P is going to put in to return to 0º. So for example, if you are at a 20º angle, it is going to give 20% power to return to 0º. If you are at a 45º angle, it is going to give 45% power to return to 0º and so on. It's like driving a car. If you are driving along and you lose 5mph, you are going to slightly increase throttle until you get back to the speed limit. If you lost 15mph, you are going to give even more throttle to get back to the speed limit.
This is the most noticeable gain on the PID scale. If P is too high, it will result in very fast oscillations. If P is too low, the quad will wonder all over the place and be very hard to control. The problem with P though, other than overshooting its target, is it is not very accurate. It can deviate from 0º by quite a few degrees since its correction is directly related to the angle at which it is trying to correct. This is where I comes in...
- I - Integral (Ki). In laymen terms, I is the OCD child of the PID family. This is the one that takes its time doing what it needs to do, but it has to be perfect. When you pair I to P, P is going to return the quad, as fast as it can, back to 0º. If this change is very small, then P will stop doing what it is doing basically saying "that's good enough" when it is still a few degrees off. I on the other hand takes over and says "no way is that good enough, i will take it from here". I will slowly return the quad to EXACTLY 0º, but it takes its time in doing so. So how do you put P and I together so that they not only work fast, but also work precisely? That is where D comes in to play.
- D - Derivative (Kd). D is the family member that remembers EVERYTHING. It remembers the time when P overshot 0º causing a massive oscillation that resulted in a crash. It remembers where it needs to be and it remembers what corrections have to be made in order to get it there. Basically, it sees that the quad was at 45º and P took over to get it back to 0º as fast as it possibly could. But it knew that P was going to overshoot 0º so D steps in and says "whoa, you need to back it off when you get to Xº so that we can stop near 0º". So it takes P by the hand and slows him down right as they are getting to 0º. Pair those two with I who will put it exactly on the mark and you have a very fast movement back to 0º which stops exactly at 0º with no oscillations.
But there is a catch. D is very short tempered and if you over work him (set the gain too high) he will start smoking ESC's and motors. D is like a fine whisky, you only use him in extreme moderation. Only enough to get the job done.
Now I will admit, getting those 3 to behave together is a major challenge to the newcomer into the Rc world. When I first heard of PID I said to myself that there was no way I would ever understand it. And in a way that is true. The algorithm that goes into the PID sequence is very complex. In fact, I have put the algorithm below.
As you can see, it's quite complex, but it doesn't have to be for the normal Rc hobbyist if you follow what I typed above.
So how do you go about testing and tuning these settings? That part is actually the best part because you get to put many batteries through your quad to get it perfect. With that said though, there is no one set of numbers that will work for everyone. You can get close with defaults, but to get perfect, it's time to fly.
The first thing to do is leave the suggested settings in the controller and fly it. Watch it, listen to it and feel it. Doing this FPV in an open field could actually be a benefit because you can see small changes in the camera that you wouldn't be able to pick up on just looking at it LOS. So let’s start the tuning.
We are going to start with the P gain. Normally your P gain is going to be set quite conservatively. Let’s use 45 as an example. Take the quad up and give the sticks some very fast flick inputs. If you do not hear and see the quad oscillating very fast, then raise the P gain. Let’s say we took the P gain all the way up to 85 and we repeated the process. Now we have a very fast oscillation that is almost unflyable. Land it and lower your gain by 5 an try it again. This is where listening to your quad is going to come into play. Once you hear no oscillations and it is stopping without any oscillations, P is close, but not perfect.
Now we are going to tune the I gain. Remember, I is very slow at what he does, but very precise. If your I gain is too low, it will not stop the quad right where it needs to at 0º There will still be a little drift in the quad. But if the I gain is too high, it can, in extreme cases cause a slow oscillation. Not as fast as the P gain oscillation though. What I do to tune the I gain is just raise it until when in fast forward flight the nose doesn't want to drift up. The quad, in all attitudes should remain right where you put it.
And finally, we are at the D gain. Like mentioned above, D is going to calculate what has happened before and apply that to the P and I so that it will stop exactly where you want it to stop. In this example, that will be 0º. However, you do NOT want to try a high value in D because it will start burning up ESC's and motors. You only want a value high enough to stop a movement exactly where you want it to stop. Start with a 0 gain on D and slowly raise it up every flight until your stops are crisp with no overshoot.
Now that you have put some D gain into the gyro, you can more than likely raise the P gain slightly to get a little crisper feel. Just go out and fly, raise P by 5, fly, and keep doing so until the quad is locked in to your flying style.
It will take time to get a feel for this but trust me, as time goes on, it will come. Use your ears, use your eyes and use the feel of the sticks. I know it may sound weird to a new modeler, but you can actually feel the flight when you are flying. Sometimes you give an input and the quad does nothing. Sometimes you give a small input and the quad starts oscillating uncontrollably. This is when it is up to you to connect it to the program and make a change where you think it needs to be corrected.
I hope this article was helpful in helping you understand how PID's work and how to tune them. Stay tuned for a video based off of this article. Now if the weather will just cooperate with me....
If you would like to print this article out, you can click on the link below for the PDF version.
P.I.D. Tuning Explained
If you would like to get rid of these banners and the ads within the posts, all you have to do is sign up and they will go away!
Welcome to Rc-Help, are you here looking for the PDF Plans? They are located in the store in the tab above, but you must be signed in to access that part of the site. It only takes a second to sign up!
Like Us On Facebook!
Hello Guest, it occurred to us during that last server failure that we had no way of informing the members of the site of the failure and I would like to invite you to like us on facebook so that you can get updates if the site happens to go down again. We don't post much over there unless we are updating the members so we will not flood your feed like some places do. Just click on Like and then allow notifications and that's it. See you there soon!
Click Here To Rc-Help's Facebook page!
To make a comment simply sign up and become a member!