# Understanding PID for Quadcopter RC – Flight behaviour

I wrote a brief article explaining what PID is and how it could affects the multicopter, after a few months of more experimenting, I would like to add a few more words, and share what I found useful on the way to better quadcopter PID tuning. (This applies not just to quadcopters, but other multicopter configurations such as the tricopters and hexacopters)

# Explain PID Tuning in Simple terms

As explained previously, a PID controller (proportional-integral-derivative controller) is a control loop feedback mechanism widely used in control systems. A PID controller calculates an “error” value as the difference between a measured variable and a desired set-point. The controller attempts to minimize the error by adjusting the control inputs. (Seriously, this definition is completely useless for us non-academic people ;-p )

In multicopter terms this means the PID controller will be taking data measured by the sensors on the flight controller (gyros / accelerometers etc) and comparing that against expected values to alter the speed of the motors to compensate for any differences and maintain balance.

The PID controller calculation algorithm involves three separate constant parameters, the proportional, the integral and derivative values, denoted P, I, and D. Heuristically, these values can be interpreted in terms of time: P depends on the present error I on the accumulation of past errors D is a prediction of future errors, based on current rate of change Depending on your flight controller there will be PID’s associated with a number of flight modes.

# PID in More Simple terms

Still don’t get it? Don’t worry, let’s just get practical here, all you need to know is how to tune PID settings. This is a general description what PID is, how it affects quadcopter performance still depends on how the algorithm is written. For example in Cleanflight firmware, there are three PID controllers and they each performs differently.

### What is P?

P is the main value you worry about, which is the number for stability. Why do I say that? You can actually leave I and D values at 0 and your plane will hover just fine. So that is why you always tune P gain first before I and D.

The higher the P the harder it tries to stabilize the plane. But if P is too high, the quadcopter becomes too sensitive, and over-correct itself (overshoot), you will have oscillations with high frequency.

Not all oscillations are from P being too high though. You need to eliminate vibration as much as possible from your quadcopter before you can even start tuning, for example the motors, frame rigidity, balanced props etc. With a vibration free copter, you can set a much higher P gain and enjoy more stability, and controlability.

The way I tune P is, increase it until you see vibrations, then back it down a little.

### What is I?

Okay now you have tuned P gain, leaving I and D at default values. When you are flying you will notice that you have to hold the pitch/roll stick to get the machine to move, as soon as you let go of the stick the machine just breaks and stay in hovering again. It might even cause a few osculations or wobbles if the change of control is rapid.

That is because your P is doing its job, trying to stabilize your quadcopter. Look at I gain as the stick follower, by adding a little I gain you will find that the plane will now fly forward more smoothly. But the side-effect is when you let go of the stick the copter will keep on flying to that direction. This is the effect of I, keeping the last stick position.

To understand it, think of the quadcopter is trying to reduce the position error, but the error is not reducing, it will just keep trying! This is the effect of the I term. In technical terms, it is integrating the error over time, the longer the error persists, the greater the force is applied. When the I gain is not zero, a small error can persist forever (which is not necessary a bad thing in real flying!)

Some people use I gain to make flying more smoothly, while some people purely just like this “stick following” behavior. However with too much I your quadcopter will start to oscillate with a lower frequency at high throttle. When I gain is too low, your quadcopter will wobble when descend.

Normally default I gain works pretty well already. But if you notice wobble when descending, increase I should help. But when I is too high, you might notice slow vibrations at punch-outs (high throttle ascend).

### What is D?

D isn’t very useful to many people. In fact you can ignore D completely and your multicopter will fly just fine. That’s why the KK2 does not allow you to tune D, because they want to make it really simple and effective, without D it’s not going to affect the flight performance too much. D is sometimes used to get rid of the jerkiness of the quadcopter movement.

D is like the opposite of P. If P is a hand to keep pushing the machine back to a stable position, then D is a spring between the hand and the machine, which absorbs the shocks . By adding D gain, you can “soften” the movement just like adding a spring to it. However too much D is not good, because again it will introduce oscillations. Also your copter will be really sluggish and mushy.

Basically, D changes the force applied to correct an position error, when it sees a decrease or increase in the position error. Just like if you are hungry, you eat a lot faster, when you are nearly full, your eating will slow down. That’s why you see a softer movement  in the quadcopter when D is used.

