In this tutorial I will share how I use Blackbox to tune filters and PID on a Betaflight FPV Drone. I will be using PIDToolBox as the primary tool for filter and PID tuning, with Blackbox Explorer as the secondary tool for Feedforward and general troubleshooting.
Disclaimer: This guide is meant for informational purposes only. The author holds no responsibility for damages resulting from actions taken by the readers.
You can totally tune your quad to fly decently without Blackbox as I described in this post, but Blackbox gives you the full insight into what’s really going on with the drone and allows you to unleash its full potential. Things like noise filtering and tiny overshoots you can only see clearly in Blackbox. If you are a perfectionist or just someone who like to tinker, this is going to be the tutorial for you.
If you are new to Blackbox, make sure to check out the Blackbox for beginners tutorial.
Table of Contents
Using Blackbox to tune our FPV drone, we want to achieve two main goals:
- More effective use of filters: use as little filtering as possible to minimize delay, but just enough to keep the noise down to an acceptable level
- Optimized PID gains and related settings to get our drone to fly more precisely and responsively
0. Hardware Checklist
- Choose an FC stack that comes with rubber grommets (aka gummies), soft mounting is great for both durability and noise performance (vibration dampening).
- Use metal screws for the FC stack, avoid nylon/plastic screws/standoffs/spacers as they are easy to break and more likely to create vibrations. If you need spacers, use the soft silicone ones. Using lighter titanium screws can save a few grams (see post).
- Locking the stack screws firmly in place with a metal nut before mounting the 4in1 ESC. If your frame have pressed insert nuts then there’s no need to add another nut. This will prevent the stack screws from wiggling and creating vibrations. Tighten them by hand first, then give a final squeeze with the wrench/screwdriver.
To secure the whole FC stack, you can use 4 plastic nuts. Tighten the nuts by hand, so that the gummies are not excessively crushed, this allows the soft-mount to work effectively.
1. Blackbox Recording Settings
Select the following settings in the BlackBox tab:
- Onboard Flash or SD Card
- Since we are tuning filters we want to log at 2KHz (or 1.6KH for BMI270 Gyro)
- Select “GYRO_SCALED” in debug mode to record unfiltered gyro signal
2. Disable ADC filter in your OpenTX/EdgeTX radio (System->Hardware). This will reduce latency.
3. ESC settings:
I have a post explaining the best BLHeli32 settings. Here’s the summary (for 5″ drones):
For BLHeli_32 ESC:
- Rampup Power 40%
- Motor timing 16
- PWM Frequency:
- Low “16KHz” (or whatever the lowest is)
- High “By RPM”
- Alternatively, you can set both LOW and HIGH to fixed 24KHz or 48KHz. 24Khz is better for prop wash handling, 48KHz is better for smoothness, but “By RPM” offers the best of both worlds
For BLHeli_S ESC, try flashing Bluejay (48KHz) which is better for smoothness and efficiency especially for micro size drones. Some prefer 24KHz because it has slightly more torque and better for prop wash handling, but if you enable thrust linearization later on it should make up some of that lost torque when using 48KHz, so you get the best of both worlds.
Bluejay firmware also allows bi-directional DShot, which is required for various features in Betaflight such as RPM filter and Dynamic Idle.
3. Flash the latest version of Betaflight firmware (currently 4.3.1) to your flight controller and leave PID/filter settings at default. Enable Expert Mode in Betaflight Configurator, this will give you all the available sliders and options on the PID Tuning page.
Regardless the FC processor, if it has a BMI270 gyro you can only run 3.2KHz PID Loop Frequency and DShot300 ESC protocol.
For any other gyro, on an F4 flight controllers, you can run 4KHz and DShot300. On an F7 or H7 FC, you can run 8KHz and DShot600, or 4K and DShot300 if you wish. Disable any features that you might not need such as Barometer, LED_Strip, Soft Serial etc in the Configuration tab.
4. In the Motors tab, enable Bi-directional DShot.
Almost all modern ESC support Bi-directional DShot. I have a tutorial on how to enable RPM filter. For BLHeli_32 ESC it works out of the box, but if you have BLHeli_S ESC, you need to flash Bluejay firmware (tutorial) first.
To check if Bi-directional DShot is working properly, run the motors in the Motors tab (without propellers!) and see if the error rate (E) remains at 0% . If this is not the case, try again with a slower DShot protocol such as DShot300 or even DShot150. If none of these protocols give you 0% error, then you might just have to disable Bi-directional DShot.
Once you have Bi-directional DShot enabled, you can then enable RPM filter, this is probably the best filter in Betaflight.
5. Load the appropriate RC_Link preset.
Different RC links require specific RC smoothing and feedforward configurations due to the different packet rate and packet interval in order to avoid problems with Feedforward. My favourite RC link at the moment is ExpressLRS, check out what radio gear I use here.
By loading the suitable RC_Link preset, Betaflight will apply all the necessary config for you automatically. Don’t forget there are a few more options to pick before loading the preset, especially flying style, for most people it would be Freestyle.
If you are using Crossfire, it’s best to lock the packet rate to either 50Hz (longer range) or 150Hz (lower latency). You can do this in the TBS Agent Lite LUA script.
6. Lower TPA
In the PID tuning tab => Rate Profile, set TPA break point to 1750, this is the throttle position when TPA start to work. We don’t want TPA to mask all the oscillation issues during tuning. We will tune TPA later if we have oscillation issues at high throttle range.
How to use PIDToolBox and Blackbox Explorer?
I will be using both PIDToolBox (PTB) and Blackbox Explorer (BE) in my PID and filter tuning.
- I already talked about how to use BE here: “the basics of how to use Blackbox in Betaflight“
- Download and install PTB here: https://github.com/bw1129/PIDtoolbox/releases/latest/
- This page explains how to use PTB: https://github.com/bw1129/PIDtoolbox/wiki/PIDtoolbox-user-guide
PIDToolBox will be our main tool, it’s by far the most powerful Blackbox tool available. It allows you to compare multiple logs side by side on the same window, so you can see the effects of the changes you made in an instance. The Step Response tool is super simple and useful for tuning PID. Another great thing is the unit on the Y axis in the spectral analyzer (in decibel), which allow for more accurate and objective comparisons. PTB also tells you the estimated filter delays which is useful.
The main downside of PTB in my opinion is speed. It loads quite a bit slower and it just isn’t as intuitive to use as BE. That’s why I mostly use BE if I only have to look at one log, or for general troubleshooting because it’s just faster to use. But for noise and filter tuning, PTB is definitely the way to go.
Hardware plays a big part in how much filtering is required. For example, a well designed frame without bad resonance issues, a set of well balanced propellers, new motors with smooth bearing, all contribute to a clean quad that requires little filtering.
Performing flight for noise analysis
Take off, fly forward with as little throttle as possible and minimal yaw/pitch/roll stick inputs.
Perform a “throttle sweep” – slowly ramp up throttle until it reaches 100% over 5-10 seconds. Vibration frequency caused by the motors can change with throttle level, this test will show all the vibrations across the whole throttle range as well as where the frame resonances are.
Repeat this 2-3 times, then land and disarm.
This is what a typical throttle sweep log would look like (see the bottom bar for throttle changes).
Understanding Gyro Frequency and Delay
Now load the log in Blackbox Explorer, and open “Gyro_Scaled” (unfiltered gyro signal) in the analyser. It’s important to remove the take off and landing parts of the log (so those vibrations don’t throw our analysis off) by pressing the keys “i” and “o”.
Here’s a breakdown of the raw gyro signal frequency graph from a typical 5″ FPV Drone:
- Under 20Hz: movements of the drone reacting to RC commands
- Between 20Hz – 100Hz: propwash, oscillations from bad PID (e.g. oscillations caused by excessive D gain), problematic ESC config and bad RC link related settings etc…
- Between 100Hz – 250Hz: frame resonance or loose parts
- Higher than 250Hz: noise from motors and propellers
Everything below 20Hz is “good” drone motion reacting to the sticks.
Between 20Hz and 100Hz is the undesired vibrations such as oscillations and propwash. As a general rule of thumb, you want to see little activity in this frequency range. Having some is normal but too much means you have an oscillation issue that needs to be addressed. Generally we try to avoid filtering below 100Hz because those are real motions of the drone, that we either want to work with or work against. Filtering in this low frequency range can actually make things worse because it introduces tremendous amount of latency. Analyzing the spectra under 100Hz can give you insight into vibration or mid throttle oscillation issues, and how well the copter is handing propwash.
We don’t care about anything above 1000Hz as these have little effect on our drone, what we want to focus on filtering is the noise between 100Hz and 1000Hz.
Perhaps not intuitive, but over-filtering can actually cause oscillation to show up as noise in the sub-100Hz spectra. That’s because filtering creates something called phase delay. When the quad tries to make a correction to the error, the response is too late due to delay and is actually counter productive. It makes the error worse and creates a feedback loop, so the drone starts to oscillate.
That’s why if we use less filtering, noise issues under 100Hz can sometimes actually get better, because latency is reduced and the quad can react faster to correct PID errors. Using less filtering also allows you to push PID gains higher which makes your quad track setpoint better and helps combat propwash.
You can find out how much delay is added to the Gyro signal due to filtering, by plotting Gyro and Gyro_Scaled and measure the gap between them.
In PTB, it automatically estimates the delay caused by gyro filtering and D-term filtering (see top right corner of the first graph in second column).
My general filter strategy is to kill motor bands using RPM filter, crush out frame resonances with dynamic notch filters, then reduce the ambient noise floor with Gyro and D-term lowpass filters. I will be tuning filters in this order:
RPM Filter => Dynamic Notch Filter => Gyro Lowpass => D-term Lowpass
We want as little filtering as possible to minimize latency, but at the same time to have just enough filtering so that we don’t burn our motors when we are flying home with a bent prop. One can certainly play safe and apply more filtering than needed, but when over-filtering, the drone would feel disconnected and slow to react due to the increased delay. It makes propwash worse too. So there’s a balance we want to strive for.
Apart from checking Blackbox logs, motor temperature is another useful determination in filter tuning. When motors get too hot is usually an indicator of pushing the filtering too far.
Pro Tip: Hot motors – how hot is too hot?
As a general rule of thumb, if you pinch the motor and can’t keep your fingers on it more than a few seconds, that means it’s too hot and you are probably pushing your setting too aggressively.
How clean is your build?
Before we begin, check if you have a clean build. Perform a throttle sweep as we previous described.
Load the log in PIDToolBox, click Spectral Analyzer. Select just “Gyro prefilt” (the raw unfiltered gyro signal, “Gyro” is the filtered signal), and hit Run.
The default filter settings in Betaflight are fairly conservative, most builds should be able to reduce filtering from there. If your quad is already noisy with default filter settings, instead of increasing filtering you should look for possible mechanical/electrical issues. Use capacitor at the ESC input power, make sure all screws are tightened up, use fresh new props etc.
On a clean 5″ quad, there should be little activity between ~50Hz (the quad’s movements) and ~200Hz (motor vibration). If you have quite a lot of noise in this region, it could be electrical noise (perhaps gyro input power is too noisy, or it requires extra capacitor at the ESC input power), or maybe mechanical (e.g. a wire is hitting the gyro). It would be harder to get optimal filtering in this condition.
As suggested by the author of PIDToolBox, it’s ideal to have the overall noise floor below -30dB above 50Hz. For D term, it’s ideal to have the overall noise floor below -10dB. From looking at the noise level in these regions can really tell how smooth your quad flies. The noise level has to do with how well the drone is built, how good the hardware quality is, and sometimes you might just have a noisy Gyro.
If your quad is noisier than this (e.g. there’s a peak in the middle above 0dB), then you will need more filtering. It’s not the end of the world, it just means the latency will be higher and you won’t be able to push PID gains as high.
Tuning RPM filter
RPM filter is one of the most effective filters in Betaflight. Both BLHeli_32 and BLHeli_S ESC support RPM filter now, so make sure to enable it if you haven’t already. On a clean build, RPM filter and Dynamic Notch filters will be doing most of the work, and we can disable a lot of other filters.
Load the log in PTB, click Spectral Analyzer and click “Freq x Throttle“.
Under “Presets” select “Gyro Prefilt, Gyro, Dterm Prefilt, Dterm” and hit Run. This is what I call “heatmaps”.
I will break it down in the below graph:
- Close to 0Hz, the very bright horizontal line at the bottom (1) is the drone’s motion reacting to the sticks
- Around 200Hz, the horizontal line (2) is the frame resonance. Its frequency does not change regardless the throttle position, but it’s the strongest where it intersects with motor band
- The diagonal line (3) is the fundamental motor band, usually the brightest. (4) and (5) are the motor band harmonics, they tend to be quite dim and harder to spot. Try adjust the scale and see if they show up more clearly
We will use RPM filter to take care of the motor bands.
Tuning RPM filter basically means to optimize the number of RPM harmonics used and set the highest possible “Min Frequency” based on the starting frequency of the motor band.
Fewer RPM harmonics and Higher min freq = less filtering and less latency.
Click the “Data Cursor” tool, and click on where the motor band starts, it will tell you the exact frequency. Confirm in roll/pitch/yaw graphs, and take the lowest frequency.
Here’s an example of me tuning my new Source One V5 build:
- On the left, is the default RPM filter: 3 Harmonics with min frequency of 100Hz
- On the right, 2 Harmonics with min frequency of 160Hz
By reducing one harmonics, you can perhaps see there is a tiny bit of noise left unfiltered from the 3rd motor harmonics.
Although it’s pretty weak, it can still get into D term and be amplified. Let’s check the Dterm heatmap below on the right, as you can see, a tiny bit of gyro noise can become pretty bad Dterm noise.
Therefore, it’s probably best to have 3 harmonics in RPM filter in this example.
The other thing you might have noticed is some noise around 116Hz left unfiltered because we raised the min freq to 160Hz. To address that, we have to lower Min Freq.
Here’s a comparison of gyro signal after filtering using 3 different settings:
- left: 2 harmonics 160Hz min freq
- mid: 3 harmonics 130Hz min freq
- right: 3 harmonics 100Hz min freq
To crush out the motor band noise, it seems we can’t really reduce RPM filter. The default 3 harmonics and 100Hz min freq works the best for us in this example.
Tuning Dynamic Notch Filter
The dynamic notch filter suppresses signal peaks in gyro signal that are mostly vibrations from the frame or other hardware, i.e. frame resonance (carbon fibre can be surprisingly springy), antennas, GoPro in a TPU mount, and bent propellers.
When RPM filter is enabled, Betaflight will automatically reduce the amount of Dynamic Notch filtering (fewer notch counts and higher Q value) as RPM filter will do most of the heavy lifting. You can further tune Dynamic notch based on your own setup.
Tuning Dynamic Notch Filter means to optimize the notch count, the highest possible Q value and the appropriate min/max frequency. Fewer notches = less filtering but lower latency.
Look at the heatmap and identify how many frame resonances there are to decide how many notches are needed. You can have up to 5 notches but usually 1-2 should be enough unless your drone is poorly built or in a really beat up condition. Especially when you have RPM filter enabled, 1 notch is usually enough to crush out frame resonance. If your quad can’t use RPM Filter, for example on a tiny whoop, you can try to enable Dynamic Notch Filter with 5 harmonics, Q factor 350 and Min Frequency at 100Hz as a starting point, then tune it by working your way up.
In this example, there only seems be to one frame resonance around 210Hz (see the horizontal line that appears across the whole throttle range).
The Q value determines the width of the filter: Higher Q = narrower filter, less filtering but lower latency.
If the default Q of 500 is working well, try 600 or even 700 (basically find the highest Q value that can still adequately control those resonances). If after filtering you can still see the frame resonance noise, you might need a lower value. Check Dterm heatmap to see how it affects D-term noise as well to decide whether or not your Q value can go higher.
Min/Max Frequency are the cut-off frequencies, it’s basically the effective range of the Dynamic Notch filter. Simply add 20-30Hz additional range to each side of the resonance.
I would avoid setting Min Frequency too high for safety as bent props can create massive resonance too. If you crash and try to fly home with a bent prop, the dynamic notch filter can really help to reduce the vibrations that can get into the D-term. We don’t know exactly where that resonance is going to be, but having a wider frequency range has a higher chance of catching it. If the Dynamic Notch fails to catch these newly pop up resonances due to Min Frequency is set too high, your motors can get hot or even burn in these situations.
In this example, I tried to increase Q to 700 and set the min/max frequency to 160-230Hz, but Q is clearly too high I think. There is more unfiltered noise, and it gets into Dterm and get amplified.
Finally, when I set Q to 450, the noise is adequately controlled. In the below graphs, on the left is Q=700, the right is Q=450. You can check Dterm heatmap again to confirm this is working well.
Tuning Gyro Lowpass Filter
In most cases you can just turn off Gyro Lowpass 1 filter as it’s not needed, test fly aggressively for 30 seconds, and check motor temperature to make sure they are not hot before proceeding.
Then use the “Gyro Filter Multiplier” slider to reduce Gyro Lowpass 2 a couple of notches at a time. Moving the slider to the right = moving frequency up = reducing filtering = less delay = better prop wash handling and higher PID gains.
Here I will compare the gyro frequency spectrum between Gyro Lowpass filter slider value 1.0 (brown), 1.5 (red) and 2.0 (orange).
The 3 lines almost overlap each other, that suggest Gyro lowpass filter isn’t really doing much and can be reduced. Interestingly, if you look at the noise in the sub-100Hz spectrum, it actually gets ever so slightly better with less filtering, that echoes what we talked about earlier.
- Never disable Gyro Lowpass 2 filter for 2K/4K PID loop frequency due to anti-aliasing reasons
- For 2K looptime, leave Gyro Lowpass 2 at 500Hz as the minimum
- For 4K you can set Gyro Lowpass 2 as far as 1000Hz
- For 8K, you can disable Gyro Lowpass 2 entirely if noise isn’t an issue
Tuning D Term Lowpass
D term is much noisier than Gyro due to its sensitive nature and noise gets amplified as frequency goes up, so be extra careful and conservative when dealing with D Term filtering.
Try moving the “D Term Filter Multiplier” slider to the right a notch at a time and see how the drone responds in a 30-second test flight (do some acro moves), also check motor temperature after landing. If they get hot you should go back a notch or two.
I would warn against going too aggressive with reducing D Term filtering, leave some headroom for possible bent props during flight. Too little D Term filtering and a damaged propeller are the best combination for hot/burned motors.
Here’s a comparison between 1.0 (brown), 1.3 (red) and 1.6 (orange) in D-term filtering slider positions. As you can see less filtering is clearly noisier for dterm, unlike Gyro lowpass.
If you hear the motors getting rough (thrilling oscillation) as you reduce d-term filtering, it’s the growing noise below 100Hz (you can check the <100Hz graphs to confirm). In this example I’d probably stay below 1.3, maybe 1.2 or even just 1.1 to be safe.
After you have tuned PID gains, you should come back and check again if D Term filtering can be optimized.
If the D Term traces are very noisy, one or two clicks more filtering on the slider may help. If the D term trace is very clean, you can perhaps reduce filtering a bit more (if motors are not hot). See below graphs, the left has a noisy D term trace, the right is much cleaner.
Important: NEVER disable D-Term lowpass filters completely, you will burn your motors.
Static Notch Filter
Static Notch filter is only used when there’s a strong resonance at a very specific frequency (such as frame resonance). However the dynamic notch filter can usually cover it and so a static notch filter is usually not needed (you can leave it disabled). You can however try adding a static notch for the known frame resonance (at a fixed frequency) and reducing the dynamic notch count by one and see which strategy works better for your setup.
Yaw Lowpass Filter
The default yaw lowpass filter at 100Hz cutoff has minimal latency penalty therefore it can be left untouched. Whoops can especially benefit from Yaw Lowpass filter as it helps to reduce yaw spin in collisions.
To tune PID using Blackbox, I will be following the “Basement Tuning” method using PIDToolBox. It’s beginner-friendly and you can literally do it in your basement/bed room hence the name. Basically you just need to perform a series of short flights with slightly different PID values, then compare the logs to find the optimal gains.
During flight, you should move the quad around in pitch and roll axis, simple enough. You can learn more about the basement method in this video by PIDToolbox.
Although they call it the “basement tuning method”, I am really not comfortable doing this indoor. I had a couple of “fly to the moon” incidents in the past and I almost drilled a hole in the ceiling, so I always try to do these tests in the garden or in the local park.
Rate Profile and Angle Mode
It takes some good line of sight flying skills to perform the basement tuning flights. It’s not easy to keep the drone controlled in confined space without hitting the walls. To make it easier, try this rate profile (Actual Rate):
- Center Sensitivity 250
- Max Rate 400
- Expo 0.00
It has low max rate, so it’s less likely to get out of control if you move the sticks too much. The high and linear center stick sensitivity ensures the stick inputs are big enough for the logs.
You can even perform this test in Angle mode which makes it even easier than rate mode. According to the author of PTB, this works just as well as in rate mode, but you need to do the following first:
- Calibrate accelerometer on the Setup tab
- Set Angle mode strength to 100 in PID Profile Settings
- Click Save
Finding P/D Balance
First of all, lower these gains so they don’t interfere with our tuning:
- Set the “Stick Response” slider (Feed Forward) to 0
- Set the “Dynamic Damping” (D Max) slider to 0
- Set the “Drift-Wobble” (I gains) slider to 0.2, it’s low enough that it shouldn’t introduce overshoot yet have just a little I terms to help stabilize the quad better, makes it easier to control
Adjust the “Damping” (D gains) slider, start with a minimum value you want to test. For a typical 5-inch FPV drone, 0.6 is a good starting point.
Here is what you want to perform in the flight:
- Arm and hover
- Constantly moving the roll and pitch stick for 20-30 seconds, the more movements the more accurate it will be
- Do as big moves as you can without hitting the walls (ideally full stick deflections)
- You can move both pitch and roll together as long as you can keep it under control
- Try not to stop/hover for too long during flight, and be as continuous as you can
Raising the Damping slider by 0.2 each time and repeat the flight: e.g, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6. When you raise D gain too high, your motors will sound rough, therefore you can’t always test the last one or two values, which is fine.
The quickest way to change slider value is by going into Betaflight OSD menu, Profile, Simplified Tuning. If you are using DJI, you can gain access to the OSD menu by rooting the goggles. If you can’t do this then just plug in the USB cable and use the Betaflight Configurator.
It’s a good idea to change battery every 2-3 flights to ensure the result isn’t affected by voltage. Power cycle the quad by unplugging the battery before every flight so it creates a new log. Or simply choose “Save and Reboot” in the OSD menu so you don’t need to unplug.
16MB memory should be enough for six 30-second flights if you time it well.
After you have completed all the flights, download them to your computer. To organize the logs better, I have a folder structure created for this process, download here: https://drive.google.com/file/d/1tx1AV2lOMgknAwIB3VFhqP1i6VpDLVjr/view?usp=share_link
And I rename the logs to something like “01 d06“, “02 d08” etc (01 means first test flight, d06 means damping slider value 0.6), and put them in the “02 PD Balance” folder.
Load all the logs in PTB, go through each one and remove the take-off and landing parts for each log (to do this, enable “Trim” on the right hand panel).
Click the “Step Resp Tool“, select all the files and click Run. if you have offset in the curves (gyro curve moving away from setpoint towards the end), enable Y Correction.
It’s pretty straight-forward, simply pick the best looking line, that’s your optimal Damping slider value. The ideal response should look something like the green line in the following graph, little to no overshoot. Having a tiny bit of overshoot is acceptable.
If your traces don’t look smooth but have lots of ups and downs, it’s an indicator that the signal is too noisy or your movements aren’t big enough.
The graphs on the right are also extremely helpful:
- Peak is highest amplitude of the overshoot (ideally the closer to 1 the better)
- Latency is the time it takes to reach setpoint (ideally the lower the better)
When D gain is low, you will get overshoot or even oscillation. As D gain increases, there will be less overshoot and Peak will decrease, but Latency will go up as a result. When D is too high (undershoot), the initial peak might not even reach the setpoint and this is not ideal. Find a response that has minimal overshoot and yet has relatively low Latency.
You can zoom in and see it more clearly (or select fewer logs, and hit Run again). We only need to look at Roll and Pitch axis.
In our example, it’s pretty clear the ideal value is orange (3) for both pitch and roll, so that would be 1.0.
It’s pretty common to have a different PD balance on pitch and roll due to the different weight distribution. If that’s the case for you, take the Damping slider to the position you want for pitch, write down the pitch D gain, then take the Damping slider to the position you want for roll, and adjust the Pitch Damping slider to match the pitch D gain you just wrote down.
Sometimes it’s better to be a little more conservative and avoid having D gain too high. If you are on the fence, always go with less D gain (higher P/D ratio), so you can raise your overall PID gains higher at the end since D is usually the limiting factor.
What I’ve found is that the step response tool tends to be quite sensitive and the P/D balance might be lower than what I’d personally prefer. So I normally bump up P/D balance by 5-10% after finding an ideal value. That’s just my personal preference, you can give that a try if you want.
The size of the drone affects PD ratio, the larger the quad, the higher P would be compared to D (higher P:D ratio). For example a 5″ might use 0.8-1.1 Damping slider while a tiny whoop might use 1.4-1.6.
Finding Max D Gain
Do the same test for Master Multiplier slider at 0.2 steps, e.g. for 5″ drone, that would be 0.8, 1.0, 1.2, 1.4, 1.6 1.8.
Be very careful though, don’t stand too close to the quad during this test, because you might hit a point where D is too high and the quad can shoot up. Pay close attention to motor noise, when you hear thrilling oscillation you should stop.
You might notice the shapes of the step response don’t change much between different values, and the Peak values stay roughly the same too. That’s because the shape of the response curve is mainly determined by the P/D ratio. By increasing the gains won’t have much of an effect on the response, but by bumping up P/D gains can reduce Latency.
You have reached the ideal Master Multiplier gain when one of the following happens:
- you hear thrilling oscillation – you can’t increase D gain anymore
- or the latency doesn’t decrease anymore (or very little) – that means it has reached the upper bound tuning window, motors are working at the hardest and you are not getting anymore performance out of them
How high your gains can go is determined by how noisy your build is and how much filtering you are using. Less filtering allows for higher PID gains. Sometimes it’s better to be a little more conservative and turn the Master Multiplier slider down a notch or two when you have found the max value, and not to push D gain to the edge would be safer in the event of a bent prop. Note that drones using higher cell count battery (higher voltage) tend to allow lower D gains, e.g. on a 6S quad, D gains might be in the 30’s, while on 4S they are usually in the 40’s.
In my example, 1.6 seems to be the value that gives us the least latency, not much improvement going to 1.8.
You might or might not be able to hear the thrilling oscillations. To check, simply go to Spectral Analyser and plot Dterm. As the gains get higher, the motors will make a thrilling sound that peaks around 40-80Hz (especially as you ramp up throttle). If you see noise at this frequency range creeping up with higher gains, then you know for sure you have an oscillation starting that is PID related.
In this example, you can clearly see that peak around 60Hz for 1.4 (olive), 1.6 (green) and 1.8 (cyan). Although 1.6 shows improvement in latency, I personally would not risk it. I’d probably go for 1.3 or even 1.2 in this example just to be safe.
It’s still controversial whether it’s better to have more Dterm filtering and higher D gain, or less Dterm filtering and lower D gain. But never run less Dterm filtering and high D gain or disasters can happen when you hit a branch or have bend a prop! It’s no joke :) Speaking from experience here:
If you check setpoint tracking now (plot Gyro and Setpoint), you should find the quad tracking pretty well. The two line should be roughly parallel (meaning the quad is accelerating and decelerating at the same rate as Setpoint), but there’s still a big gap between them (latency!). In the next step, we will reduce that gap using Feedforward.
Tuning Feed Forward
Feed Forward accelerates your quad when you move the sticks, making your quad more responsive and follow setpoint closer.
P term is quite slow compared to Feedforward because it only begins to react when there’s a PID error. Feedforward measures the rate of stick deflection – how fast you are moving the sticks. It does not depend on gyro data, it gets the motors moving as soon as the the stick moves, therefore it’s a lot faster than P term.
When tuning Feed Forward I prefer to do some snap rolls and flips and check Gyro/Setpoint traces. Use your usual rate profile, or a default rate profile in Betaflight (just switch to the unused rate profile) to get a decent max rate at full stick.
Instead of using the step response tool in PTB, we can just check setpoint/gyro traces in BE, the gyro should be tracking setpoint even better than before (less delay). In the best cases the gyro may be right on top of setpoint. If Feedforward overshoots (gyro moves before setpoint), then feedforward is too high. In the following demonstration, 0.5 is way too low, 1.0 is still not high enough, but 1.5 is a tiny bit too much and overshoots. I think Feedforward at 1.3-1.4 should do it in this example.
Doesn’t matter what your flying style is, feedforward can be useful and doesn’t apply only to certain types of flying. Even cinematic flying can benefit from a good amount of feedforward, if you are moving your stick smoothly and slowly, then feedforward won’t kick in anyway. When you need snappy response FF will reduce the latency between stick input and quad response. If you want smooth flying, just use expo, more RC smoothing or lower your rate.
Tuning I Gain
The ideal I term is pretty much a feel thing to some degree, you don’t need a lot of I gain when you have optimal P and D gains, just need a minimum amount of I gain to keep the drone from drifting and wandering. Take a look at my method of tuning I here. If you are cruising forward with minimal stick inputs, the drone should hold its position for a time. If there’s any drifting then you need higher I gain.
I term has a REALLY wide tuning window especially for powerful 5″ quads, 0.5 to 1.5 in the I term slider would probably work fine. That’s why we can tune everything else and tune I term last.
Racers might prefer higher I gain for the tighter control and better tracking in sweeping turns, while freestylers might prefer the looser feel of lower I gain (and because freestyle pilots don’t hold the position for very long). When it’s windy you also need higher I gains to keep the drone stable from external forces.
Since we have added FeedForward, and the Gyro/Setpoint are tracking so closely, the Step Response tool in PTB won’t be effective for finding the I term.
Thanks to the feature “I-term relax” in Betaflight, you can use very high I gain without much of the negative effects. What I found when setting I term too high is it’ll make the traces look bumpy when doing flips and rolls. So I tend to set I on the lower side for my freestyle rigs, just enough to keep the quad from drifting due to wind. Using Anti-Gravity can boost your I gain temporally during throttle pumps to reduce nose wanders, so I usually don’t find the need to have very high I gain. For 5″, I normally leave it around 0.7-0.9.
Anti Gravity Gains
As mentioned, when you punch out and let go of throttle, the drone would wobble and nose dip. Anti Gravity can boost I gain temporally when during throttle pumps to reduce these undesirable dips. However when you set AG gain is too high, your quad may stutter when you let go of throttle (rapid oscillation), because AG boosts both P and I. For 5″, I found 5-7 a good range.
You need to tune AG by looking in the goggles.
Dynamic Idle Value 30 to 35
Dynamic Idle helps to improve stability, better propwash handling and lower chance of ESC desync. The downside is you may lose hang time. By increasing motor speed when throttle is at zero, it improves control authority of the PID controller and low throttle input responsiveness. There are also other benefits such as sharper flip and roll stops, more responsive in low throttle and more effective braking etc.
When Dynamic Idle is set, Static Motor Idle (in %) in the Motors tab is disengaged.
To setup Dynamic Idle, you need to
- enable bi-directional DShot in the Motor Tab (if you already have RPM filter enabled, you are all set)
- set a suitable Idle RPM value in the PID Tuning page (enter 30 to 35 for 5″)
The recommended Idle RPM value depends a lot on propeller size and pitch, smaller and lower pitch propellers generally require higher value. For 7″ you can generally set this to 14-28, for 5″ drones, 20-40, and for 3″ it’s higher at 33-66. When it’s windy you can also set this higher to counter.
Value too high, you lose hang time when you let the drone fall upside down (the motors push harder towards the ground). A high value will also tend to make the quad “hover” a little more even at zero throttle, making throttle management a little harder. When value is too low, you risk low throttle instability.
To set the value, depends on what ESC idle you had previously (default is 5.5%), test your motor in the motor tab, you can use a smoke stopper or bench power supply to limit current in case it goes out of control. Spin the motor at the ESC idle value, e.g. for 5.5%, move slider to around 1055, and see what the reported RPM value is (it will only show this if you enable bi-directional DShot). Then this RPM value would be the ideal value for your dynamic Idle value (divide it by 100).
Default value is 5, works for most freestyle builds. It boosts your throttle value when you are moving throttle stick up suddenly to give you extra power, it gives you a power boost but also makes throttle more unpredictable. It doesn’t have any effect when you move throttle stick slowly though. If you find throttle is hard to manage you can reduce it. I know some racers even disable throttle boost entirely by setting it to 0. You can experiment with smaller values and see what works for you.
Voltage Sag Compensation
It boosts your PID as voltage drops to make your quad performance more consistent throughout the whole flight.
Enable Thrust Linearization, 20%.
This will boost PID to improve responsiveness and control authority at low throttle, while lowering PID at top throttle to reduce oscillations (same effect as TPA). It can help with nose dip too. This is especially recommended for whoops and if you use 48KHz PWM frequency on ESC. It’s also useful when TPA alone isn’t enough to address high throttle oscillation.
Since it boosts PID at low throttle, you might want to drop the master multiplier slider down a notch or two if motors get hot.
Do a throttle sweep again and check freq vs throttle heatmap.
If you are getting oscillations only above certain throttle level, TPA might be the solution. It also helps to push PID higher without giving you problem in the high throttle range.
In the latest Betaflight it only attenuates D gain above certain throttle level (which is usually the cause of the oscillations). In the older Betaflight it attenuates both P and D, if you want you can bring this back by typing in CLI: set tpa_mode = PD.
Normally I prefer to set throttle value in TPA as high as possible, so D gain is more constant across a wider throttle range. Make sure to set the throttle value a little lower than the position where the D term related oscillations start to show up. For example, if oscillation starts around 1800 throttle, I would do something like this: TPA = 0.75, 1750.
Revisit D term filtering
After all these changes, you can check D term filtering again and see if you need to reduce or increase it.
I don’t play with Yaw too much, default gain generally works well. The tuning window for Yaw is quite wide.
Unlike pitch and roll which are based on thrust generated by propellers, yaw is based on the inertia generated by propeller rotation. Therefore, yaw will inherently be too slow to overshoot setpoint, and there’s little need to tune yaw PID.
Yaw is also too slow for D terms to have any meaningful effect and it’s generally not required. However you can enable it if you want, but it might introduce more problem than it solves, like vibrations etc. So we are left with P and I terms for Yaw.
You can tune Yaw using the step-response analysis like we did with Pitch and Roll. Additionally, if slow oscillations occur in the back part of the graph, then I-Term is too high. If fast oscillations occur, then P-Term is too high.
If you have yaw shakes when doing throttle pump, you can isolate yaw from the slider tuning, and set Yaw PID individually. To do this, go to the PID tuning tab, in the ‘Slider Mode’ dropdown list, select RP (Roll Pitch), instead of RPY (Roll Pitch Yaw). This will exclude yaw values from the sliders, and allows you to enter PID numbers for yaw. For 5″ freestyle and cinematic builds, try 100 for both P and I would be a good starting point. You can also try higher values as yaw tends to be quite slow reacting.
There is no perfect tune
How good is good enough? You can always spend more time playing with filters and PID numbers, and you may see improvements but it can be situational and the time you invest in it might not be proportional to the result. I normally just stop when it looks “good enough” and leave it there unless I have a specific problem I want to solve.
On default Betaflight settings, a 5-inch FPV drone should already fly pretty smoothly. If your quad has vibration, it could either be mechanical or electrical related. Sometimes the Gyro on the FC can cause problems too, though this is not common.
Here’s what a bad gyro might look like. What tends to happen with a bad gyro, is that one axis is particularly noisier than other axes, especially in the lower frequency spectrum below 200Hz. If you rotate the FC by 90-degree, and the noisy axis follows the rotation, then that Gyro could be faulty.
In this example, you can see pitch axis is much noisier than roll and yaw. You can also see bursts of D term noise in the pitch axis which is caused by the noisy gyro.
However, it doesn’t have to be a bad Gyro, other potential causes are: high power wires near the gyro, noisy power to FC, bad board design, etc. You can try using a 1000uF low ESR capacitor at the ESC power. If you have already done that, try soldering an extra smaller 220uF-470uF cap to the power of the FC (VBAT/VCC pad).
RC smoothing is a must-have setting in Betaflight in order to avoid issue with feedforward. The appropriate RC smoothing settings depend on your particular RC link, I strongly recommend just loading the appropriate RC_Link preset, it’s the best way to avoid user mistakes.
The Auto Factor is perhaps one of the most important values, lower is more twitchy and responsive while a higher value is softer and smoother but more sluggish. Here’s a general rule I personally follow:
- 20-25: Racing
- 30: Default value, great for Freestyle
- 50: Cinematic
- 90: Extremely smooth cruising, delay might be noticeable to some
- 120: The highest smoothness possible without getting into trouble, but delay is noticeable
Bad gear/pilot require higher RC smoothing too, e.g. Low quality radio control equipment, worn out gimbals, pilots with shaky fingers, etc. Basically anything that might contribute to jerkiness in RC commands.
If possible, check black box logs to confirm you have smooth setpoints, if the setpoint isn’t smooth (has steppings from RC commands), simply increase the smoothing slightly.
If you have noise in setpoint that peaks around 50Hz, 150Hz, 250Hz or 500Hz, then there is probably a problem with RC smoothing. These frequencies are common packet rates in RC link. In this example, it’s Crossfire 150Hz.
If you are not using enough filtering for the RC commands, you might not have smoothed out the RC signal enough and it could create noise at the frequency of your radio link packet rate.
RC smoothing removes stepping and bumpiness in your set-point, it makes P term trace less jerky. However it also adds delay to feedforward as well as setpoint, so your quad might feel a little bit less responsive. RC Smoothing is useful, but too much smoothing defeats the purpose of having fast RC packet rates like ExpressLRS offers.
The goal is to smooth out the steppings but not adding too much delay. If you want smoother RC input, try adding some more expo, it has similar effect but it won’t give you the latency penalty.
The best way is to just load the appropriate RC Link preset as I talked about here. If you failed to load the correct RC_Link preset for your particular RC link and packet rate, it might also cause problems to Feedforward. In this example, feedforward jitters due to the lack of stepping smoothing in RC commands.
PID Sum too low?
PID_Sum hitting the default 500 limit here (50%) because PID are set very high on this drone. You can raise it to 1000 (in CLI enter set pid_sum_limit=1000) to fix it, but it does not always make a difference in flight behaviour as motors might saturate at this rate anyway.
ADC Filter Jitters Causing Oscillations
If you are getting random vibrations and wobbles due to feed forward jitters, even though you’ve applied the correct RC Link preset or increased RC smoothing, it could be ADC filter!
Make sure you have turned it off in your radio’s system menu, hardware page.
This is what the feedforward spikes look like when ADC filter is tuned on.
I spent over 3 months writing this 7000 words tutorial! If you find my content useful, please consider supporting my work.