Flight Controllers P.I.D. Tuning Explained

Tony

Staff member
Tony submitted a new Article:

P.i.d. Tuning Explained

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, lets 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, lets say the quad is at a 45º angle, and it wants an angle of 0º or flat. The Proportional gain is going to sense thequad 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 it's 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º to D steps in and says "whoha, 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.
View attachment 17159

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 lets start the tuning.

We are going to start with the P gain. Normally your P gain is going to be set quite conservatively. Lets 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. Lets 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 a 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 slighty to get a little more crisp 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 need 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....

View attachment 17159

Read more about this article here...
 
Last edited:

Tony

Staff member
PID can be a very confusing setup process. I always start with P then go to I and finally D. Just remember, D can and will burn out your ESC's if you set it too high, so only go as high as you need to go.
 

FlyByKnight22

New Member
Tony,

I’m glad you have decided, for whatever reason to touch upon “PID” tuning.

Most forums I have been on don’t talk much in depth about the underlying electronic theory/history that makes our planes and quads, behave and work the way they do.

Like surfing the web we open a browser, push a track ball or mouse button and just expect things to work without appreciating or fully understanding the immense complexity of the binary, octal, hexadecimal numbering systems, routing algorithms, digital electronics, cable/fiber optic medium, WiFi and satellites involved, that make the world wide IP network function.

It used to be said: “Engineers delightfully design the thing but it’s the Technicians in the field, those that work in the real world, involved with the man power/manning and the hardware in general, that have to make the DANG THING WORK!” :)

That’s kind of how I see us, the “technicians” that have to make it “WORK”.

Most folks just want to hook up a battery and fly. It doesn’t generally matter to them how it does what it does, as long as it works the way it should. With most of my store bought quads I have a tendency to be this way. After all, they’ve already been built and in many cases Pre-tuned to fly as advertised.

PID tuning “generally” doesn’t become a factor (at least not for me) until you build one from scratch, with a wide variety of components that you have to try and optimize to get it flying the way you want it too. This is when I think it becomes “generally” more important to understand, at least at a more fundamental level, how this technology basically works.

PID Control systems have been around for a long time.

Many years ago I went to a 26-week maintenance course at the Navy’s Fleet Anti-Submarine Warfare Training Center Atlantic (FLTASWTRACENLANT) in Key West Florida.

I was there for several years taking various sonar/electronic maintenance courses but in this one particular class I was taught the theory behind it and how to repair, adjust, maintain and operate an underwater fire control computer system, that used trigonometric functions from various inputs, to predict future target position and to remotely control and program a missile launching system/mount, stabilized for pitch and roll, to effectively place a weapon on that target at various ranges.

As you might imagine, the computer system had to account for many factors in order to correctly command/move the remote launching system in elevation and bearing, program the weapon itself prior to release/launch, in order to get a good firing “solution” to hit the target.

The underwater fire control computer system was state of the art for its day but even then it was a hybrid of digital/analog components and gearing systems, filled with syncros, servos, resolvers, motors, encoders, decoders and amplifiers. Error signals, dampening and feedback loops were used extensively throughout the system.

This in many ways sounds reminiscent and somewhat similar to the toys we play with today and perhaps answers the question as to why I participate and enjoy the RC sport.

Much of the electronics behind how this works is defined primarily with mathematics but that is beyond the scope of what we need or what you are attempting to do here and is really unnecessary unless you are the man,..
“that wants to know everything” :)

If you are still awake, I said all that to say this:

This is kind of where I see your article on PID tuning. I think it fits just right where it needs to, to get us thinking more about how to get started in tuning our DIY and store bought quads.

Thank you again for your thoughtful, reasoned and well targeted article.

Best Regards,
Dennie
 

Tony

Staff member
That was one hell of a post, that's for sure lmao. And thank you for taking the time to tell us all of that. I try my best to put things in a term that everyone can understand. Those that have a fantastic grasp on the concept will think it's too "dumbed down" but those that have never had to deal with them and need to wrap their head around what each thing does, hopefully it is just right to help them to understand it.
 
Top Bottom