From 261f9b4b668c5b9481822f499c9aada58024f488 Mon Sep 17 00:00:00 2001 From: Ray Morris Date: Tue, 15 Sep 2026 21:29:07 -0500 Subject: [PATCH] Fix inverted tpa_pitch_compensation documentation and comment The description and inline comment for tpa_pitch_compensation stated "increase throttle when pitching up" - but the code and its own math (groundCos positive while diving) actually raise the virtual TPA throttle - and so attenuate PID gains - when pitching down, not up. This is the aerodynamically correct direction: diving increases airspeed, so gains should attenuate; climbing reduces airspeed, so gains should stay more aggressive. #11952 previously investigated this same mismatch and concluded the *code* was backwards, adding a sign flip to make it match the (incorrectly worded) documentation - which would have made behavior wrong in flight. This corrects the documentation and comment instead, leaving the working code untouched. Claude-Session: https://claude.ai/code/session_01BUNPAbSF46z9QMPqTVWjv4 --- docs/Settings.md | 2 +- src/main/fc/settings.yaml | 2 +- src/main/flight/pid.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index 16161b870f1..eea71ea4f56 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -6454,7 +6454,7 @@ Throttle PID attenuation also reduces influence on YAW for multi-rotor, Should b ### tpa_pitch_compensation -Pitch angle based throttle compensation for fixed wing. Positive values will increase throttle when pitching up, and decrease throttle when pitching down. +Pitch angle based throttle compensation for fixed wing, used as a proxy for airspeed when no airspeed sensor is fitted. Positive values will increase this virtual throttle (attenuating PID gains) when pitching down, and decrease it when pitching up, since diving increases airspeed and climbing reduces it. | Default | Min | Max | | --- | --- | --- | diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 177dcb00521..67c722b481a 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -1399,7 +1399,7 @@ groups: min: PWM_RANGE_MIN max: PWM_RANGE_MAX - name: tpa_pitch_compensation - description: "Pitch angle based throttle compensation for fixed wing. Positive values will increase throttle when pitching up, and decrease throttle when pitching down." + description: "Pitch angle based throttle compensation for fixed wing, used as a proxy for airspeed when no airspeed sensor is fitted. Positive values will increase this virtual throttle (attenuating PID gains) when pitching down, and decrease it when pitching up, since diving increases airspeed and climbing reduces it." default_value: 8 field: throttle.tpa_pitch_compensation min: 0 diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index 9beda7ae225..1ec02fd8ff9 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -517,7 +517,7 @@ static float calculateTPAThtrottle(void) if (usedPidControllerType == PID_TYPE_PIFF && (currentControlProfile->throttle.fixedWingTauMs > 0)) { //fixed wing TPA with filtering fpVector3_t vForward = { .v = { HeadVecEFFiltered.x, -HeadVecEFFiltered.y, -HeadVecEFFiltered.z } }; float groundCos = vectorDotProduct(&vForward, &vDown); - int16_t throttleAdjustment = currentControlProfile->throttle.tpa_pitch_compensation * groundCos * 90.0f / 1.57079632679f; //when 1deg pitch up, increase throttle by pitch(deg)_to_throttle. cos(89 deg)*90/(pi/2)=0.99995,cos(80 deg)*90/(pi/2)=9.9493, + int16_t throttleAdjustment = currentControlProfile->throttle.tpa_pitch_compensation * groundCos * 90.0f / 1.57079632679f; //groundCos is positive while diving; this raises the virtual throttle (and so attenuates PID gains) when pitching down, since diving increases airspeed. cos(89 deg)*90/(pi/2)=0.99995,cos(80 deg)*90/(pi/2)=9.9493, uint16_t throttleAdjusted = rcCommand[THROTTLE] + constrain(throttleAdjustment, -1000, 1000); tpaThrottle = pt1FilterApply(&fixedWingTpaFilter, constrain(throttleAdjusted, 1000, 2000)); }