When you see vibrations, don’t rush to decrease P, try to increase D and see if you can eliminate the vibrations. Also If you see some bumpiness or slight vibration at high throttle, or doing flips and rolls, give it a bit more D should also help. The cost is you have mushier control and stick responsiveness.

### PID for Yaw Axis

The above are mainly for roll and pitch axis, and you need to tune Yaw axis separately. Default values usually work pretty well, but same principle applies from above. It shouldn’t cause too much vibrations like roll and pitch, and at the end of the day it’s just a matter of personal preference.

# Conclusion

Here is how I setup my Naze32 FC.

I realize tuning PID is just to find the balance between the moment of inertia of the multicopter, and the force generated by the motors, which is also affected by other factors such as vibrations, frame rigidity, FC performance etc. The moment of inertia is related to how heavy the quadcopter is, how the mass is distributed, and the properties of motors. Therefore PID gains are different settings for each individual quadcopter, because they all have different setup, mass distribution etc.That’s exactly why for the pre-built quadcopters, they fly so well straight out of the box for example the DJI Phantom, because they have exactly the same setup so they can all use the same PID settings.

So there you go! Don’t forget to look at the hardware side of things before tuning PID. When your quadcopter is not stable, it could be more than just PID. It could be the malfunctioning ESC, unbalanced props or motors, could be the frame, or might be the weight is not distributed evenly on the frame. There are just so many other issues that will affect the drone’s performance and flight behavior besides PID.

Further reading: How to choose RC transmitter.

## 31 thoughts on “Understanding PID for Quadcopter RC – Flight behaviour”

1. Josi

Completely agree with you.

A well built model would not require much in PID corrections.
A few ways to improve model construction, as follows:
Assuring a balanced center of gravity.- Hold up the device by a string tied to the CG and make corrections as needed.
Reducing vibrations on the sensors located on the control board. – Secure the CB to the frame with Velcro, Inspect propellers and motor axles, use rubber between motor and frame.

2. Michael Thompson

I’m about to get into programmable flight control boards for multirotors after building toy grade FCBs intro custom flyers.
I appreciate the introduction. Many tutorials seem to say, “Don’t worry about understanding” but I want to get some book learning before I go hands-on, so thanks.

3. john barry

Can someone help.. when I punch my quadcopter and then decrease the throttle the whole way then try to punch it again or even try to increase throttle i cant. My quad will wobble violently and crashes. What am I doing wrong

4. Eddie Lloyd.

Hi Oscar

Great website and full of really useful stuff I need to learn fast ! Lol !

I’ve just started to fly a ZMR 250 with a Naze32 onboard and wondered if you could recommend suitable PID settings to tame the miniquad down for smooth beginner flying please ! I’ve set it up all using default settings in Clean Flight.

Main reason is to enable me to maintain softer control while trying FPV.

Regards – Eddie.

1. Oscar Post author

it’s hard to give you any useful “PID values” just based on guesses lol :D
it really depends on what kind of flight characteristics you want to achieve..
To fly “softer” i think you might need to look into adjusting your Rate and expo :)

1. Eddie Lloyd

Hi Oscar – Thanks for such a speedy reply ! Much appreciated !

I have just gone through your PID info again and it’s slowly making sense – I think ! Lol !

I’ve left the PID’s at default value in Cleanflight on my Naze 32 FCB and although my 250 Quad flies well it’s a bit too lively now I’ve started FPV flying ! ( First solo flight last week with only a few broken props ! )

It was suggested to me that I could try adjusting the RC and Expo rates in Cleanflight but I have no idea how to, so if you could explain these 2 adjustments it would be really helpful as I’m sure there must be other flyers out there that may like to achieve a more docile flying Quad while getting to grips with FPV flying.

Happy Flying and thanks again for such useful information Oscar ! Kind Regards . . . Eddie.

5. laurent

Hi Oscar,

Many thanks for your diverse tutorials :) i am new to this racing quad world and your explanations are always clear and knowledgeable which is an awesome help for a newbie like myself :)

6. pete

Hi Oscar, I just finished my QAV250 ARF version from getfpv.com. Lumenier 2204-14 2300kv. 5×4 DAL props. 1300 4s. Running a cc3d with librepilot. Im just using the basic settings tab and increased my Attitude – 150, Rate – 678, Rate Yaw – 678. Its basically the middle point of the INSANE tab. The quad flies ok but when I try to punch the throttle it starts to wobble. Any idea why?

