How to Tune FPV Drone Filters and PID with Blackbox

by Oscar
How To Tune Fpv Drone Filters And Pid Using Blackbox Tutorial

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.

banggood

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.


Getting Started

Tuning goals

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

Basic configurations

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

Betaflight 4.3 Configurator 10.8 Blackbox

2. Disable ADC filter in your OpenTX/EdgeTX radio (System->Hardware). This will reduce latency.

Edgetx Hardware Adc Filter Disabled


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

Blheli 32 Best Settings 2022 Pwm Frequency Rampup Power Motor Timing Blhelisuite32

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.

Bluejay Esc Configurator 24khz


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.

Betaflight 4.3 Configurator 10.8 Expert Mode Enabled Pid TuningIn the Configuration tab, set your PID Loop Frequency, and in the Motor tab, set your ESC protocol.

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.

Betaflight 4.3 Load Preset Rc Link Expresslrs 500hz Options

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.

Betaflight Configurator Tpa Breakpoint


How to use PIDToolBox and Blackbox Explorer?

I will be using both PIDToolBox (PTB) and Blackbox Explorer (BE) in my PID and filter tuning.

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.


Filters Tuning

Further reading: Learn about the different types of filter in Betaflight in this tutorial.

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

Betaflight Blackbox Filter Tuning Throttle Sweep

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

Betaflight Blackbox Filter Tuning Noise Spectrum Frequency Break Down

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.

Blackbox Log Explorer Gyro Filter Delay

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

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Delay

Filter Strategy

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Prefiltered Gyro DipThe 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”.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Freq Throttle Heatmap

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

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Freq Throttle Motor Band Harmonics Frame Resonance

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Freqxthrottle Motor Bands Min Freq

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Freq Throttle Rpm Sourceone V5

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Rpm Dterm Noise Sourceone V5

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Rpm Min Freq Data Cursor

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

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Rpm Min Freq Comparison

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

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Frame Resonance Dynamic Notch Sournceone V5

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Frame Resonance Dterm Noise 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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Frame Resonance Dynamic Notch Sourceone V5 Q Freq

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.

Betaflight 4.3 Disable Gyro Lowpass 1 Filter

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.

Betaflight 4.3 Reduce Gyro Filter Slider

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.

Important:

  • 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

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser Gyro Lowpass 1 1.5 2 Compare Sourceone V5

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser D Term Slider 1 1.3 1.6 Sourceone V5In the following heatmap, from left to right: unfiltered D term, Dterm lowpass filter 1.0, 1.3 and 1.6.

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.

Betaflight Blackbox Filter Tuning Pidtoolbox Spectral Analyser D Term Slider 1 1.3 1.6 Heat Map Sourceone V5

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.

Betaflight Blackbox Pid Tuning Dterm Lowpass Clean D Term Trace

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.


PID Tuning

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.

Betaflight Pid Tuning Pidtoolbox Basement Method Flight Perform

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

Betaflight Blackbox Pid Tuning Pidtoolbox Slider Intial Setup

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.

Betaflight 4.3 Damping Slider Move Down

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.

Betaflight Osd Menu Simplified Tuning Slider Dji Avatar Hdzero Digital

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

Betaflight Blackbox Pid Tuning Pidtoolbox Folder Structure

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

Betaflight Blackbox Pid Tuning Pidtoolbox Step Response Basement Method

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.

Betaflight Blackbox Pid Tuning Pidtoolbox Step Response Basement Method Pd Compare Lines

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)

Betaflight Blackbox Pid Tuning Pidtoolbox Step Response Basement Method Peak Latency Graphs

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.

Betaflight Blackbox Pid Tuning Pidtoolbox Step Response Basement Method Pd Compare Lines Zoom In

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.

Betaflight 4.3 Master Multiplier Slider Move Up

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.

Betaflight Blackbox Pid Tuning Pidtoolbox Step Response Basement Method Master Multi Slider

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.

Betaflight Blackbox Pid Tuning Pidtoolbox Basement Method Master Multi Slider Dterm Noise

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:

 

View this post on Instagram

 

A post shared by Oscar Liang (@oscarliang3)

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.

Betaflight Blackbox Pid Tuning Pidtoolbox Basement Method Master Multi Slider Setpoint Tracking No Ff

Tuning Feed Forward

Betaflight 4.3 Stick Response Slider Move Up

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.

Betaflight Blackbox Pid Tuning Feedforward Setpoint TrackingIf your feedforward gain is way too high, it will even cause P term to go the opposite direction trying to fight it :)

Blackbox Log Too Much Feedforward

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.

Other Settings

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

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

Throttle Boost

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.

Thrust Linearization

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.

TPA

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.

Tuning Yaw

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.

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.

Troubleshooting Tips

Bad Gyro

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.

Blackbox Log Explorer Faulty 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

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.

Blackbox Log Explorer Setpoint Noise Peak 150hz Not Enough Rc Filtering

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.

Blackbox Log Wrong Rc Link Preset Feedforward Jitter Smoothing

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.

Blackbox Log Pid Sum Too Low 500 Motor Saturate

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.

Blackbox Adc Filter Jitter Rc Commands Feed Forward Spikes

I spent over 3 months writing this 7000 words tutorial! If you find my content useful, please consider supporting my work.

Leave a Comment

By using this form, you agree with the storage and handling of your data by this website. Note that all comments are held for moderation before appearing.

22 comments

Ivan Bukharin 24th January 2023 - 4:07 pm

Great great article!
But I can not find the cause of the periodic twitches of the copter.
Video demonstrating the problem: youtube.com/watch?v=HadMNNDLi5k
Flight time:
02:11
02:46
There are logs. Where to look?

