Thread Tools
Jun 17, 2015, 12:20 AM
Registered User
Thread OP

Mini quad PID tuning from start to finish

If you are interested in donating to support my efforts, you can use this link to Paypal me:
I also have a Patreon here:

I've got what I think is a pretty good tune on my mini quad using Cleanflight's Luxfloat. But I'm not 100% happy with the tune, even though it's basically as good as I can possibly get it, so I'm going to give a shot at PIDC#1, which it seems like a lot of the pro pilots are flying. I thought I'd document it start to finish, since there are often a lot of questions about tuning.

My equipment is as follows:
  • RedRotor Strider frame
  • Fire Red 12 amp ESC with BLHeli 13.1 (Oneshot and Damped Light)
  • Sunnysky 2204 2300 kv motors running on 3S battery
  • HQ 6030 props
  • Naze32 with CleanFlight
  • looptime = 1600
  • All-up Weight = 550 grams

In case it's not obvious from the equipment, I am tuning a mini quad for acro-style FPV flight. The basic principles I'm describing would be the same for a camera platform style copter, but the intended flight characteristics would be different. For example, you would be much more concerned about stability than responsiveness in a camera platform, so you might have a higher I gain and a lower P gain. Also, I use flips and rolls to help bring out flight characteristics for tuning. You're probably not going to flip a 3 kg octo with a DSLR gimbal on it.

I'm running a custom version of CleanFlight 1.9 that Boris B is working on. The firmware has a low-pass filter on the D term. For dicussion on that, go check out the CleanFlight thread around post #9057. The takeaway of this is that my actual PID numbers will probably not be usable by people who aren't running that firmware, but I expect that the basic process of running up the tune will be similar to others, so hopefully it will be helpful to document it.

EDIT: The software filters created by Boris have been incorporated into CF 1.10. At the time that I created this thread, only dterm_cut_hz existed. CF 1.10 has gyro_cut_hz and pterm_cut_hz as well.

To re-iterate: unless you are running the identical setup to me, don't focus too much on my numerical values. Focus on the procedure. Focus on what happens when values are too low, too high, and just right. The quad's flight characteristics will always tell you, if you know how to interpret them. If you focus excessively on the numbers, you'll miss the forest for the trees, as the saying goes.
Last edited by joshuabardwell; May 11, 2016 at 10:19 AM.
Sign up now
to remove ads between posts
Jun 17, 2015, 12:29 AM
Registered User
Thread OP
EDIT: Step Zero. If your motors are not completely symmetrical, create a cmix for your layout according to these instructions. Cmix is not required, but if you have a cmix, it will cause your P gains to be much closer together on the pitch and roll axis. This makes it easier to tune, since you can basically tune both axes at the same time, instead of having to do each one separately.

Step One. I loaded the default PID values, then reduced D to 15 and I to 0.020. I believe that the first step should be to find a roughly correct range for P, without too much influence from I and D.

The default value for both pitch and roll P is 4.0. I have a custom mixer set up for my motor layout, so that should help the P gain value be approximately the same on both axes. So I will be changing both pitch and roll P gain together, at least at first.

I hovered the quad and listened/looked for high frequency oscillations. There were none. I increased P to 8.0. None. I increased P to 12.0. Now I could just start to hear oscillations in the motors, but I didn't see them, at least not from LOS. I might be able to see them in the FPV camera. I increased P to 16.0. The oscillations were more pronounced, but still not out of control. Bear in mind that this is just during hover. Actual flight would be more likely to bring out oscillations.

At this point, I have somewhat of a sense of what a flyable range of P values might be. I could hover the quad with reasonable control at P=4.0, and the quad didn't shake itself out of the air at P=16.0. This certainly is living up to PIDC#1's reputation for having a wide range of flyable values.

I set P down to 6.0 as a starting point. Tomorrow I'll take the quad out for some actual flying and work the numbers up further.
Last edited by joshuabardwell; Jun 17, 2015 at 10:23 PM.
Jun 17, 2015, 07:35 AM
Team AlienWarpSquad
Did you know that there are three Profiles that can have different PID Controllers, PID, rates and more? So instead of wiping out a flyable setup you just setup another Profile to try out new PIDC and setting while keeping the flyable setup.
Jun 17, 2015, 10:52 AM
Registered User
Thread OP
Originally Posted by waltr
Did you know that there are three Profiles that can have different PID Controllers, PID, rates and more? So instead of wiping out a flyable setup you just setup another Profile to try out new PIDC and setting while keeping the flyable setup.
Yeah. I haven't wiped it out--I've got the dump saved if I want to go back.
Jun 17, 2015, 03:09 PM
Registered User
Thread OP