7. Gaurav Mukhraiya

Hi oscar.. I hv made my new quadcopter with x configuration.. Having.1400kv motor
. Electronic all good but the main problem comes while we try to fly quad. A half feet
. Above the ground it just rolling continously with throttle. Up.. It doesn’t get stable.in one direction nd.. Nt get hovered. In one position.. And. Also.. On increasing throttle it. Automaticallly get. Moving..in other direction. Give me suggestions to improve this problem

Hi Oscar,

before the question i want to say Thank You soo much for you blog, that helped me a lot into this “drone world” :)
okay the question is..
Can you explain how to tune a quadcopter in a single axis? like Pitch PID, Roll PID, Yaw PID.
Im still confused by the tuning method that people explain on the internet,
I saw the other people PIDs (lets say the pro pilot hhe) like mr steele, skitzo, boris b & etc, they use PID1 and the value of roll P and pitch P has a different number. the Roll P value is bigger than the P pitch.

Sorry for my bad english, hope you can understand my question

1. Optamizm

Hi Adi, what I do is tune P for both axis at the same time until it starts to have high frequency oscillations… Then I pull it back a bit until they go away… Then I switch it to just the Roll P and do the same and then Pitch P and do the same… Then I do the same for I and then D… Don’t worry about other people’s PID settings, unless you have the exact same setup up as them…

Hello Oscar,

I am using Naze32 with Luxfloat on my QAV250 BlHeli flashed esc 30a and got it tuned ok so far the only 1 issues I have is, when going forward full throttle I notice my quad starts to yaw itself to right or left sometimes and almost lose control but flying up to 80% throttle is perfect ascend and descending no wobble.
I have set the looptime properly and the yaw deadband to 10 to get a little wiggle room but can’t seem to get this fast wobble in full throttle away.

1. Oscar Post author

is your max throttle 2000 at the moment? if so i guess your motors just don’t have headroom for balance adjustment at full throttle? try to set your max throttle at 1950 or even 1900 it should get better.

10. uday chandra

Hey oscar,
I have started learning more about quadcopter mathematical modelling. i want to theoretically calculate the PID values for a normal flight of a quadcopter.how should i appoach it. i have read a lot about the PID necessity,functionality and others but to put it on paper it is a problem.pls suggest a solution.

11. JITHU G

HELLO OSCAR,
I HAVE BEEN READING LOTS OF IEEE PAPER FOR GETTING A MATLAB SIMULINK MODEL OF QUADCOPTER AND I HAVE CAME ACROSS LOTS OF CONTROLLING STRATEGIES , FOR EXAMPLE, LQR , BACKSTEPPING , etc WHICH THEY CLAIM MUCH BETTER THAN PID CONTROL . I WOULD LIKE TO KNOW YOUR COMMENTS ON THIS….YOU ARE A GENIUS IN PRACTICAL HARDWARE MASTERING….SO PLEASE SHARE YOUR VIEWS ON THIS….ALSO WHICH CONTROL STRATEGY DOES THE PHANTOM DRONES USE?

12. Arvydas

Hi Oscar. Maybe you can come up with a solution. What do I do, if I get pretty hard punchback every time I snap a flip ? Btw those punchbacks are not fast oscallations. Also another one: did you have a chance to play around with PID 1 controller ? There is this really strange thing that there are no slow oscallations even when I raise Integral up to it’s max point (0,245 I believe).
Thanks!

1. Oscar Post author

those are overshoot? try to raise D of that axis…. also check if your COG is in the center and make sure weight is distributed evenly on the frame.
Were you testing indoor? slow oscillation caused by high I gain is more obvious in windy condition. But if you don’t get any that’s good for you :)

Hi Oscar,
I own a ZMR250 carbon miniquad,use kk mini 2.1, 4sets of Multistar 2206,2150kv V2+ gemfan 5×3-2blade+afro 12a v3(un-flashed,stock f/ware dated april2015′)*the esc dont have any external capacitor,though. Use two kind of lipos, mostly flown with Zippy compact 3s,1500mah,35c(as ive own 3packs), another is Turnigy nanotech 3s,1300mah,45c( so far ive seldom use this pack cuz i just have one).
-a.u.w; 620gram/with fpv set+1500mah,3s.
; 614gram/with fpv set+1300mah,nano 3s

