Skip to content

docs(autotune): fix fixed-wing autotune docs to match actual behavior#11676

Closed
sensei-hacker wants to merge 293 commits into
iNavFlight:release/9.1from
sensei-hacker:docs/fix-fw-autotune-documentation
Closed

docs(autotune): fix fixed-wing autotune docs to match actual behavior#11676
sensei-hacker wants to merge 293 commits into
iNavFlight:release/9.1from
sensei-hacker:docs/fix-fw-autotune-documentation

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Summary

The fixed-wing AUTOTUNE documentation no longer matched the current implementation in src/main/flight/pid_autotune.c. A user reported confusion after their rates changed significantly during an AUTOTUNE flight, which they didn't expect based on the docs.

Changes

  • Corrected the pre-flight parameter table: roll_rate/pitch_rate/yaw_rate are described as fixed limits AUTOTUNE respects, but by default (fw_autotune_rate_adjustment = AUTO) AUTOTUNE actively rewrites them while flying. Documented all three fw_autotune_* settings that control this.
  • Removed the claim that AUTOTUNE sets P and I gains - that formula (P/I/D derived from FF) was removed from the code in 2021 (9dcf985b0c, "Don't change P, I and D during autotune"). AUTOTUNE only ever tunes FeedForward gain and, conditionally, rate.
  • Added yaw to the flying instructions - the code tunes yaw identically to roll/pitch (own FF, own rate, own minimum rate floor), but the doc only described roll/pitch maneuvers.
  • Documented the flight-mode dependency: rate is tuned in ACRO/HORIZON but not ANGLE mode (FF still is), and AUTOTUNE has no effect at all - not even FeedForward - while flying in MANUAL mode (pid.c:881).

Testing

Documentation-only change; no firmware behavior changed, so no build/SITL testing applies. Every factual claim was checked directly against the source:

  • src/main/flight/pid_autotune.c (core tuning logic, rate/FF update conditions, min/max rate constants)
  • src/main/flight/pid.c (pidApplyFixedWingRateController, HORIZON-mode rate blending)
  • src/main/fc/fc_core.c (ANGLE_MODE/HORIZON_MODE/MANUAL_MODE flag semantics)
  • src/main/fc/settings.yaml (fw_autotune_rate_adjustment, fw_autotune_min_stick, fw_autotune_max_rate_deflection defaults and valid values)

Code Review

Reviewed with the inav-code-review agent, used specifically to independently verify every claim in this doc against the code above. It caught one real error in a companion wiki doc (AUTOTUNE incorrectly described as active in MANUAL mode) before this was opened; that's fixed in the companion inavwiki PR.

Related

Companion doc fix in the inavwiki repo (AUTOTUNE section of Modes.md) covers the same inaccuracies for the wiki's mode reference page.

daijoubu and others added 30 commits February 5, 2026 06:39
… the MATEKF765SE. Allocate memory for the bxCan write and read messages.
…dle to the CAN instance to avoid a dangling pointer.
…fer and the task reads from the ring buffer.

Fix missing include for math.h
Expand dronecan_messages_unittest.cc from 5 to 14 tests covering
NodeStatus, Fix v1, Auxiliary, boundary values, and data type
verification. Create canard_unittest.cc with 30 tests for the
libcanard core: init/node ID, memory pool, CRC-16/CCITT, float16
conversion, transfer ID logic, DLC conversion, single/multi-frame
TX, RX frame processing, and pool statistics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The BatteryInfo message already contains current data which was being
stored in dronecanBattSensorGetAmperage(), but this wasn't integrated
with INAV's battery metering system.

Changes:
- Add CURRENT_SENSOR_CAN enum value in battery_config_structs.h
- Add case handler in battery.c to read current from DroneCAN
- Update settings.yaml to expose CAN option for current_meter_type