Reply
Oscar 24th January 2023 - 5:12 pm

maybe share your logs on google drive and let’s have a look?
Another good place to get troubleshooting help is https://intofpv.com/

Reply
Ivan Bukharin 24th January 2023 - 5:43 pm

Thanks!
Log: drive.google.com/file/d/1OKZHyLf–fhArrWftB23HvbaaIyu4Jar/view?usp=share_link
This is the log from the flight, which is in the video above.

Reply
Oscar 24th January 2023 - 8:26 pm

There are some spikes in your RC commands, which I believe is causing some spikes in your feedforward and results in the twitching.
Have you disabled ADC filter in your radio? See second step in this section: https://oscarliang.com/pid-filter-tuning-blackbox/#Basic-configurations
I suggest you to go through the whole “Basic Configuration” again.

Reply
Ivan Bukharin 25th January 2023 - 10:19 am

ADC filter enabled.
Thank you! I will try everything you said, but queues.

Ivan Bukharin 25th January 2023 - 1:13 pm

1) applied presets, as in your article.
2) disabled the ADC filter.
The problem remains, but perhaps not such severe fluctuations now.
I did the following: in the “TX Power” settings: “Dynamic” ~ off; “Max power” ~ 100. As a result, the problem is completely gone! When there was a problem, the settings were as follows: “TX Power”: “Dynamic” ~ dyn; “Max power” ~ 1000. Apparently the problem is related to power switching on the equipment. Hardware: built-in elrs 1000mw jumper t-pro.
Of course, I will think about how best to make the antenna on the receiver. What else can be done?

Ivan Bukharin 25th January 2023 - 3:53 pm

1) applied presets, as in your article.
2) disabled the ADC filter.
The problem remains, but perhaps not such severe fluctuations now.
I did the following: in the “TX Power” settings: “Dynamic” ~ off; “Max power” ~ 100. As a result, the problem is completely gone! When there was a problem, the settings were as follows: “TX Power”: “Dynamic” ~ dyn; “Max power” ~ 1000. Apparently the problem is related to power switching on the equipment. Hardware: built-in elrs 1000mw jumper t-pro.
Of course, I will think about how best to make the antenna on the receiver. What else can be done?

Oscar 25th January 2023 - 4:53 pm

Can you use 500mW? I don’t think 1000mW and 500mW make a big difference when it comes to range. Also have you tried disabling Dynamic Power?

Ivan Bukharin 26th January 2023 - 6:04 am

With dynamic power, a problem arises – the copter shakes when turning. With static power, there is no problem.

Oscar 26th January 2023 - 11:00 am

Yea just disable dynamic power, I always have it disabled.

Ivan Bukharin 26th January 2023 - 2:20 pm

OK, thx Oscar!

Alexis 13th December 2022 - 11:17 am

Great thanks for all these deep explainations, details, so easy to follow!.
I have started to optimized on Tyro79 with a Mamba Mk4 F722 FC.
As the first steps are “only” optimizing the signal fitering, perhaps one only flight with several filtering simulation (to do in a dedicated app or other) could be enough instead of performing one flight/record per parameters setup?
What do you think about it?

Reply
SebCBien 4th December 2022 - 6:59 pm

I subscribed to your patreon!
The help provided by these articles is tremendous!
I often come here and it’s generally better than videos and especially more complete!
On the other hand you do not use the method of first putting the master to multiply the farthest and then making the other parameters (like Chriss Rosser and others). Why ?
Continue like that !

Reply
Oscar 4th December 2022 - 8:24 pm

Just a matter of styles I guess, I don’t think that would make much of a difference to the final tune. But if change Master Multiplier first, then you don’t really wanna use the Damping sliders later on, as it will change your D gain, instead you wanna use the P/I slider to change P/D balance.
Like I said, either way we are doing the same thing and you will get the same result.

Reply
SebCBien 4th December 2022 - 10:43 pm

Thanks ! :-)

Reply
Zois 21st November 2022 - 3:01 pm

Drone falls from the sky.
Desync or power loss?
Can you see it in blackbox?

thank you

Reply
Oscar 21st November 2022 - 4:04 pm

Yes it’s possible to tell.

Reply
Nikotttin 17th November 2022 - 11:39 pm

Amazing article!! Thank you!!

Reply
Tehllama 17th November 2022 - 4:30 pm

Seriously amazing work.
I still recommend 48kHz PWM on the ESC for this particular setup (running dynamic idle AND thrust_linear basically negates the only downside, and higher PWM frequency really helps reduce EMI coming off the ESCs and ‘seen’ by the flight controller gyroscope).
In Betaflight 4.4 the AntiGravity feature will have different values, but stock works extremely well – generally running 10x the previous value if you took the time to tune it should work great.

Reply
Oscar 17th November 2022 - 5:16 pm

Thanks for the great feedback and recommendations!

Reply
Jupiter 17th November 2022 - 12:14 am

I’m having trouble tuning a racing build because my gyro has a constant spike at 40- 80 hz and I cant seem to get rid of it, it mostly shows up on roll peaking at 5 db (on pitch and yaw it only peaks to -10 db) is this a bad gyro?
I’ve checked and made changes multiple time but nothing seems to fix it. the build is running 6s with the rush pfb that has 2 35v 330uf caps and 3 Tvs diodes if that helps
Any help is appreciated!
Thanks

Reply
Mars 17th November 2022 - 11:10 am

Try to rotate the FC by 90 degree and see if the noisy axis becomes pitch? if so then it’st most likely to be bad gyro.

Reply