Many quadcopter software such as Betaflight and KISS allow users to adjust PID values to improve the flight performance. In this post I will explain what PID is, how it affects aircraft stability and handling, and I will share some simple techniques how to tune your quadcopter’s PID.
What Is PID in a Quadcopter?
Unfortunately, we don’t live in the perfect world, so we invented PID controller to help bring the real world closer to that perfect world.
PID is a function in flight controllers. It reads the data from sensors, and tells the motors how fast they need to spin. Ultimately this is how stability is achieved in a quadcopter.
PID stands for proportional-integral-derivative. PID controller is a closed-loop control system that tries to get the actual result closer to the desired result by adjusting the input. The error is fed back to the beginning, and the same process repeats.
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.
There are 3 functions in a PID controller, they are P, I, and D. Heuristically, these values can be interpreted in terms of time:
- P looks at present error – the further it is from it’s setpoint the harder it pushes
- D is a prediction of future errors, by looking at how fast you are approaching a setpoint and counteracts P when it is getting close to be at the setpoint
- I on the accumulation of past errors, it looks at forces that happen over time (if an axis constantly drifts away from a setpoint due to wind) it spools up motors to counteract it
If you are feeling extremely confused right now, it’s okay. You don’t have to understand the theory of PID and still be able to tune your quad’s PID, just jump straight to the “My Simple PID Tuning Process”. But if you are interested in how things work, keep reading :)
To have any kind of control over a quadcopter:
- We first need to measure the quadcopter’s angular rate (how fast the quadcopter is rotating in each axis)
- Knowing what the desired angular rate we want the quad to be, we can estimate the error
- We can then apply the 3 control algorithms to the error, to get the next outputs for the motors aiming to correct the error
That really just is the “academic description” of how PID controller works. In practice, each of these three parameters presents some unique effects to the craft’s flight characteristics and stability.
These parameters are numbers we can play around with. They are basically just the coefficients to the 3 algorithms we mentioned above. The coefficients change the influence of each algorithm to the output. Here we are going to look at what the effects of these parameters have to a quadcopter .
A multirotor can rotate in 3 axis, and for each axis there is a PID controller for it. That means we will have a separate set of PID coefficients for each axis (Pitch, Roll and Yaw), in total 9 values we can tune.
You don’t need to fully understand how PID controller works in order to fly a quadcopter. However, if you’re interested in the theory and background, here is a very interesting explanation of PID controller with examples. This PID tutorial is also very good and easy to understand for beginners.
The Effect Of Each Parameter
Generally, altering PID values (gains) have the following effect on a quadcopter’s behavior:
P determines how hard the flight controller corrects error to achieve the desirable flight path (aka where the pilot wants it to go, your stick input).
Think of it as sensitivity and responsiveness setting, it sometimes can affect your rate as well, your rate will feel higher if P is higher.
Generally speaking, higher 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.
You can lower P to reduce oscillations, but then your quadcopter might feel sloppy, so you need to play with I and D to compensate, begin to get the beauty of tuning? :)
I term determines how hard it holds the copter’s attitude against external variables, including wind and off-centered CG.
Think of it as the stiffness setting in the stall motion of your quadcopter.
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. When I is too low you might find yourself having to correct the quad’s flying path a lot more with your sticks, espeically when you play a lot of with throttle.
When I gain gets too high your quadcopter will be overly constrained by the I term, and it can start to feel stiff and doesn’t respond to your stick well. It’s similar to having a slower reaction and a decrease effect of the P gain. In more extreme cases with excessive I gain, the copter can even oscillate in a low frequency.
No ESC’s, motor’s or propellers are identical thus will provide different thrust when spinning in the same air. When you do a punch out and immediately lower your throttle, a motor can start and stop faster than other ones, this will cause an unwanted dip movement.
I gain can be used to “fix” these tiny details in your quad’s flight performance.
D gain works as a dampener and reduces the over-correcting and overshoots caused by P term. By adding D gain, you can “soften” the movement just like adding a spring to it, and it counter the oscillations caused by excessive P gain and can minimize propwash oscillations as well.
When D is too low, your quad will overshoot (bounce-backs) badly at the end of a flip or roll, and you will have the worse propwash oscillations caused by vertical decents.
However excessive D value can introduce vibration in your quadcopter because it amplifies the noise in the system. In the attempt to make your quadcopter fly smoother it will tell the motors to spin faster or slower in a very fast rate that the motor cannot keep up, and eventually cause motor overheat. The vibration will feed back into the flight controller, and make the situation even worse over time.
Another side effect of high D term is increased latency in the quad’s control and reaction, and makes it feel “mushy”.
Is PID tuning necessary?
PID tuning used to be necessary, but that’s not true anymore.
Modern flight controller software has sophisticated noise filtering and optimized algorithms. Quadcopters can fly very well out of the box on stock PID values unless you are using some very poor quality parts or the quad is badly built.
Nowadays knowing PID tuning makes the difference between “flying well” to “flying perfect”.
How to tune quadcopter PID Gains
- Always tune your quad in Rate Mode (aka Acro Mode)
- Make sure your quadcopter’s CG (centre of gravity) is right in the middle, CG has a significant effect on how good your quad can fly, and can be tuned
There is no right or wrong way of tuning PID, whatever works for you is the right way.
I normally start out by using default PID when I tune my quad. With modern flight controller software such as Betaflight and KISS, the stock values work very well for most setups out of the box.
I fly around, notice any undesired behaviour and then adjust PID accordingly. If the quad flies really badly with default PID values, for example, lots of vibrations, you can try tuning PID from low values. Just lower all the PID values half or more, to make sure they are definitely not too high to start with.
Every time when you adjust PID, you should ask yourself: “is it getting better or worse?” Find the point where it has the best flight characteristics before it goes down hill again.
Tune one axis at a time: first roll, then pitch, and finally yaw. And at each axis, I adjust one value at a time starts with P gain, then D gain, and finally I gain. You will need to constantly go back to fine tune the values as one value could affect the effectiveness of another.
Yaw Performance and PID
The hardest part to understand in PID tuning is the yaw axis. But it’s also the easiest part because you can leave it at default in Betaflight and your quad should fly just fine.
PID can help with yaw performance of your quadcopter to certain extend, but you have to understand there many other factors that can introduce yaw destabilization too.
one of the most common bad yaw symptons is, when you do a fast yaw spin the quad shoots up and doesn’t stay level.
Quadcopter’s yaw performance depends heavily on the hardware, i.e. motors, propellers and ESC. This hardware determines your maximum yaw rate (how fast you can spin around yaw axis), until you get destabilization.
To improve yaw performance, you can try the following.
- Using Heavier Propllers: Higher pitch propellers can generate more counter-torque at the cost of efficiency
- Increase Motor RPM, by using higher kv motors or increasing battery voltage
- Using ESCs with stronger braking – Yaw destabilization can occur when a down-spinning motor cannot decrease its speed as fast as an up-spinning motor increases
- Reducing motor distance can help increase yaw authority too: A 6″ frame flying 5″ props will have worse yaw performance than a 5″ frame with the same props.
If you cannot afford to mess around with hardware, the last resort would be to lower your yaw rate, or increase yaw expo, either way will slow down the yaw spins.
My Simple Tuning Process
P on Roll
Cruise around, with good P, the control should feel precise and the quad should follow your sticks very closely.
Try to do some sharp turns, if P is too low the quad would dip to one side, but when P is too high, you will get fast oscillations. When P is right, you should get minimum oscillations when doing sharp turns.
P on Pitch
Do a slit-S, and as you increase throttle to recover, pay attention to the pitch movement. If the quad pitch up more than it should, then P is probably too low. but if you get some fast oscillations then you need to decrease P.
Fine tune it until you get to a point where the quad would feel very responsive and nimble, yet there is no excessive amount of vibration. Also listen to your motors, twitching motors are a sign of excess P gain which might not be visible in the camera.
TPA is a setting to reduce the effectiveness of P gain as throttle increases.
Do a punch out and see if there is any fast oscillations, if so then increase TPA. Good TPA will give you a relatively smooth punch out. I personally wouldn’t use TPA higher than 0.4.
D on Roll and Pitch
Now when you do aggressive maneuvers like flips and rolls, you will probably notice some overshoots (aka bounce-back) at the end of the move. Increasing D gain can help reduce that.
Be careful because excessive D gain can make motor run hot, so use just enough to eliminate the bounce-back. A good amount of D gain will also reduce propwash. D gain too high would also cause fast oscillations at the end of a roll or flip too.
I on Roll
Bank your quad to the left or right and see if it’s holding the angle well. You want it to just stay in the same attitude as you release the stick. If the quad can’t hold the angle then I gain is too low and need increasing.
Do the same for pitching forward.
Your quad can drift in windy condition, so I gain needs to be adjusted depends on wind speed.
But I would recommend increasing I term just high enough to stay level, excessively high I gain can result in stiff and robotic feeling.
Anti Gravity Gain
Fly in a straight line and do some rapid punchouts to see if pitch stays the same angle, If the quad dips down then increase Anti Gravity. I found 3 to be a good value for most of my setup’s.
Yaw PID needs to be tuned separately. Default values usually work pretty well on all setups.
Spin yaw quickly and see how it stops, if you get fast oscillations then decrease P, but if the quad dips one side, then increase P.
Excessive Yaw P won’t cause as much vibrations like roll and pitch because yaw movement is much weaker on a quadcopter (lack of yaw authority). But look for any twitching and oscillations in the yaw axis. Also you might notice the quadcopter would tend to gain altitude when doing rapid yaw movements when P is too high.
When Yaw P is right the spin should be clean and snappy.
As mentioned, “I” is there to prevent drift, but excessive yaw “I” can introduce instability and actually reduces responsiveness. Yaw “I” should never be higher than is needed to prevent drift.
If nothing is wrong, just leave Yaw I at default.
D-Term Set Point Weight
If D SetPoint Weight is high, the quad would feel more locked in but more robotic as well. If it’s low, the quad feels more smooth but a bit loose and sluggish.
I personally prefer 0.6 which is a good balance.
Rate and Expo
Rates and expo are just as important to quad’s flight performance and control.
Not Every Problem is related to PID
Before tuning PID, here are a few things you should get right first with your quad.
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.
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.
“What’s your PID?” – Wrong Question!
It’s pretty meaningless to use someone else’s PID on your quad. Every quad is unique in some way: motor, propellers, ESC, FC, weight distribution, COG, frame… Even the wind speed and climates are different where we are flying, so the ideal PID values are going to be different too.
When to “Retune” 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.