Im intended to fly as fpv racing. Its my habit to always make cg adjustment rtf on my quad(yes,with the xt60 plugged in too) to be as centered cg…i dunno why,but ive never want to & didnt want to start fly with any offset cg setup…

Q1; is the kk mini fc is suitable& capable to be flown as my purpose,including aile/roll flip,and elevator flip?..and hows the kk mini can exceed the performance envelope of naze32 that hobbyking sells?is it possible or not?

Q2; if the quad is to be flown with rtf with fpv equipment(considering it’ll be heavier than flown without fpv), is my Zippy 1500mah considered as at heavier side for 250 class quad?Considering its just 6gram heavier than my nanotech 1300.

Q3; if most people says and proved that the naze32 is better than kk 2.1 fc for fpv racing,what makes it so,and how is it so?

Thanks Oscar..

14. Guilhem

Well I think the signal sent to the ESCs are a good proxy for RPM, so a simple ratio between the current speed signal sent to the ESCs and the maximum value that this signal can take (according to the max value used during calibration of the ESCs) can inform us about where we are between min and max RPMs, even if we don’t know the absolute value.

But my main question is actually: does this way of thinking makes sense according to you ? If no one else uses this kind of information when using PID on devices such as quadcopters (with propellers, not wheels!), it means that using a classic PID should be able to stabilize the quadcopter. I’m currently trying to get the best parameters, but as everyone seems to say, it’s hard work to find the best combination… mine sucks so far!

Thanks for you answer, and if you have a first bet for Kp,Ki and Kd value for each axis, that would be awesome. And please also precise the dimension of error value (angle in degree ?…) and of your response variable (mine is the throttle value that I adjust, and it takes values between 700 and 2000, so if you work with a signal between 0 and 5 let’s say, the parameters will be completely different… I found some values on the web that could help to start with, but people to precise the dimensions and min max of the variables.

Cheers,
Guilhem

15. Guilhem

Hey,
Thanks for your post. I’ve been reading many posts about PID algorithms as I’m making my own quadcopter (with an arduino board), and I think I got the meanings of each gain. But I still have one wonder: do you guys use a factor proportional to the motor RPMs, to have an effect proportional to the current speed ?
Let’s say my motors turn from 0 to 10 000 RPMs (I have no idea, just for illustrating), is a correction only dependent on the quadcopter position (Kp*error + Ki*interal_error + Kd*der_error) gonna make the same effect on the quadcopter if the motors run at 100 or 8000 rpms ? I actually don’t have the answer, but it the effect is the same then a “simple” PID should be all right, but if there is a difference, then I should multiply the PID by a factor depending on the current speed, as for example a simple ratio : (current_speed)/max_speed * (Kp*error + Ki*interal_error + Kd*der_error).

What do you think ? Do you know how this problem is usually solved ? Or do you think the speed has no influence ?

Guilhem

1. Oscar Post author

first question would be, how to you measure RPM? :D
It would be useful, but it’s hard to get this data, also different motors/props combination have different RPM, even motors of the same brand/model would have slightly different RPM at the same voltage/current.

16. John

I’m trying to implement a controller for a quadcopter to maintain stable flight and hover without oscilation and to effectively react to disturbance and keep stability. Planning on putting on an IMU sensor and a sonar sensor as well as a microprocessor to do the on board calculation and send signal to motors to correct any error and maintain the stable flight. Please share your experience with onborad calculations since most of the articles I’ve found have the ground control through a computer that does calculations and send signal input to the motors. What are my outputs from the sensors and how can the system calculate the desired parameters and what are these needed parameters (in my understanding only pitch yaw and role angles) ? how these calculated parameters going to be used by the controller are these values going to be subtracted from the input values ( desired values) and then the error will be sent through the controller to calculate the desired voltage to be sent to each propeller to correct the error and adjust the quad copter to reach stability? Please share any ideas of how to implement the hardware to do all these calculations and output the desired voltage to reach stability. Would a Matlab code work on a micro controller or I have to use C language? Thank you.

17. Michael

Many thanks, Oscar – I wondered about PID settings and after reading your article, I wanted to see if I could come up with my own simple explanation in a control system with feedback loops that sum the 3 factors. And like you pointed out, this subject is fairly esoteric so I came up with a few analogies (please correct any of my mistaken explanations).

First off, we should be aware that compensating amplifiers are not completely linear through their range, resulting in error conditions. Second, the feedback amplifiers do not instantaneous compensate with an offsetting feedback signal, it has both latency and hysteresis over time. Then there are other factors, such as noise that is often introduced into the feedback loop, where the feedback signal is not pure. Finally, while the formulas (algorithms) in a circuit attempt to simulate the real world, the forces of nature can frustrate the limitations of our simplistic approximation.

P – the PROPORTIONAL feedback is the main/primary offsetting (error-correcting) compensating signal. In the case of an automobile speed controller, it is the “error” between the existing speed and the desired speed we’ve set in the cruise controller. However, if the associated P error gain signal is set too high, the control circuit will overcompensate and oscillate or “buck” against itself. And if set too low, in the case of a human expecting the desired effect (joystick change) they will then overcompensate, causing hard to adjust or disfunctional controls

I – the INTEGRAL response or feedback is all about time. While we would like to think when the input signal is stable and steady after a new signal level was applied, the control circuit would immediately set itself to the new point without hunting. Unfortunately, its more like trying to get a large bowl of water to stop sloshing back and forth when holding it – the water wants to keep oscillating back and forth. Ditto on the accelerator gas petal for our car. When we want to go faster, we do not smash the gas petal to the floor. Instead, we slowly “ramp up” the throttle and adjust for the desired rate of acceleration to increase our speed. So the integral circuit controls the RATE of feedback over TIME to compensate for the hysteresis of the real world. Or to paraphrase Newton, “A body in motion tends to stay in motion – a body at rest tends to stay at rest.” So sometimes the algorithms in our imperfect circuit need to be tweaked to better compensate for the real world. Let’s take the cruise control on our car as an example. Going down the flat open road, everything is gong fine at 65 MPH… until we hit a steep hill. At this point, if we allowed the control feedback to provide 100 percent full gas throttle to the engine, we would end up overshooting the desired 65 and we might find ourselves going almost 70 before our feedback circuit caught up. Oops, now the feedback loop tells the engine to slow all the way down. But we are going up the steep hill and before you know it, one again we are going 60 MPH. So we adjust the “I” latency of the overall feedback so it does not INTEGRATE the feedback over time so it is not too fast nor too slow for our real-world contraption. Sorta like Baby Bear said – not too hard or hot, not too soft orcold, but just right :)
And for those with an electronics background, in essence we feed back a portion of the output signal back to the input through a variable capacitor that takes time to charge and discharge, delaying the feedback over time with the “I” changing the amount of capacitance.