Users can now select 'CAN' as the current_meter_type in CLI when using
DroneCAN-compatible battery sensors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
daijoubu and others added 25 commits May 29, 2026 20:23
PLL2M was hardcoded to 5, which assumes HSE = 8 MHz. On KAKUTEH7WING
(HSE = 16 MHz) this gives VCO = 16/5 * 500 = 1600 MHz (out of spec)
and SDMMC clock = 400 MHz instead of the required 200 MHz.

Fix: compute PLL2M as HSE_VALUE / 1600000, pinning the VCO input to
exactly 1.6 MHz for any HSE frequency. With N=500 this gives VCO=800 MHz:

  HSE=8 MHz:  M=5,  N=500 → VCO=800 MHz (identical to original)
  HSE=16 MHz: M=10, N=500 → VCO=800 MHz (correct for KAKUTEH7WING)

PLL2R/4 = 200 MHz (SDMMC), PLL2P/2 = 400 MHz. VCIRANGE_0 (1–2 MHz)
is correct for the 1.6 MHz VCI input on all targets.

Also adds STATIC_ASSERT to catch future targets with non-multiple HSE,
and corrects the PLL2P comment (was "500Mhz", should be "400Mhz").

Fixes iNavFlight#11594
If PLL2 fails to lock at startup the SDMMC clock is dead and the SD
card will fail silently. Call Error_Handler() (infinite loop) on
failure to make the fault visible rather than continuing into
undefined behaviour.
PLL1 VCI input is HSE/M = 2 MHz on all H7 targets, which falls in the
2-4 MHz range (VCIRANGE_1). The previous VCIRANGE_2 (4-8 MHz) was
incorrect and affected PLL charge pump calibration.

Fixes iNavFlight#11602
Remove redundant prose that duplicated the assert, remove board-specific
name from shared init code, and shorten the assert slug to match
codebase conventions.
…mic-m-divider