Basic tuning of I gain

Previously, I roughed-in a set of basically flyable PID values by starting with default values and testing them in hover. I set I and D to a relatively low value because I didn't want them excessively affecting my tuning of P. It's worth pointing out that, until you get to very high values of I, there tends to not be as much interaction between I and P as there is between D and P. So, to some degree, it's most important to start tuning P with a relatively low D gain. It's relatively safe to tune I up to close to its final value because that's unlikely to affect your ultimate P gain. P and D counteract each other to some degree, so if you start tuning P with too high of a D, you can end up in a state where both P and D are excessive and the copter flies poorly, but it's hard to tell exactly why. So it's important to find the right value for P with D at a relatively low value, then work up D and P together.

Once I have P at a basically flyable level, my next step is to check I. I find it distracting if the quad is wandering all over the place while I'm trying to finish tuning P to the nth degree, so I like to tune I after I get P in roughly the right place, then after I tune I, I go back to tuning P and D.

My starting value for I of 0.020 is based on past experience with the MultiWii PID controllers. Lacking that experience, I might try setting I to half its default value. I found that a value of I=0.020 was actually pretty good, whereas I expected it to be too low. In order to demonstrate the effect of low I gain, I turned I down to 0.010. Here's the results:

PID Tuning Start To Finish - Effect of low I gain (0 min 23 sec)

One of my favorite tests for I gain is to punch out hard, then cut the throttle to about 25% and let the quad fall, then punch the throttle hard to arrest the fall. If the quad can maintain solid attitude during these maneuvers, I gain is probably not too low. In the video, I have the Blackbox trace for the pitch axis rcCommand up, so that you can see that I'm not moving the pitch stick at all during most of this maneuver. Watch how much the horizon changes during this maneuver, and also more subtly, during the level flight after the maneuver. There is a lot of drift.

I've chosen to isolate the pitch axis because my experience is that, at least with mini quads, you tend to need more I gain on the pitch axis than the roll axis. This has nothing to do with the quad being slightly shorter than it is wide, because I've got a cmix to compensate for that. Rather, this has to do with the distribution of mass relative to the CG. The mass is much more centered on the roll axis, whereas it is more spread out on the pitch axis. Therefore, more force is needed to move the quad along the pitch axis than the roll axis. The cmix takes care of this to some degree, which is why we should find that our P gains are roughly the same on both pitch and roll, but cmix doesn't address the issue entirely.

The next video shows I gain at 0.020. All other settings are the same.

PID Tuning Start To Finish - I Gain Closer To Correct (0 min 49 sec)

You should see that the quad holds attitude much better during the punchouts. It still tends to nose up a bit when the throttle is cut at the end of the punchout, and when the throttle is applied to arrest the fall. During normal forward flight, there is a small amount of wander, but it's much more noticeable in the playback than it is during flight. My gut feel is that this value is still a bit low, but getting close to the right value, at least for the pitch axis.

The bottom line is that if I notice my attitude changing when I didn't put in a stick input, or if I find that I'm constantly having to "nudge" the copter back onto course, that's probably an indication that I is too low on the axis in question.

EDIT TO ADD: Troubleshooting excessive I gain is a little harder because it's not as obvious (at least to me) when I is too high. Excessive I gain may sometimes manifest as low-frequency (2 Hz or slower, approximately) oscillations, but not always. Excessive I gain may also manifest as a feeling of "stiffness" in response to stick inputs. If the copter feels unresponsive on an axis, and you are sure that P is high enough and your rates are high enough, you may have excessive I on that axis. If you are already good at coordinating your turns, but you find that the copter seems to want to keep turning into a turn after you intend to end the turn, or after you end the turn, the copter seems to want to swing outwards--that may be excess I gain on the yaw axis, for example. Another example of possibly excessive I gain is that you finish a move and, maybe 1/4 second later, the copter adjusts its attitude without you moving the stick. This may be the I term trying to correct for previous error. The signature of this type of correction is that the copter will adjust its attitude, like it might pitch up slightly, and then it will stay there. It won't oscillate. The I term will unwind its error and then be satisfied and stop.
Last edited by joshuabardwell; Jul 03, 2015 at 09:11 PM.
Jun 17, 2015, 05:13 PM
Registered User
Thread OP

Working up P gain

