N5JLD dot NET

What I do in my Spare Time

User Tools

Site Tools


drone:maint:pid_tuning

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

drone:maint:pid_tuning [11/19/2026 14:12] – created Jondrone:maint:pid_tuning [11/19/2026 14:16] (current) – Jon
Line 1: Line 1:
 +====== PID & Filter Tuning for Drones ======
 +
 +**PID (Proportional, Integral, Derivative)** control and **gyro/D-term filtering** govern how a flight controller translates pilot stick inputs and gyro sensor data into motor commands. Proper tuning eliminates oscillations, reduces motor heat, sharpens stick response, and unlocks smooth, locked-in flight performance.
 +
 +<note warning>
 +**Motor & ESC Thermal Warning:** Aggressive PID gains (especially high D-term) combined with insufficient filtering can pass high-frequency mechanical noise directly to your motors. Always perform 15–20 second hover and throttle-blip tests after tuning changes, and check motor temperatures by hand—if motors are too hot to touch comfortably (>60°C / 140°F), lower D-gains or increase filtering immediately.
 +</note>
 +
 +===== 1. Anatomy of a PID Controller =====
 +
 +A PID loop continuously calculates the **error** (the difference between your desired rotation rate from the sticks and the drone's actual rotation rate measured by the gyro) and applies three corrective forces across Pitch, Roll, and Yaw.
 +
 +^ Term ^ Full Name ^ Primary Function ^ Too Low Symptoms ^ Too High Symptoms ^
 +
 +| **P** | Proportional | Immediate muscle/authority to reach the target setpoint. | Sluggish response, drifting in turns, washout on throttle cuts. | Fast, sharp oscillations/shuddering during quick maneuvers. |
 +| **I** | Integral | Corrects long-term drift caused by external forces (wind, off-center CG). | Nose dips on punch-outs, wandering attitude in wind, poor hold. | Slow, sluggish bounce-back after flips; stiff, robotic feel. |
 +| **D** | Derivative | Dampens P-term overshoot and cushions sudden movements. | Bounce-back at the end of flips/rolls; propwash oscillations. | Hot motors, audible high-pitched motor whine/trill, twitchy feel. |
 +| **FF** | Feedforward | Boosts initial stick response based on how fast the sticks move (not error). | Slight delay between stick movement and aircraft reaction. | Overshoot at the start of flips; twitchy center-stick behavior. |
 +
 +<note tip>
 +**The Spring Analogy:** Think of **P** as the stiffness of a spring pulling the drone toward your stick command, **D** as the shock absorber preventing that spring from bouncing wildly back and forth, and **I** as a steady hand holding the drone level against constant wind or weight imbalance.
 +</note>
 +
 +===== 2. Understanding Gyro & D-Term Filtering =====
 +
 +Before the PID loop can calculate clean motor outputs, the flight controller must scrub mechanical vibrations (frame resonance, bent props, rough bearings) from the raw gyro signal.
 +
 +==== Why Filtering Matters ====
 +  * **Noise Amplification:** The **D-term** looks at the //rate of change// of error. High-frequency gyro noise looks like rapid error changes, causing the D-term to drive motors rapidly back and forth—generating extreme heat and wasting battery efficiency.
 +  * **The Latency Trade-Off:** Every filter introduces a tiny time delay (phase lag) between real aircraft movement and motor reaction. **Too little filtering** burns up motors; **too much filtering** causes sluggish handling and propwash oscillations.
 +
 +==== Common Filter Types (Betaflight / INAV / ArduPilot) ====
 +  * **RPM Filtering (Bidirectional DShot):** Reads exact motor RPM telemetry from the ESCs and places dynamic notch filters directly on each motor's fundamental frequency and harmonics. **Always enable this if your ESCs support it.**
 +  * **Dynamic Notch Filter:** Tracks the loudest remaining noise peaks in real time (such as frame resonance) and notches them out automatically.
 +  * **Gyro Low-Pass Filters (LPF1 / LPF2):** Cuts off all frequencies above a set Hz threshold. Moving sliders to the right raises the cutoff frequency (less filtering, lower latency).
 +  * **D-Term Low-Pass Filters:** Dedicated smoothing specifically for the D-term output, which is far more sensitive to noise than P or I.
 +
 +<note important>
 +**Filter Before Tuning:** Always optimize your filters **first** before pushing PID gains upward. A noisy airframe will hide bad filter settings behind hot motors and false oscillations, making accurate PID tuning impossible.
 +</note>
 +
 +===== 3. Pre-Tuning Mechanical Checklist =====
 +
 +Software cannot fix a mechanically compromised aircraft. Verify these hardware items before touching firmware sliders:
 +
 +  * [ ] **Propellers:** Installed fresh, undamaged, well-balanced props (bent blades are the #1 source of gyro noise).
 +  * [ ] **Frame & Arm Rigidity:** All frame screws, standoffs, and motor bolts are tight with blue threadlocker applied to metal-on-metal threads.
 +  * [ ] **Flight Controller Mounting:** Soft-mounted gummy grommets are seated evenly without pinched wires touching the gyro chip.
 +  * [ ] **Battery Strap & Wiring:** LiPo battery is strapped tightly with zero wobble, and capacitor/motor wires are secured away from the FC.
 +
 +===== 4. Step-by-Step Tuning Workflow =====
 +
 +Follow this methodical sequence using **Blackbox logs** (or careful line-of-sight/FPV testing) to dial in a clean, locked-in tune.
 +
 +==== Step 1: Establish a Clean Filter Baseline ====
 +  - Enable **Bidirectional DShot** and **RPM Filtering** (typically 3 harmonics per motor).
 +  - Set the **Dynamic Notch Filter** count to 1 or 2 (with RPM filtering active, fewer dynamic notches are needed).
 +  - Test hover and perform brief full-throttle punch-outs. Check motor temperatures—motors should feel cool to slightly warm.
 +  - //Optional (Blackbox Tuning):// Inspect the Gyro Scaled vs. Gyro Filtered frequency spectrum. Gradually move the **Gyro** and **D-Term Filter sliders** toward less filtering until noise just begins to appear above 100Hz, then back off 10%–15%.
 +
 +==== Step 2: Tune Master Multiplier & P/D Balance ====
 +  - **Increase Master Multiplier (or P & D together):** Raise gains in increments of 0.1–0.15 while performing quick, sharp flips and rolls.
 +  - **Watch for Bounce-Back:**
 +    * If the drone **bounces back** slightly at the end of a sharp roll stop, **increase D** (or lower P slightly).
 +    * If the drone feels **sluggish** or washes out in hard turns, **increase P** (and raise D proportionally to keep it damped).
 +  - **Check Motor Heat:** After each adjustment, fly aggressively for 20 seconds, land, and touch all four motor bells.
 +
 +==== Step 3: Dial In I-Term & Feedforward ====
 +  - **I-Term:** Perform fast forward flight followed by a sudden throttle cut, or fly in gusty wind. If the nose pitches up or drifts off-axis, increase **I-gain** slightly until the attitude stays locked on rails.
 +  - **Feedforward (FF):** Perform rapid stick snaps. Increase FF for sharper, more immediate stick-to-frame connection. Reduce FF if the quad twitches nervously around center stick or overshoots the start of flips.
 +
 +==== Step 4: Propwash Handling Optimization ====
 +Propwash oscillations occur when descending through your own turbulent air (e.g., pulling out of a steep dive or sharp hairpin turn).
 +  * **Primary Cause:** Excessive filter delay or an under-damped P/D ratio.
 +  * **Fixes:**
 +    - Ensure **Dynamic Idle** is properly configured so motors maintain sufficient RPM authority at zero throttle.
 +    - Reduce unnecessary filter latency (only if motor temps allow).
 +    - Slightly boost **D-gain** or **P/D ratio** on Pitch and Roll.
 +
 +===== 5. Tuning Profiles by Drone Class =====
 +
 +Different airframe sizes and mission profiles require vastly different baseline approaches:
 +
 +^ Drone Class ^ Prop Size ^ Filter Strategy ^ PID Characteristics ^
 +
 +| **5" FPV Freestyle** | 5.0" – 5.1" | RPM filter + minimal low-pass filtering for ultra-low latency. | High P & D for crisp propwash control; moderate-high Feedforward. |
 +| **Micro / Tiny Whoop** | 31mm – 2.5" | Higher filtering required due to high-RPM vibration and flexible frames. | Very high P & I relative to D; high Feedforward for snappy indoor agility. |
 +| **7" – 10" Long Range** | 7.0" – 10.0" | Lower low-pass cutoff frequencies (more filtering) to block low-Hz arm flex. | High I-term for wind stability; lower D-term and smoother Feedforward. |
 +| **Heavy-Lift Cinelifter** | 7" – 13" X8 | Heavy low-pass & notch filtering to tame dual-prop turbulence. | High P & I to handle heavy camera payload inertia; cautious D-gains. |
 +
 +===== 6. Quick Troubleshooting Reference =====
 +
 +^ Symptom ^ Likely Cause ^ Recommended Adjustment ^
 +
 +| **Rapid high-frequency shudder on throttle** | P-gain too high, or loose frame hardware. | Tighten frame/motor screws; lower **P-gain** by 10%–15%. |
 +| **Bounce-back after sharp flips/rolls** | D-gain too low relative to P, or excessive FF. | Increase **D-gain** slightly, or reduce **Feedforward**. |
 +| **Hot motors + faint high-pitched trill** | Excessive D-term noise reaching motors. | Lower **D-gain** or move **D-Term Filter slider** toward more filtering. |
 +| **Shaking when descending into own wash** | Filter latency or insufficient D-term damping. | Enable **RPM filtering**, set **Dynamic Idle**, or increase **D-gain**. |
 +| **Nose pitches up/down on throttle punch** | I-term too low, or off-center battery CG. | Center battery weight; increase **I-gain** by 10%–20%. |
 +
 +<note>
 +**Rule of Thumb for Tuning:** Change **one parameter at a time**, keep notes (or use firmware presets/CLI diffs) before making major changes, and always prioritize cool motors and clean mechanical builds over chasing aggressive numbers.
 +</note>
 +
 +====== Step-by-Step Blackbox Log Analysis Instructions ======
 +
 +Follow these exact instructions to record, export, and analyze Blackbox flight logs using **Betaflight Blackbox Explorer** and **PIDtoolbox**.
 +
 +===== Part 1: Exporting Your Flight Log =====
 +
 +  - **Connect to Betaflight Configurator:** Plug your drone into your PC via USB (no battery required for onboard flash; plug in a battery if your SD card reader requires 5V rail power).
 +  - **Open the Blackbox Tab:** Click **Blackbox** in the left-hand navigation menu.
 +  - **Download the Log:**
 +    * //For Onboard Flash:// Click **Save Flash to File...** and save the ''.bbl'' or ''.bfl'' file to a dedicated folder on your computer.
 +    * //For SD Card:// Click **Activate Mass Storage Device** (or remove the microSD card and insert it into your PC) and copy the latest ''LOG000xx.BFL'' file.
 +  - **Clear Storage for Next Flight:** Click **Erase Flash** (or delete old logs from the SD card) so your next test flight starts with empty memory.
 +
 +<note tip>
 +**File Naming Habit:** Immediately rename your downloaded log file to include the slider values used during that flight (e.g., ''2026-11-19_5inch_Filters1.3_Master1.2.bbl''). Without clear filenames, comparing back-to-back test flights becomes nearly impossible.
 +</note>
 +
 +===== Part 2: Inspecting Traces & Spectrums in Blackbox Explorer =====
 +
 +Use **Betaflight Blackbox Explorer** to check mechanical health, motor saturation, and raw vs. filtered noise frequencies.
 +
 +==== Step 1: Load and Configure the Workspace ====
 +  - Open **Betaflight Blackbox Explorer** and click **Open Log File** (top right) to load your ''.bbl'' file.
 +  - If your file contains multiple flights (multiple arm/disarm cycles), use the **Log Selector** dropdown in the top bar to pick the specific test flight.
 +  - Click the **Graph Setup** button (top bar) and load a clean workspace layout containing:
 +    * **Graph 1:** ''Gyro [roll, pitch, yaw]'' + ''Setpoint [roll, pitch, yaw]''
 +    * **Graph 2:** ''PID P, I, D'' (select Roll or Pitch axis)
 +    * **Graph 3:** ''Motors [1, 2, 3, 4]''
 +    * **Graph 4:** ''Debug [0, 1, 2]'' (this displays raw ''GYRO_SCALED'' if enabled before flight)
 +
 +==== Step 2: Check Noise Frequencies (Spectrum Analyzer) ====
 +  - Hover your mouse over the **Debug [0]** (Raw Roll Gyro) trace and click the **Spectrum / Analyzer icon** (or press **F** on your keyboard) to open the frequency graph.
 +  - Look at the peak frequencies between **0Hz and 500Hz**:
 +    * **Note any sharp spikes below 100Hz:** These indicate frame resonance or loose screws.
 +    * **Check the high-frequency floor (>150Hz):** Note how tall the noise floor is before filtering.
 +  - Now open the Spectrum Analyzer on **Gyro [roll]** (Filtered Roll Gyro) and **PID D [roll]**:
 +    * Verify that the sharp motor noise spikes seen in ''Debug [0]'' are gone in the filtered ''Gyro'' trace.
 +    * Check **PID D [roll]**: The area above **120Hz** should be flat and quiet. If you see large peaks above 120Hz on the D-term spectrum, **increase D-term filtering** (move the D-Term Filter slider left).
 +
 +==== Step 3: Check Motor Saturation & Balance ====
 +  - Scrub through the timeline to a **full-throttle punch-out** and a **sharp flip/roll**.
 +  - Inspect the **Motors [1, 2, 3, 4]** graph:
 +    * **Check for Clipping:** If any motor trace hits the flat ceiling at **100% (2000)** during maneuvers, your motors are saturating. Lower your **Motor Output Limit** slightly or use lower-pitch props.
 +    * **Check Trace Thickness:** Zoom in closely (scroll wheel up) on a steady hover section. Motor lines should look like **thin, crisp threads**. If they look like **thick, fuzzy markers**, high-frequency noise is vibrating your motors.
 +
 +<note warning>
 +**Single-Motor Anomaly Check:** Compare the average percentage of all four motors during a level hover. If one motor consistently runs **10%–15% higher** than the others, inspect that arm for a bent motor shaft, damaged prop, twisted arm, or unbalanced battery placement before changing any PIDs.
 +</note>
 +
 +===== Part 3: Analyzing Spectrograms & Step Response in PIDtoolbox =====
 +
 +Use **PIDtoolbox (PTB)** to turn your test flight into clear visual heatmaps and step-response curves.
 +
 +==== Step 1: Import the Log ====
 +  - Launch **PIDtoolbox** and click **Select File(s)** to load your ''.bbl'' log.
 +  - Select the desired sub-log number if multiple flights exist in the file, then click **Load**.
 +
 +==== Step 2: Generate & Read the Noise Spectrogram ====
 +  - Click the **Spectral Analyzer** button on the main dashboard.
 +  - Set the columns to compare side-by-side:
 +    * **Column 1:** ''Gyro Pre-Filt (Debug)'' — Shows raw physical vibration.
 +    * **Column 2:** ''Gyro'' — Shows what remains after your Gyro filters and RPM filter.
 +    * **Column 3:** ''D-Term'' — Shows what actually reaches your motors.
 +  - **How to Interpret the Heatmap:**
 +    * Look at the **D-Term** column above **100Hz**. It should be almost entirely **dark blue/black**.
 +    * If you see **bright yellow or green streaks** above 100Hz in the D-Term column, your filters are too loose—move your **D-Term Filter Multiplier** slider to the left by **0.1–0.2**.
 +    * If the D-Term column is completely dark blue/black all the way down to 80Hz and your motors came down cold, you have headroom to move your filter sliders to the right by **0.1–0.2** for sharper response.
 +
 +==== Step 3: Generate & Read the Step Response Curve ====
 +  - Close the Spectral Analyzer and click **Step Response** on the PIDtoolbox dashboard.
 +  - Ensure your log contains at least **3–4 sharp roll and pitch stick snaps** (PIDtoolbox automatically isolates high-rate stick movements to calculate the curve).
 +  - Inspect the **Roll**, **Pitch**, and **Yaw** response curves against the dashed **1.0 target line**:
 +    * **Latency Check:** Look at the horizontal time axis (in milliseconds). A well-tuned 5" quad reaches **1.0** within **40ms to 60ms**. If it takes >80ms, increase **Master Multiplier** or **Feedforward**.
 +    * **Bounce-Back Check:** If the curve climbs above **1.0** (e.g., peaks at **1.15**) and dips back down, increase the **P and D Gain (Damping)** slider by **0.05–0.1** (or lower Feedforward slightly).
 +    * **Oscillation Check:** If the curve waves up and down multiple times like a sine wave after hitting 1.0, lower the **Master Multiplier** slider by **0.1**.
 +
 +<note important>
 +**Log-Based Tuning Loop:** Make **one** slider adjustment based on your PIDtoolbox graphs, flash the change, fly the exact same 30-second test routine, and compare the new Step Response curve directly against the previous log using PIDtoolbox's multi-file overlay feature.
 +</note>
 +
 +
 ====== Step-by-Step Betaflight Slider Tuning Workflow ====== ====== Step-by-Step Betaflight Slider Tuning Workflow ======
  
drone/maint/pid_tuning.1795097549.txt.gz · Last modified: by Jon