D – the DERIVATIVE feedback signal is yet another compensating/offsetting signal response, however this one derives yet another offsetting signal from above. So far we know the “error input” (gas petal throttle, joystick controller, etc.) and the real-world load attempt to approximate the correct “P” and “I” feedback signals over time. We had hoped that over time the INTEGRAL feedback signal would always compensate for errors over time, but such is not the case. Simplistically, the “D” adjustment PRE-ACTS to make the the overall circuit better respond to the P and I feedback with the real-world load so the circuit does not overshoot. So in essence, once we have adjusted the P and I feedback circuits, we observe the behavior and tweak the D to further compensate for hunting that the P oscillation feedback did not adequately handle. Bottom line, first we handle the nasty oscillations, then we tweak to subtle drift and hunting.

For those who prefer a visual colorized representation of the PID effects, here are some nice graphs:expertune.com/tutor.aspx

1. Mark Younger

Hi Oscar & Michael
Great write up. Thank you for making this blog Oscar, and thank you for reiterating your POV here Michael. The visual descriptions really pulled it together for me! Now, off to try and get those oscillations during forward flight out of my TBS running Naze 32. “I” too high? Thanks again gentlemen.

18. Phill

Thank you for a very well written article on the quite complicated subject of PID tuning, still trying to iron out the wrinkles on my 4’s monster mini quad with acro naze32, I need my quad to be tuned solid for extreme proximity FPV, with the help of this I hope to get it perfect :)

1. Oscar Post author

Yes, without knowing what PID is doing exactly, it’s a bit like walking in the dark, you just increase or decrease the values mindlessly, which is really ineffective when it comes to tuning.