Next I explored P gain some more. I established the approximate bounds of the P parameter in hover just to try to get a basically flyable quad. Now I'll do the same thing in flight to get a more realistic perspective.

I started with P=6.0 and used in-flight adjustments to increase P. Basically, I flipped the "increase" switch up and just left it there while I watched for oscillations to start. I have to say that PIDC#1's reputation for having a wide tuning range seems to be holding up. I was watching carefully for oscillations to start so I could quickly flip the switch back without rapidly losing control. But the onset of bad behavior happened very gradually, with lots of warning before things got bad. In fact, I ended up landing halfway through to check the values because nothing seemed to be happening as I just pumped the P gain through the roof.

PID Tuning Start To Finish - Working Up P Gain (1 min 39 sec)

Comments. Bear in mind that P is slowly and continuously increasing throughout the whole video.
  • 0:04 - You can see some oscillations, but this may just be buffetting from the wind. It's hard to judge whether this is excessive P without more context. EDIT: Based on later investigation, I think this is probably excess vibration. See later posts for details.
  • 0:10 - Lower throttle, the quad begins to fall. More oscillation, but it's low-frequency oscillation. This may also just be buffeting from descending into the quad's own prop-wash, and/or from the wind. Also, P-gain oscillations tend to happen when you increase throttle, not when you decrease it. This type of low-frequency oscillation is sometimes symptomatic of excess I gain, but my experience with tuning leads me to believe that I=0.020 is not high enough to result in this behavior. We have only just tuned I to the point where wander goes away. It's unlikely that the "good" range of I values is so narrow that we've over-shot the mark into excess I gain. EDIT: Based on later investigation, I think this is probably excess vibration. See later posts for details.
  • 0:12 - Punch throttle. Throttle sounds basically smooth. No visible oscillations.
  • 0:21 - Punch throttle. Now you can start to hear some oscillations in the motors for the first time. Compare with the punchout at 0:12. Still no visible oscillations, though, but at this point, P is probably too high. At the very least, one would want to add some TPA.
  • 0:38 - A drop-and-catch. The oscillation in the roll axis as the throttle is increased looks a bit like excess P.
  • 0:41 - Another punch-out. Now there is some obvious visible oscillation as the throttle increases. Also, listen to the oscillation in the motors.
  • 0:47 - Much more obvious P-gain oscillation as the quad falls.
At this point, I landed and checked my P gain value. It was P=10.0. Just for kicks, I increased P to 15.0 and flew it. The quad was still flyable as long as I was gentle, but you can see small oscillations pretty much the whole time. I started increasing P, and the oscillations immediately started to make the quad hard to fly. If you look at the flight from 0:52 forward, this is an example of a quad that a beginner might think was flying okay, but P is actually MUCH too high. You can hear the motors oscillation even during gentle maneuvers (e.g. the right turn at 1:04).

At the end of the video, when P=15 and above, you can clearly see high frequency oscillations, but an important point to make is that by the time you clearly see the oscillations, P is already way too high. Before you get to obvious visible oscillations, you are getting micro-oscillations that are affecting flight characteristics and motor efficiency. The earliest sign that P is starting to be too high will be an audible oscillation in the motors especially at high throttle. For whatever reason, it's easier to hear this than it is to see visible oscillations in the camera. These micro-oscillations can easily be seen in a Blackbox log, but not everybody has Blackbox, so listening for smooth motors at high throttle is the next best thing.

SIDE NOTE EDIT: Why is the fall at 1:12 so smooth when previous falls were all wobbly? You would think that the much higher P gain would result in worse oscillations. One possible explanation is that the quad was moving forward more during the 1:12 fall, so it was not falling into its own prop-wash.

As a general guideline, I agree with Alex / IBCrazy's suggestion of setting P equal to about 50% of the point where oscillations occur. When I first heard this guideline, I thought it was way too low, because the copter can appear to be flying pretty well at 80% or even higher of the oscillation point. But I have been digging around in Blackbox logs pretty seriously for the last couple of weeks, and it's obvious that excessive P is still affecting flight negatively past the point where obvious oscillations stop occurring.

In summary: We started to see very minor oscillations even at P=6. Oscillations under extreme flight conditions became obvious somewhere around P=9 to 10. Oscillations became unavoidable even under normal flight conditions somewhere around P=16. If we use the 50% guideline, then our target for P is probably going to be somewhere between about 4.5 and 8. I saw the beginnings of oscillations even at P=6, but they weren't too bad, and there were no oscillations during gentle flight.

