PID Tuning and Quadcopter Flight behaviour

We explained “what Quadcopter PID is” in our last article, and in this tutorial we will explore the effect of PID tuning for a quadcopter. This does not only apply to quadcopters, but also other multicopter configurations too such as the tricopters and hexacopters.

PID Tuning Explained in Simple Terms

As explained previously, a PID 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.

This can relate to something we are familiar with: in a multirotor, PID controller takes data from sensors and compare that against the expected values. The difference would be what we call an “error”. And so the flight controller alters the speed of the motors and hopefully the “error” will get smaller next time. And this is how PID stabilize a quadcopter.

As you might already know, PID has 3 parameters, 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

Still don’t get it? That’s okay.

Seriously, it’s not necessary to understand how PID work in order to be a good Quadcopter PID tuner. Read on…

PID Tuning in Practice

Here we will try to relate PID to how your quadcopter flies in the air. Hopefully it will give some your hints on how to tune PID better, and understand how each parameter affects quadcopter flight characteristics.

What is P term?

P is the main value you worry about, which determines the stability and handling. You can actually leave I and D values at 0 and your aircraft will still fly.

The higher P gain, the harder it tries to stabilize the copter. Generally speaking, high P gain means sharper control while low P gain means softer control. But if P is too high, the quadcopter becomes too sensitive and over-correct itself. Eventually it will cause overshoots, and you will have high frequency oscillations.

What is I term?

Very simply, the I term helps to hold the copter’s attitude against persistent bias (e.g. off-centered CG) and external variables (e.g. wind). Your quadcopter would feel stiffer with higher I gain.

 

 

Normally default I gain works pretty well on most modern FC software and hardware. But if you notice some drifting without user command, then increase I term. But when I is too high, you might notice slow vibrations at punch-outs (high throttle ascend).

What is D term?

D gain is like the opposite of P. If P was a hand to keep pushing the machine back to a stable position, then D was 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, and it remove the P gain oscillations.

When you begin to have slow vibration by raising P gain, don’t rush to bring it back down. Try to add a bit more D gain see if it can fix it. D gain allows higher P as it reduces some of the P term vibrations.

If you see some bumpiness or slight oscillations in your acro moves, or overshoots at the end of a flip and roll, give higher D also helps. D term also helps reducing propwash oscillations.

However too much D is not good, because it amplifies noise in the system, and cause oscillations in the quadcopter and motors overheat. Also your copter would feel sluggish and mushy with excess D value.

How To Enhance Flight Characteristics Apart from PID?

Vibration

Not all oscillations are caused by high P term. You need to eliminate vibration sources as much as possible on your quadcopter before tuning PID. For example balancing of motors and propellers, frame rigidity etc. With a vibration free copter, you can set a much higher P gain, and smoother machine.

Center of Gravity (CG)

You want quad’s center of gravity to be right in the middle, where the 4 motors intersect on a horizontal plane.

What happens when your CG is off-centered? Some motors will have to work harder than others, not only it might cause motors overheat, it will also affect stability.

For example in a quad, maybe your LiPo battery is too far back, it shifts the CG to the back. And now the 2 rear motors have to work 100%, while the front 2 motors are only at 80%. If you want to push harder in throttle, you can’t! You quad might oscillate back and forth and won’t deliver any extra power because the rear motors have already maxed out.

Mass Distribution

Quadcopters with more centralized mass tend to feel more precise, snappy and responsive. When there is more mass on the outside of a quad, it takes more force to rotate it. Also due to the angular mass and inertia it’s harder to stop it from rotating.

That’s why X frames (mini quad frame shape) have taken over the mini quad market from H quads when people realized the benefits. Apart from frame design, lighter motors and ESC also helps reduce rotational inertia.

When to “Re-Tune” your PID?

Almost all the parts in your copter has some effect on your PID. So when you swap out components for a different brand/model, you must re-tune your PID gains. For example Frame, Propellers, Motors, ESC’s etc…

In Betaflight and Cleanflight, Looptime also has a great impact on your PID values. Once you changed Looptime make sure to return PID.

34 thoughts on “PID Tuning and Quadcopter Flight behaviour

  1. Mitch

    Good article, thanks. I have a QAV-R build and just learning to adjust PIDs and improve my ACRO flying. I have it adjusted (using dronin) so that i can bank left or right, release the stick and it stays at whatever angle I put it at. So far so good. When I am in a left bank for example at 20 degrees and apply left YAW to swing around to the left, the drone levels out (starts tilting right) and if I don’t apply left aileron stick, it will continue to go past level and angle to the right, while still maintaining a left turn as I am still applying left yaw. Is it normal in ACRO mode to have to apply more left aileron in a left banking turn to counter the yaw? Hope this newbee question makes sense. Mitch

    Reply
  2. Harish

    Hello,

    I am using Pixhawk for my FPV and when I did the calibration and started the operation, what I found is, it just rolls on one side when I increase the throttle. I calibrated around 5 times and the problem remains the same. I checked the motor by motor tester and it is working fine along with ESCs. What should I do? Is it a problem of ESC or PID or PixHawk calibration or something else?

    Please guide me in this case.

    Thanks and Regards

    Reply
  3. 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.

    Reply
  4. 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.

    Reply
  5. 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

    Reply
  6. 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.

    Reply
    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 :)

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

        I have already tried scouring youtube and not found anything yet.

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

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

    Reply
  8. 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?

    Reply
  9. 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

    Reply
  10. adi sirfefa

    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

    Reply
    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…

      Reply
  11. Adeel Khan

    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.

    Thanks in Advance.

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

      Reply
  12. 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.

    Reply
  13. 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?

    Reply
  14. 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!

    Reply
    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 :)

      Reply
  15. Mohd Fadly

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

    Reply
  16. 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

    Reply
  17. 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 ?

    Thanks a lot for your answers :)

    Guilhem

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

      Reply
  18. 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.

    Reply
  19. 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

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

      Reply
  20. 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 :)

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

      Glad it helps you :)

      Reply
      1. pail

        Hi oscar
        I’m having problems with my cc3d ZMR when I push the stick forward and then center the stick it still continues to go forward what can I do to make it stop and hover after it centers I’m using the Taranis radio Thanks

      2. seth

        on open piolet and cc3d i increase the D value that seems to increase the stick response..the exact oposite from what you explained on D.. seems the softness comes with lower D value?

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you Robot? *

I don't look at blog comments very often (maybe once or twice a week), so if you have any questions related to multirotor please post it on this forum IntoFPV.com... You're likely to get a response from me faster on there.