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