Remember that we are doing this testing with an intentionally low D gain, and increasing D will dampen these oscillations to some degree. Therefore, one way to proceed is to intentionally set P a little bit high and then use a combination of D and TPA to remove oscillations under more extreme conditions. So probably what I will do is set P to something like 6.0 to 8.0, and that will be just a tad high, and then I will start working up D and P together, with increased D getting rid of the oscillations and then increased P putting them back again, until I get D and P where I want them. For the time being, I'm intentionally leaving TPA out of the equation. That's going to be the last thing I tune, at least in part because my previous PID controller didn't use it, so I'm not as familiar with it.

I also want to remind everybody that I am using Boris B's custom firmware, with the low-pass filter on the D term. As a result, my D term is going to be more effective than people flying the stock firmware. On the stock firmware, excess D values result in amplification of noise in the system. If D is too high, it overwhelms the PID sum and makes it jump all over the place. So you have to keep your D values low enough that D is not as effective as it could be. The tuning procedure I'm using is the same as I would use with any PID controller, but the outcome is probably going to be that I have a slightly higher P and D value than would work well on the stock firmware.
Last edited by joshuabardwell; Jun 18, 2015 at 07:36 AM.
Jun 17, 2015, 05:18 PM
Registered User
Thread OP

Check and adjust rates

My next step is to check and adjust my rates. With P and I at close to optimal values, the quad is flyable enough that I feel confident doing flips and rolls. I like to judge my rates by doing full-deflection flips, rolls, and pirouettes, and seeing if they are as fast as I want them. Then I adjust expo to give me enough softness around the center stick that I can still do precision flying.

Remember that with PIDC#1 and #2, the RC rate and the Pitch/Roll rates are simply additive. The only purpose of the Pitch/Roll rates is to let you adjust pitch and roll rate separately. On the other PID controllers, the P/R rates act as a "super expo" that decreases the PID constraints as the stick moves away from the center. The MW documentation summarizes this as: If you want a copter that is super twitchy all the time, use high RC rate. If you want a copter that is gentle at center stick and then does super fast flips and rolls when you slam the stick, use a lower RC rate and higher P/R rate.

Once I have my rates where I want them, I will begin to adjust D and P together by looking for bounceback or oscillation at the end of flips and rolls. But I need my flips and rolls to be the right speed before I do that.
Last edited by joshuabardwell; Jun 17, 2015 at 10:06 PM.
Jun 17, 2015, 07:57 PM
Team AlienWarpSquad
Great write up.
Jun 17, 2015, 10:46 PM
Registered User
Thread OP
The last flight of today was a slightly more aggressive check-ride, to give me a better feel of how my decisions are turning out. I ended up using a P value at the higher end of the acceptable rage. My PIDs were 8.0 / 0.020 / 15. Here's the result:

PID Tuning Start To Finish - Checking Initial P/I and Rates (1 min 25 sec)

The first thing you should notice is that there is constant oscillation throughout the flight, even during relatively gentle maneuvers. The motors sound reasonably smooth during many parts of the flight, but you can hear them oscillating during others. Visually, however, the result is near motion-sickness-inducing.

My takeaway is that P=8.0 is too high. EDIT: This turned out not to be the correct conclusion. Read on. It might be tempting to stay at this value and use increased D to tame it, but I don't think that's what I want to do. I don't want P to be like a wild stallion, constantly having to be reigned in by D. I want to find a P value that is smooth during gentle flight, and maybe has just a bit of oscillation to tame with either D or TPA during more extreme maneuvers. We can absolutely achieve responsive, precise flight without having to push P to extreme levels where it is constantly at risk of causing oscillations.

If we go back to the 50% guideline, it shouldn't be surprising that P=8.0 is too high. Remember that oscillations started to be really obvious around P=9.0 to 10.0, and oscillations were very prevalent around P=15.0 to 16.0. So P=8.0 should be thought of as likely to be near the upper end of possible final values. Given that we have a low D gain and no TPA, it's expected that we can't get good results with P set this way.

I want to point out that the oscillation wasn't really obvious through the FPV goggles. Maybe it's because of the low resolution of the standard-def feed, or maybe it's just because I was focused on flying and not paying as much attention to video quality. This should reinforce to you the usefulness of reviewing HD video recorded on-board, in addition to real-time feedback from the FPV feed.

