DEV Community

FPVtune
FPVtune

Posted on

How I Built a Blackbox Log Analyzer to Auto-Tune FPV Drone PIDs

I fly FPV drones as a hobby, and if you've ever tried tuning Betaflight PIDs manually, you know the pain. Record a flight, pull the blackbox log, open PIDtoolbox, stare at gyro traces for an hour, change one number, fly again... repeat forever.

So I built a tool that does it automatically. Here's the story and some of the technical bits.

The Problem

Betaflight's PID controller has ~15 parameters that affect how your drone flies. Most pilots either copy someone else's tune (which rarely works because every build is different) or spend days doing test flights and analyzing blackbox logs.

The existing tools like PIDtoolbox are great for visualizing data, but they don't tell you what to actually change. You still need to know what a noisy gyro trace means and which PID term to adjust.

The Approach

I wanted something that could:

  1. Parse Betaflight blackbox logs (.bbl files)
  2. Analyze the frequency response and noise characteristics
  3. Suggest specific PID values based on the analysis

The blackbox format is basically a compressed binary stream of sensor data — gyro, accelerometer, motor outputs, RC inputs, etc. sampled at up to 8kHz.

Parsing Blackbox Logs

Betaflight's blackbox logs use a custom encoding with variable-length integers and predictive coding. Here's a simplified look at how the parsing works:

def decode_blackbox_frame(data, field_defs):
    values = {}
    for field in field_defs:
        if field.encoding == 'signed_vlq':
            val = read_signed_vlq(data)
        elif field.encoding == 'unsigned_vlq':
            val = read_unsigned_vlq(data)
        elif field.encoding == 'tag8_8svb':
            val = read_tag8_8svb(data)
        values[field.name] = val * field.scale
    return values
Enter fullscreen mode Exit fullscreen mode

The tricky part is handling the different Betaflight firmware versions — the log format changes between versions and you need to parse the header to figure out which fields are present.

Frequency Analysis

Once you have the raw gyro and PID error data, the real magic happens in the frequency domain. I use FFT to identify:

  • Noise floor: How much electrical/mechanical noise your quad produces
  • Motor resonance peaks: Frequencies where your motors/props create vibrations
  • PID response: How well the current tune tracks setpoint changes
import numpy as np

def analyze_axis(gyro_data, pid_error, sample_rate):
    # FFT of gyro data to find noise profile
    freqs = np.fft.rfftfreq(len(gyro_data), 1/sample_rate)
    gyro_fft = np.abs(np.fft.rfft(gyro_data))

    # Find dominant noise frequencies
    noise_peaks = find_peaks(gyro_fft, height=np.mean(gyro_fft) * 3)

    # Analyze step response from setpoint changes
    step_indices = find_setpoint_steps(pid_error)
    overshoot = calculate_overshoot(gyro_data, step_indices)
    settling_time = calculate_settling(gyro_data, step_indices)

    return {
        'noise_peaks': freqs[noise_peaks],
        'overshoot': overshoot,
        'settling_time': settling_time
    }
Enter fullscreen mode Exit fullscreen mode

From Analysis to PID Suggestions

This is where it gets interesting. Based on the frequency analysis, the tool adjusts PIDs following some basic control theory:

  • High overshoot on roll/pitch → reduce P gain or increase D gain
  • Slow response → increase P gain
  • High frequency oscillation → reduce D gain, check D lowpass filter
  • Prop wash oscillation (low frequency, shows up in throttle cuts) → adjust I gain and D term

The tool outputs specific numbers you can paste directly into Betaflight configurator.

Try It Out

I turned this into a web tool called FPVtune — you upload your blackbox log and it spits out PID recommendations. No software to install, works in the browser.

The source code for the analysis engine is on GitHub if you want to dig into the algorithms.

It's $9.90 for the full analysis, but I have a beta code for the DEV community: FPVTUNE-BETA-2026 — just enter it on the activation page to get free access.

What I Learned

Building this taught me a lot about:

  • Signal processing in Python (scipy.signal is your friend)
  • Working with binary data formats that have zero documentation
  • The gap between "analyzing data" and "making actionable suggestions"

If you fly FPV or work with any kind of PID control systems (robotics, etc.), I'd love to hear how you approach tuning. The control theory fundamentals are the same whether you're tuning a drone or a robot arm.


Repo: github.com/chugzb/betaflight-pid-autotuning

Top comments (0)