fix: make PLL2M dynamic to keep VCO=800MHz for any HSE frequency (closes iNavFlight#11594)
Fix: Prioritize Airspeed over GPS for turn acceleration compensation
…2688-devhw

Fix ICM42688 bus device hardware type on GEPRC targets
…x_fixed_value

VTOL.md: Rename smix max fixed value
* Add new target: AEDROXH7 (Airbot Systems AEDROX H7)

STM32H743 flight controller with ICM42688P gyro, W25N01G NAND flash,
DPS310 baro, MAX7456 analog OSD, HD OSD via MSP DisplayPort, and
8 motor outputs split across TIM1 and TIM8.

SPI3 MOSI on PB2 requires explicit GPIO_AF7_SPI3 override.
Magnetometer enabled on I2C1 (hardware present, not in BF config).

* AEDROXH7: replace UART4 with DroneCAN on PD0/PD1

PD0/PD1 connect to the CAN transceiver (CANL/CANH pads visible on
board), not to a user-accessible UART4 header. Replace UART4 with
USE_DRONECAN defines. CAN standby pin TBD pending INAV syntax
confirmation.

* AEDROXH7: add CAN1_STANDBY PD3 (not yet tested)

* CI: re-trigger build to pick up fc_msp.c sign-compare fix in maintenance-9.x
…nance-10.x

Removes the DroneCAN DSDLC library (lib/main/Dronecan -- entirely new in 10.x)
and reverts STM32F4/F7/H7 HAL libraries to their maintenance-9.x versions.
932 files. No post-merge commits touched lib/ -- this is a clean mechanical revert.
Reverts 319 STM32CubeF7 SDK extraction files introduced by the accidental
maintenance-10.x merge. No post-merge commits touched this directory --
this is a clean mechanical revert.
This reverts commit 10343b4, reversing
changes made to bb61218.
…-merge

Revert accidental merge of maintenance-10.x into maintenance-9.x
Removed redundant phrases and clarified manufacturer information.
…e-ordering-stdperiph

drivers: fix DMA request disable ordering in timer IRQ handlers and stop functions
Add support for XTX XT25F128F nor flash chip
…WINGMINI

Add FlyingRC F4Wing Mini target updates
Roll/pitch/yaw rates are described as a fixed ceiling autotune
respects; in reality, with the default fw_autotune_rate_adjustment
setting, autotune actively rewrites roll_rate/pitch_rate/yaw_rate
while flying. The doc also claimed autotune sets P and I gains,
which hasn't been true since gain the P/I/D-from-FF formula was
removed in 2021. Neither yaw nor the MANUAL-mode no-op were
mentioned.

Rewrites the pre-flight parameter table and flying instructions to
describe what the code actually does: FeedForward is tuned on all
three axes, P/I are never touched, rate tuning depends on flight
mode and fw_autotune_rate_adjustment, and AUTOTUNE has no effect at
all in MANUAL mode.
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Fix fixed-wing AUTOTUNE docs to match current firmware behavior

📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Clarify AUTOTUNE tunes FF always, and rate only in ACRO/HORIZON
• Correct pre-flight parameters: rates are starting points unless rate adjustment is FIXED
• Document MANUAL-mode no-op and include yaw maneuvers in flight instructions
Diagram

graph TD
  P[Pilot] --> D["Autotune - fixedwing.md"] --> M[AUTOTUNE modifier] --> L[PID autotune logic]
  M --> S[Settings/params]
  S --> R[Rate & FF updates]
  L --> R

  subgraph Legend
    direction LR
    _usr[Pilot] ~~~ _doc[Documentation] ~~~ _mod[Mode/feature] ~~~ _cfg[Configuration] ~~~ _logic[Logic]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Auto-generate parameter table from settings metadata
  • ➕ Reduces drift between docs and defaults/valid values
  • ➕ Makes future parameter additions/renames harder to miss
  • ➖ Requires tooling and a doc generation pipeline
  • ➖ Does not cover behavioral/mode-gating narrative text
2. Add firmware-side, versioned behavior notes and link from docs
  • ➕ Clearly communicates behavior changes across releases (e.g., P/I no longer tuned)
  • ➕ Gives users a canonical source tied to code version
  • ➖ Adds ongoing maintenance overhead to keep notes current
  • ➖ Doesn’t prevent doc text from drifting if not enforced
3. Add a lightweight doc validation checklist in CI
  • ➕ Encourages verifying docs against source during code changes
  • ➕ Can catch obvious contradictions early (e.g., MANUAL-mode no-op)
  • ➖ Hard to automate semantic correctness beyond simple assertions
  • ➖ May add process friction without strong signal

Recommendation: The PR’s approach (directly correcting the narrative to match current implementation) is the right immediate fix for user confusion. If this area continues to churn, consider auto-generating the parameter/defaults table from settings metadata to prevent future drift, while keeping the higher-level behavioral guidance manual and version-aware.

Files changed (1) +20 / -11

Documentation (1) +20 / -11
Autotune - fixedwing.mdAlign fixed-wing AUTOTUNE behavior docs with current tuning logic +20/-11

Align fixed-wing AUTOTUNE behavior docs with current tuning logic

• Rewrites the AUTOTUNE behavior description to reflect current firmware: FF is tuned on all axes when stick input is sufficient, rate changes are conditional (ACRO/HORIZON and non-FIXED adjustment), and MANUAL mode is a no-op. Updates the pre-flight parameter table to clarify that roll/pitch/yaw rates are starting points (unless FIXED) and documents the fw_autotune_* settings, plus adds yaw maneuvers and mode-specific flying guidance.

docs/Autotune - fixedwing.md

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Rate-mode docs mismatch 🐞 Bug ≡ Correctness
Description
The docs state rate (roll_rate/pitch_rate/yaw_rate) is only tuned in ACRO/HORIZON, but the
implementation updates rates in any non-ANGLE mode (including ANGLEHOLD) when
fw_autotune_rate_adjustment != FIXED, so users can still have rates adjusted outside ACRO/HORIZON.
Code

docs/Autotune - fixedwing.md[R11-13]

+* **FeedForward (FF) gain** - in ANGLE, HORIZON or ACRO, whenever you give it enough hard stick input to learn from
+* **Rate** (`roll_rate`/`pitch_rate`/`yaw_rate`) - only while flying in ACRO or HORIZON, and only if `fw_autotune_rate_adjustment` is not set to `FIXED` (see below). Rate is never adjusted while flying in ANGLE mode.
+
Evidence
Rate adjustment is gated by !FLIGHT_MODE(ANGLE_MODE) (not by ACRO/HORIZON), and ANGLEHOLD is a
distinct flight mode that does not set ANGLE_MODE, so AUTOTUNE can still update rates there when
active.

src/main/flight/pid_autotune.c[189-224]
src/main/fc/fc_core.c[686-699]
src/main/flight/pid.c[1276-1296]
src/main/flight/pid.c[880-883]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The documentation claims that AUTOTUNE rate adjustment happens only in ACRO/HORIZON, but the firmware gates rate adjustment only on `!ANGLE_MODE` (and not MANUAL). This makes the docs inaccurate for modes like `ANGLEHOLD_MODE`.

### Issue Context
- `autotuneFixedWingUpdate()` adjusts rates whenever `fw_rate_adjustment != FIXED` and `!FLIGHT_MODE(ANGLE_MODE)`.
- `ANGLEHOLD_MODE` is enabled separately from `ANGLE_MODE`, so rate adjustment can occur while flying in ANGLEHOLD.

### Fix Focus Areas
- docs/Autotune - fixedwing.md[11-13]
- docs/Autotune - fixedwing.md[56-58]

Suggested doc direction:
- Replace “only in ACRO/HORIZON” with “in any non-ANGLE mode” (and still recommend ACRO/HORIZON for best results), or explicitly mention ANGLEHOLD as also allowing rate changes.
- Keep the “no effect in MANUAL” statement.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +11 to +13
* **FeedForward (FF) gain** - in ANGLE, HORIZON or ACRO, whenever you give it enough hard stick input to learn from
* **Rate** (`roll_rate`/`pitch_rate`/`yaw_rate`) - only while flying in ACRO or HORIZON, and only if `fw_autotune_rate_adjustment` is not set to `FIXED` (see below). Rate is never adjusted while flying in ANGLE mode.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Rate-mode docs mismatch 🐞 Bug ≡ Correctness

The docs state rate (roll_rate/pitch_rate/yaw_rate) is only tuned in ACRO/HORIZON, but the
implementation updates rates in any non-ANGLE mode (including ANGLEHOLD) when
fw_autotune_rate_adjustment != FIXED, so users can still have rates adjusted outside ACRO/HORIZON.
Agent Prompt
### Issue description
The documentation claims that AUTOTUNE rate adjustment happens only in ACRO/HORIZON, but the firmware gates rate adjustment only on `!ANGLE_MODE` (and not MANUAL). This makes the docs inaccurate for modes like `ANGLEHOLD_MODE`.

### Issue Context
- `autotuneFixedWingUpdate()` adjusts rates whenever `fw_rate_adjustment != FIXED` and `!FLIGHT_MODE(ANGLE_MODE)`.
- `ANGLEHOLD_MODE` is enabled separately from `ANGLE_MODE`, so rate adjustment can occur while flying in ANGLEHOLD.

### Fix Focus Areas
- docs/Autotune - fixedwing.md[11-13]
- docs/Autotune - fixedwing.md[56-58]

Suggested doc direction:
- Replace “only in ACRO/HORIZON” with “in any non-ANGLE mode” (and still recommend ACRO/HORIZON for best results), or explicitly mention ANGLEHOLD as also allowing rate changes.
- Keep the “no effect in MANUAL” statement.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@sensei-hacker sensei-hacker changed the base branch from maintenance-9.x to release/9.1 July 1, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.