The flight ends with a roll at 0:49 in which I conclude that my rates are MUCH too low. I turned RC rate down from 0.87 to 0.60 when switching from PIDC#2 to PIDC#1, because I didn't want any surprises. I've since turned it back up to 0.80. EDIT: I have since turned it up to 1.0, with P/R rates of 0.5 for a total of 1.5. My previous rates on PIDC#2 were around 1.3. I don't think I've suddenly become a faster flyer; I just think PIDC#2 doesn't handle rates exactly like PIDC#1.
Last edited by joshuabardwell; Jun 19, 2015 at 11:23 PM.
Jun 17, 2015, 11:41 PM
I Like Coffee ^_^
PokkaGold's Avatar
Enjoyed reading these. Such detailed writeups.
Jun 18, 2015, 12:57 AM
Registered User
Thread OP
I have been giving some more thought to my last flight, and I'm not confident that the bounciness seen in this video is because of excess P gain. This looks more like a "bounciness" or "driving over a rough road" rather than the kind of hard and fast oscillations caused by excess P gain. It's kind of similar to the jostling that was seen during the low-throttle drops during the P gain tuning.

"Slow wobble" is the typical symptom of excess I gain, but as previously discussed, I don't think there's any way that we've raised I high enough to cause problems. And this doesn't exactly look like the kind of wobble you get with excess I. The closest thing I've ever seen to this kind of bounciness is a time when I had wildly excessive D gain, but as with I, there's no way we're into that territory right now.

The remaining cause of unexplained twitchiness is excess vibration getting into the controller. Boris B's modification to the PID controller involves turning off the low-pass filter that is normally present on the gyro. This allows more vibration to get into the PID algorithm, but Boris's adjustments are supposed to make up for that, and the reduction in latency that comes from disabling the filter is supposed to result in overall better performance. Part of me is wondering whether the type of disturbance seen in this video is the result of vibrations from the gyro getting into the PID algorithm. In other words, I'm wondering whether my quad is not responding well to the reduced low-pass filter on the gyro. I'll continue to explore and find out.

EDIT: The similarity between this and excess D gain may not be an accident. Excess D gain causes problems by amplifying noise that gets into the system. So in one case, we have the low-pass filter disabled, so noise is getting into the system. In another case, we have the low-pass filter enabled, so less noise gets into the system, but then a crazy-high D gain amplifies the noise that does get through. In both cases, the effect on the flight characteristics could be expected to be similar.
Last edited by joshuabardwell; Jun 18, 2015 at 01:12 AM.
Jun 18, 2015, 02:20 AM
Registered User
great stuff here...learning loads
Jun 18, 2015, 03:10 AM
Registered User
Boris B's Avatar
Can you include some more information in your blackbox video or log perhaps, cause you need to see what part is causing those vibrations. My initial thought......It looks like a very very noisy gyro/quad.
Try lowering gyro_lpf till that is gone of fix exessive vibration issues on the quad.

Best is to see separate PID's on all axis and gyro and perhaps also accelerator data in the same view.
I use something like this:

Zoomed out

Also what mode are you flying and
Jun 18, 2015, 05:05 AM
Registered User
Thread OP
Here's the log file. Flying rate mode. I've also attached a screen shot for those who may not have the viewer.

Not sure what could be making this quad extra noisy, though. I mean, I don't hand-balance my props, but I think most mini quad pilots don't.

I will give a try at reducing gyro_lpf. Would you think the main_cut_hz is still worth using, even if I have to bring gyro_lpf all the way back down to the default value of 42? Presumably, this would increase latency, but it seems like there still might be some benefit in making the D term less noisy. Or is reducing latency likely to have more advantage?
Jun 18, 2015, 05:28 AM
Registered User
Boris B's Avatar
Originally Posted by joshuabardwell
Here's the log file. Flying rate mode. I've also attached a screen shot for those who may not have the viewer.

Not sure what could be making this quad extra noisy, though. I mean, I don't hand-balance my props, but I think most mini quad pilots don't.

I will give a try at reducing gyro_lpf. Would you think the main_cut_hz is still worth using, even if I have to bring gyro_lpf all the way back down to the default value of 42? Presumably, this would increase latency, but it seems like there still might be some benefit in making the D term less noisy. Or is reducing latency likely to have more advantage?
I am on my mobile and cant view the logs now, but from looking in the screenshot I can see D is doing a good job and is being filtered.
The P seems to be jumping all over the place together with the gyro.

It is always good to filter D even with gyro of 42hz.
But you could really look to see where this huge noise is coming from.
Test motor by motor in motor tab with props on and see the differences.

Also lower the P to very low values for example and see hoe the gyro is behaving with lower P.

Quick Reply

Thread Tools