From 7ab904457cf3cccfb2ac01925efd66ef2d6bf7de Mon Sep 17 00:00:00 2001 From: RomanBapst Date: Mon, 16 Nov 2026 10:47:28 +0300 Subject: [PATCH] fix(tecs): assume gliding in the pitch loop without a throttle range At speed weight 2 the pitch flies airspeed only and its climb angle follows from the total energy rate. With the setpoint's rate it pitched towards the altitude demand, which a glider has no throttle to deliver, so it held the airspeed only once the integrator had given the demand up. With no throttle range (FW_THR_MAX = FW_THR_MIN, also a gliding waypoint) the pitch now takes the minimum total energy rate, the glide, as fast descend and underspeed already do. Limited to speed weight 2: below it the throttle range also closes at the end of the landing flare, where the pitch keeps flying the height rate setpoint. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: RomanBapst --- docs/en/flight_stack/controller_diagrams.md | 1 + src/lib/tecs/TECS.cpp | 13 ++++++++++++- src/lib/tecs/TECSControlClosedLoopTest.cpp | 14 ++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/en/flight_stack/controller_diagrams.md b/docs/en/flight_stack/controller_diagrams.md index b95f96c8371..120546786c2 100644 --- a/docs/en/flight_stack/controller_diagrams.md +++ b/docs/en/flight_stack/controller_diagrams.md @@ -197,6 +197,7 @@ With an airspeed setpoint at or below trim there is no middle region, and pitch These regions apply up to a speed weight of 1 and are faded out as the speed weight goes from 1 to 2, so with a weight of 2 pitch alone tracks the full airspeed setpoint. Gliders, which have no throttle to accelerate with, should therefore use `FW_T_SPDWEIGHT` = 2. +Gliders should also set [FW_THR_MAX](../advanced_config/parameter_reference.md#FW_THR_MAX) equal to [FW_THR_MIN](../advanced_config/parameter_reference.md#FW_THR_MIN): with a speed weight of 2 and no throttle range, pitch assumes the vehicle glides at the minimum sink rate ([FW_T_SINK_MIN](../advanced_config/parameter_reference.md#FW_T_SINK_MIN)) instead of flying the climb or descent rate demanded by the altitude setpoint. The speed weight is also raised towards 2 automatically during underspeed recovery and fast descend, which therefore still use pitch to reach their airspeed setpoint. ## Fixed-Wing Attitude Controller diff --git a/src/lib/tecs/TECS.cpp b/src/lib/tecs/TECS.cpp index 22a1d84a273..ed55509c237 100644 --- a/src/lib/tecs/TECS.cpp +++ b/src/lib/tecs/TECS.cpp @@ -580,7 +580,18 @@ float TECSControl::_calcPitchControlSteRate(const STERateLimit &limit, // on the maximum throttle it commands (failed engine, throttle still slewing up, less excess power near stall). // Assume gliding, the minimum total energy rate, in both. If the throttle does deliver in underspeed, the // airspeed recovers faster. - return lerp(ste_rate_pair, limit.STE_rate_min, constrain(max(param.fast_descend, _ratio_undersped), 0.f, 1.f)); + float gliding_ratio = constrain(max(param.fast_descend, _ratio_undersped), 0.f, 1.f); + + // A glider (speed weight 2 with no throttle range, also a gliding waypoint) has no throttle to deliver the + // setpoint's total energy rate at all: it always glides. Not applied below speed weight 2, where the throttle + // range also closes at the end of the landing flare and the pitch keeps flying the height rate setpoint. + const bool no_throttle_range = param.throttle_max - param.throttle_min < FLT_EPSILON; + + if (no_throttle_range && param.pitch_speed_weight > 2.f - FLT_EPSILON) { + gliding_ratio = 1.f; + } + + return lerp(ste_rate_pair, limit.STE_rate_min, gliding_ratio); } float TECSControl::_calcPitchControlOutput(const Input &input, const ControlValues &seb_rate, float ste_rate_setpoint, diff --git a/src/lib/tecs/TECSControlClosedLoopTest.cpp b/src/lib/tecs/TECSControlClosedLoopTest.cpp index 117d207c10d..2aaa530ff03 100644 --- a/src/lib/tecs/TECSControlClosedLoopTest.cpp +++ b/src/lib/tecs/TECSControlClosedLoopTest.cpp @@ -541,18 +541,16 @@ TEST_F(TECSControlClosedLoopTest, AltitudeStepUpDefaultTuningPitchOffset) // --- Gliding at speed weight 2 --------------------------------------------------- // // Speed weight 2 is the glider setting: the pitch flies airspeed only, so it tracks an airspeed setpoint with no -// propulsion at all. -// -// Disabled: at speed weight 2 the climb angle follows entirely from the total energy rate the throttle delivers, -// gamma = (SEB rate + 2 STE rate) / (2 g V). The pitch takes it from the setpoint, which with a failed throttle is -// never delivered, so the pitch flies the altitude demand. Needs the pitch to assume gliding at speed weight 2. +// propulsion at all. A glider has no throttle range (throttle max = min). Its climb angle follows from the total energy +// rate, gamma = (SEB rate + 2 STE rate) / (2 g V), which the pitch must take as the glide (minimum total energy rate), +// not the altitude demand of the setpoint, which no throttle delivers. -TEST_F(TECSControlClosedLoopTest, DISABLED_GlideSpeedWeightTwoAirspeedStep) +TEST_F(TECSControlClosedLoopTest, GlideSpeedWeightTwoAirspeedStep) { _params.pitch_speed_weight = 2.f; + _params.throttle_max = _params.throttle_min; + _throttle = _params.throttle_min; - run(10.f); - _throttle_failed = true; run(60.f); // settle into the glide setAirspeedSetpoint(_params.equivalent_airspeed_trim + AIRSPEED_STEP);