From 2930dbcbe80ed0c8a7c974b5fedbe62df650582c Mon Sep 17 00:00:00 2001 From: b14ckyy <33039058+b14ckyy@users.noreply.github.com> Date: Wed, 2 Dec 2026 11:00:26 +0100 Subject: [PATCH 1/5] FW nav: bank ceiling on turn arcs and loiter follows nav_fw_bank_angle The arc controller could bank up to max_angle_inclination_rll to hold its radius in wind. With that limit raised to 85 deg for stick feel, windy coordinated turns and loiters banked far beyond the navigation bank. The ceiling is now nav_fw_bank_angle plus a fixed reserve of 30 % more lateral acceleration, still capped by max_angle_inclination_rll. With the defaults (35 / 45 deg) it drops from 45 to 42.3 deg. Co-Authored-By: Claude Fable 5.2 --- docs/Settings.md | 2 +- docs/development/fw-turn-debugging.md | 6 +++--- src/main/fc/settings.yaml | 2 +- src/main/navigation/navigation_fixedwing.c | 9 ++++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/Settings.md b/docs/Settings.md index a0bdc187935..4038d976ea9 100644 --- a/docs/Settings.md +++ b/docs/Settings.md @@ -3772,7 +3772,7 @@ P gain of auto speed PID controller. ### nav_fw_bank_angle -Maximum sustained roll angle when turning in GPS assisted modes: the target bank that turn and loiter radii are planned for. Corrections may exceed it temporarily; the absolute ceiling remains max_angle_inclination_rll +Maximum sustained roll angle when turning in GPS assisted modes: the target bank that turn and loiter radii are planned for. Wind corrections on turn arcs and the loiter circle may exceed it by a fixed reserve of 30 % more lateral acceleration (e.g. 35° -> about 42°), never above max_angle_inclination_rll | Default | Min | Max | | --- | --- | --- | diff --git a/docs/development/fw-turn-debugging.md b/docs/development/fw-turn-debugging.md index 49ec76eacd9..71c76e6a97c 100644 --- a/docs/development/fw-turn-debugging.md +++ b/docs/development/fw-turn-debugging.md @@ -16,7 +16,7 @@ blackbox logging. | 3 | Remaining heading to the exit course | centideg | Arc coordinator, only while engaged | | 4 | Arc bank command | centideg | Arc coordinator, only while engaged; clamped to the effective bank ceiling | | 5 | WP-turn roll feed-forward | centideg | Feed-forward (0 when disabled, loitering, or inside the heading deadband) | -| 6 | Energy-guard bank ceiling | deg | Energy bank guard (sits at `max_angle_inclination_rll` unless the guard is reducing it) | +| 6 | Energy-guard bank ceiling | deg | Energy bank guard (sits at the bank ceiling, `nav_fw_bank_angle` plus a 30 % lateral-acceleration reserve capped by `max_angle_inclination_rll`, unless the guard is reducing it) | | 7 | Roll ease time | ms | Arc coordinator, only while engaged (sizes the entry/exit ramps and the turn-start lead) | Channels 2, 3, 4 and 7 hold their last value after the arc disengages; check channel 1 to know @@ -54,6 +54,6 @@ rolling out of the S's second arc; `3` (idle) = S finished, coordinator handed b A healthy COORD_FLYBY corner shows: channel 1 stepping `10 → 20 → 30 → 0`, channel 4 ramping to the nominal bank, holding, then collapsing as channel 3 converges to 0 without overshoot. The hand-back happens aligned (|ch3| small) and nearly level (|ch4| < 10% of nominal). Channel 4 -pegged at channel 6 × 100 indicates the command is saturated at the flyable ceiling — expected -briefly downwind, a problem if sustained. Channel 6 dropping below `max_angle_inclination_rll` +pegged at about channel 6 × 100 (channel 6 is in whole degrees) indicates the command is saturated at the flyable ceiling — expected +briefly downwind, a problem if sustained. Channel 6 dropping below that bank ceiling means the energy guard is trading bank for climb capability. diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 142f5f06c9b..1f2b854c130 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -3113,7 +3113,7 @@ groups: field: mc.slowDownForTurning type: bool - name: nav_fw_bank_angle - description: "Maximum sustained roll angle when turning in GPS assisted modes: the target bank that turn and loiter radii are planned for. Corrections may exceed it temporarily; the absolute ceiling remains max_angle_inclination_rll" + description: "Maximum sustained roll angle when turning in GPS assisted modes: the target bank that turn and loiter radii are planned for. Wind corrections on turn arcs and the loiter circle may exceed it by a fixed reserve of 30 % more lateral acceleration (e.g. 35° -> about 42°), never above max_angle_inclination_rll" default_value: 35 field: fw.max_bank_angle min: 5 diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index dcfc6d17b5f..8b4fca72940 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -86,6 +86,7 @@ #define NAV_FW_ARC_EXIT_BANK_CD 1000.0f // [centideg] ... and below this bank; the residual hands over into the tracker #define NAV_FW_ARC_AWAY_TIMEOUT_FACTOR 1.5f // half away-circle traverse times, before the away arc is abandoned #define NAV_FW_ARC_SHARP_TURN_CD 15000 // [centideg] beyond this the tangents explode toward the reversal -> capture only +#define NAV_FW_BANK_RESERVE_FACTOR 1.3f // lateral-accel reserve over nav_fw_bank_angle for wind correction on arcs/loiter // FW energy/altitude bank guard thresholds (conservative; observable via DEBUG_FW_TURN) #define NAV_FW_GUARD_PHI_FLOOR_DEG 15.0f // minimum effective bank limit @@ -521,13 +522,15 @@ static float applyFwRollInSmoothing(float rollTargetCd, timeDelta_t deltaMicros, return out; } -// Hard roll ceiling [deg]: the global angle-mode limit (max_angle_inclination_rll) +// Hard roll ceiling [deg]: max_angle_inclination_rll is a stick-feel limit and must not become a nav bank static float getFwBankCeilingDeg(void) { - return (float)pidProfile()->max_angle_inclination[FD_ROLL] / 10.0f; + const float bankRad = DEGREES_TO_RADIANS((float)navConfig()->fw.max_bank_angle); + const float reserveDeg = RADIANS_TO_DEGREES(atan2_approx(NAV_FW_BANK_RESERVE_FACTOR * sin_approx(bankRad), cos_approx(bankRad))); + return MIN(reserveDeg, (float)pidProfile()->max_angle_inclination[FD_ROLL] / 10.0f); } -// Output bank ceiling [deg]: hard ceiling reduced by the energy guard; nav_fw_bank_angle is only the planning target +// Output bank ceiling [deg]: hard ceiling reduced by the energy guard static float getFwEffectiveBankLimit(void) { const float ceiling = getFwBankCeilingDeg(); From cf63582c8b550619b78af4301ad1e09b44c157b5 Mon Sep 17 00:00:00 2001 From: b14ckyy <33039058+b14ckyy@users.noreply.github.com> Date: Wed, 2 Dec 2026 11:12:35 +0100 Subject: [PATCH 2/5] FW nav: cache the bank ceiling between setting changes The ceiling is read on every PID loop; its trig only depends on two settings. Co-Authored-By: Claude Fable 5.2 --- src/main/navigation/navigation_fixedwing.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index 8b4fca72940..f04964ec3a9 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -525,9 +525,21 @@ static float applyFwRollInSmoothing(float rollTargetCd, timeDelta_t deltaMicros, // Hard roll ceiling [deg]: max_angle_inclination_rll is a stick-feel limit and must not become a nav bank static float getFwBankCeilingDeg(void) { - const float bankRad = DEGREES_TO_RADIANS((float)navConfig()->fw.max_bank_angle); - const float reserveDeg = RADIANS_TO_DEGREES(atan2_approx(NAV_FW_BANK_RESERVE_FACTOR * sin_approx(bankRad), cos_approx(bankRad))); - return MIN(reserveDeg, (float)pidProfile()->max_angle_inclination[FD_ROLL] / 10.0f); + static float ceilingDeg; + static int16_t cachedInclination; + static uint8_t cachedBank; + + const uint8_t bank = navConfig()->fw.max_bank_angle; + const int16_t inclination = pidProfile()->max_angle_inclination[FD_ROLL]; + // Called every PID loop: redo the trig only when a setting changes + if (bank != cachedBank || inclination != cachedInclination) { + const float bankRad = DEGREES_TO_RADIANS((float)bank); + const float reserveDeg = RADIANS_TO_DEGREES(atan2_approx(NAV_FW_BANK_RESERVE_FACTOR * sin_approx(bankRad), cos_approx(bankRad))); + ceilingDeg = MIN(reserveDeg, (float)inclination / 10.0f); + cachedBank = bank; + cachedInclination = inclination; + } + return ceilingDeg; } // Output bank ceiling [deg]: hard ceiling reduced by the energy guard From f97a4be622f0a6e34dae5a8e146b7a0b57351fd0 Mon Sep 17 00:00:00 2001 From: b14ckyy <33039058+b14ckyy@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:42:31 +0100 Subject: [PATCH 3/5] FW nav: no turn arc when the turn-in point is already behind the aircraft Entering WP mode more than 30 deg off the bearing to the first waypoint planned a corner arc. The leg starts at the aircraft there, so the circle's turn-in tangency lies behind it and the aircraft starts well outside the circle. The arc law then demanded 80-95 deg of bank and the command ran to the bank ceiling (tester log: 73 deg bank, 60 deg heading overshoot). Such a turn now flies the bounded leg capture, limited to nav_fw_bank_angle. Co-Authored-By: Claude Fable 5.2 --- src/main/navigation/navigation_fixedwing.c | 33 ++++++----- .../navigation_fixedwing_turn_math.c | 6 ++ .../navigation_fixedwing_turn_math.h | 1 + ...navigation_fixedwing_turn_math_unittest.cc | 56 +++++++++++++++++++ 4 files changed, 83 insertions(+), 13 deletions(-) diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index f04964ec3a9..90dd3d4b26a 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -951,18 +951,10 @@ static void fwArcPlanCornerTurn(const fwArcCtx_t *c, bool capped) fwPlanTurn(c->v, &plan); const float omegaNomCds = DEGREES_TO_CENTIDEGREES(RADIANS_TO_DEGREES(c->v / plan.r)); // v/R == g*tan(phi)/v const float psiTmp = 0.5f * omegaNomCds * (plan.tEaseMs / 1000.0f); - if (capped || ABS(c->hdgErrToLeg) > NAV_FW_ARC_SHARP_TURN_CD) { - // Capped or near-reversal: no valid tangent circle - fly the bounded capture directly - fwTurn.arc.engaged = true; - fwTurn.arc.bankCmd = c->lastNavRollCmdCd; // blend from the current command: no engage step - fwTurn.arc.rampMs = 0.0f; - fwTurn.arc.rampStartCd = 0.0f; - fwTurn.arc.r = plan.r; // capture ignores it, but the away timeout is sized from it - fwTurn.arc.dir = (c->hdgErrToLeg > 0) ? 1 : -1; - fwTurn.arc.phiNomCd = plan.phiNomCd; - fwTurn.arc.tEaseMs = plan.tEaseMs; - fwArcCaptureToLeg(c->legBearing); - } else if (2.0f * psiTmp < (float)ABS(c->hdgErrToLeg)) { // enough turn left for a steady arc between the ease ramps + if (!capped && ABS(c->hdgErrToLeg) <= NAV_FW_ARC_SHARP_TURN_CD) { + if (!(2.0f * psiTmp < (float)ABS(c->hdgErrToLeg))) { // too little turn for a steady arc between the ease ramps + return; + } const int8_t dirTmp = (c->hdgErrToLeg > 0) ? 1 : -1; // Centre = intersection of both legs shifted R inside (inscribed circle), so the exit lands ON the out-leg const float cogRad = CENTIDEGREES_TO_RADIANS((float)c->cog); @@ -978,8 +970,23 @@ static void fwArcPlanCornerTurn(const fwArcCtx_t *c, bool capped) cx = p1x; cy = p1y; } - fwArcEngageRampIn(&plan, dirTmp, cx, cy, c->legBearing, c->lastNavRollCmdCd); + // Turn-in tangency already behind us: the arc law would start far outside the circle and saturate the bank + if (fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y) >= 0.0f) { + fwArcEngageRampIn(&plan, dirTmp, cx, cy, c->legBearing, c->lastNavRollCmdCd); + return; + } } + + // Capped, near-reversal or past the turn-in point: no valid tangent circle - fly the bounded capture directly + fwTurn.arc.engaged = true; + fwTurn.arc.bankCmd = c->lastNavRollCmdCd; // blend from the current command: no engage step + fwTurn.arc.rampMs = 0.0f; + fwTurn.arc.rampStartCd = 0.0f; + fwTurn.arc.r = plan.r; // capture ignores it, but the away timeout is sized from it + fwTurn.arc.dir = (c->hdgErrToLeg > 0) ? 1 : -1; + fwTurn.arc.phiNomCd = plan.phiNomCd; + fwTurn.arc.tEaseMs = plan.tEaseMs; + fwArcCaptureToLeg(c->legBearing); } static void fwArcPlanNewLeg(const fwArcCtx_t *c, bool capped) diff --git a/src/main/navigation/navigation_fixedwing_turn_math.c b/src/main/navigation/navigation_fixedwing_turn_math.c index 8b54fa6e18c..2ee7d340b4b 100644 --- a/src/main/navigation/navigation_fixedwing_turn_math.c +++ b/src/main/navigation/navigation_fixedwing_turn_math.c @@ -109,6 +109,12 @@ float fwOffLegCm(float px, float py, float qx, float qy, float ux, float uy) return (px - qx) * (-uy) + (py - qy) * ux; } +// Signed along-track position [cm] of p ahead of q on the line with unit direction (ux, uy) +float fwAlongLegCm(float px, float py, float qx, float qy, float ux, float uy) +{ + return (px - qx) * ux + (py - qy) * uy; +} + // Ground distance covered while the roll-in ramp builds the bank (k calibrated in flight) float fwRollInLeadCm(float v, float tMs) { diff --git a/src/main/navigation/navigation_fixedwing_turn_math.h b/src/main/navigation/navigation_fixedwing_turn_math.h index 4656cdaef61..09e4f532bf0 100644 --- a/src/main/navigation/navigation_fixedwing_turn_math.h +++ b/src/main/navigation/navigation_fixedwing_turn_math.h @@ -36,4 +36,5 @@ float fwSmoothBlend(float from, float to, float p); float fwSlewToward(float cur, float target, float maxStep); float fwArcMaxStepCd(float phiCd, float tEaseMs, float dtMs); float fwOffLegCm(float px, float py, float qx, float qy, float ux, float uy); +float fwAlongLegCm(float px, float py, float qx, float qy, float ux, float uy); float fwRollInLeadCm(float v, float tMs); diff --git a/src/test/unit/navigation_fixedwing_turn_math_unittest.cc b/src/test/unit/navigation_fixedwing_turn_math_unittest.cc index 1082b0c1ada..4fd919ff9fe 100644 --- a/src/test/unit/navigation_fixedwing_turn_math_unittest.cc +++ b/src/test/unit/navigation_fixedwing_turn_math_unittest.cc @@ -155,6 +155,11 @@ static float ref_offLegCm(float px, float py, float qx, float qy, float legRad) return (px - qx) * (-sin_approx(legRad)) + (py - qy) * cos_approx(legRad); } +static float ref_alongLegCm(float px, float py, float qx, float qy, float legRad) +{ + return (px - qx) * cos_approx(legRad) + (py - qy) * sin_approx(legRad); +} + // P17 @784, 935, 1008 static float ref_rollInLeadCm(float v, float tMs) { @@ -376,3 +381,54 @@ TEST(NavFwTurnMathUnittest, RollInLead) } } } + +TEST(NavFwTurnMathUnittest, AlongLeg) +{ + const float px = 12345.0f, py = -6789.0f; + const float qx = -2200.0f, qy = 33300.0f; + for (int32_t cd = 0; cd < 36000; cd += 37) { + float ux, uy; + fwBearingUnit(cd, &ux, &uy); + const float legRad = CENTIDEGREES_TO_RADIANS((float)cd); + EXPECT_BITS_EQ(fwAlongLegCm(px, py, qx, qy, ux, uy), ref_alongLegCm(px, py, qx, qy, legRad)); + } +} + +// Corner-turn planner chain: along-course distance from the aircraft to the inscribed circle's turn-in tangency +static float cornerEntryAlongCm(float px, float py, int32_t cog, float wpx, float wpy, int32_t leg, float r) +{ + const float dir = (wrap_18000(leg - cog) > 0) ? 1.0f : -1.0f; + float d1x, d1y, d2x, d2y, p1x, p1y, p2x, p2y, cx, cy; + fwBearingUnit(cog, &d1x, &d1y); + fwBearingUnit(leg, &d2x, &d2y); + fwPerpOffset(px, py, r, CENTIDEGREES_TO_RADIANS((float)cog), dir, &p1x, &p1y); + fwPerpOffset(wpx, wpy, r, CENTIDEGREES_TO_RADIANS((float)leg), dir, &p2x, &p2y); + if (!fwLineIntersect(p1x, p1y, d1x, d1y, p2x, p2y, d2x, d2y, 0.087f, &cx, &cy)) { + cx = p1x; + cy = p1y; + } + return fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y); +} + +TEST(NavFwTurnMathUnittest, CornerEntryTangency) +{ + // WP mode entered 103 deg off the leg, the leg starting at the aircraft: tangency 1.26 R behind + const float r = 7580.0f; + const float px = 22396.0f, py = -13081.0f; + float ux, uy; + fwBearingUnit(16440, &ux, &uy); + const float behind = cornerEntryAlongCm(px, py, 6150, px + 30000.0f * ux, py + 30000.0f * uy, 16440, r); + EXPECT_LT(behind, 0.0f); + EXPECT_NEAR(behind, -r * tanf(DEGREES_TO_RADIANS(102.9f / 2.0f)), 50.0f); + + // Regular FLY_BY corner, 90 deg left: on the inbound leg, switched at roll-in lead + R*tan(45 deg) before the WP + const float r2 = 4000.0f; + const float lead = fwRollInLeadCm(2000.0f, 950.0f); + const float wp0x = 50000.0f, wp0y = 20000.0f; + const float ahead = cornerEntryAlongCm(wp0x - (lead + r2), wp0y, 0, wp0x, wp0y - 40000.0f, 27000, r2); + EXPECT_GT(ahead, 0.0f); + EXPECT_NEAR(ahead, lead, 20.0f); + + // Near-parallel legs take the tangent-at-entry fallback: exactly zero, which must still engage the arc + EXPECT_GE(cornerEntryAlongCm(px, py, 22500, px - 5000.0f, py + 9000.0f, 22700, r), 0.0f); +} From f3838008ecfa95e6a44774d140de9271ed0741ff Mon Sep 17 00:00:00 2001 From: b14ckyy <33039058+b14ckyy@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:53:59 +0100 Subject: [PATCH 4/5] FW nav: tolerate a turn-in point up to 10 m behind before dropping the arc A regular corner can engage marginally late; it should keep its arc. Co-Authored-By: Claude Fable 5.2 --- src/main/navigation/navigation_fixedwing.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index 90dd3d4b26a..18d9ae60947 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -86,6 +86,7 @@ #define NAV_FW_ARC_EXIT_BANK_CD 1000.0f // [centideg] ... and below this bank; the residual hands over into the tracker #define NAV_FW_ARC_AWAY_TIMEOUT_FACTOR 1.5f // half away-circle traverse times, before the away arc is abandoned #define NAV_FW_ARC_SHARP_TURN_CD 15000 // [centideg] beyond this the tangents explode toward the reversal -> capture only +#define NAV_FW_ARC_ENTRY_PAST_CM 1000.0f // [cm] turn-in point this far behind still flies the arc: a corner engaged slightly late #define NAV_FW_BANK_RESERVE_FACTOR 1.3f // lateral-accel reserve over nav_fw_bank_angle for wind correction on arcs/loiter // FW energy/altitude bank guard thresholds (conservative; observable via DEBUG_FW_TURN) @@ -970,8 +971,8 @@ static void fwArcPlanCornerTurn(const fwArcCtx_t *c, bool capped) cx = p1x; cy = p1y; } - // Turn-in tangency already behind us: the arc law would start far outside the circle and saturate the bank - if (fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y) >= 0.0f) { + // Turn-in tangency well behind us: the arc law would start far outside the circle and saturate the bank + if (fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y) >= -NAV_FW_ARC_ENTRY_PAST_CM) { fwArcEngageRampIn(&plan, dirTmp, cx, cy, c->legBearing, c->lastNavRollCmdCd); return; } From 831b478dbcdeb11ccf00a6fcbfcfce25b141ba69 Mon Sep 17 00:00:00 2001 From: b14ckyy <33039058+b14ckyy@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:53:02 +0100 Subject: [PATCH 5/5] FW nav: review follow-ups for the turn-in point check - Tolerance is the smaller of 10 m and 0.2 R: on a small radius 10 m behind already drives the arc law into the bank ceiling. - Without WP tracking there is no leg line to capture; leave such a turn to the heading controller, which flies straight at the waypoint. - A reset after a pilot-flown phase also clears the last nav roll command, so a stale bank no longer seeds the arc engage or the handback. Co-Authored-By: Claude Fable 5.2 --- src/main/navigation/navigation_fixedwing.c | 9 +++++++-- src/test/unit/navigation_fixedwing_turn_math_unittest.cc | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/navigation/navigation_fixedwing.c b/src/main/navigation/navigation_fixedwing.c index 18d9ae60947..4c3409076a5 100755 --- a/src/main/navigation/navigation_fixedwing.c +++ b/src/main/navigation/navigation_fixedwing.c @@ -87,6 +87,7 @@ #define NAV_FW_ARC_AWAY_TIMEOUT_FACTOR 1.5f // half away-circle traverse times, before the away arc is abandoned #define NAV_FW_ARC_SHARP_TURN_CD 15000 // [centideg] beyond this the tangents explode toward the reversal -> capture only #define NAV_FW_ARC_ENTRY_PAST_CM 1000.0f // [cm] turn-in point this far behind still flies the arc: a corner engaged slightly late +#define NAV_FW_ARC_ENTRY_PAST_R 0.2f // ... but never more than this fraction of the radius, where the arc law saturates #define NAV_FW_BANK_RESERVE_FACTOR 1.3f // lateral-accel reserve over nav_fw_bank_angle for wind correction on arcs/loiter // FW energy/altitude bank guard thresholds (conservative; observable via DEBUG_FW_TURN) @@ -429,6 +430,7 @@ void resetFixedWingPositionController(void) // transition, e.g. RTH -> CRUISE) seed from the last applied command so the level-off/turn change // is eased; after a pilot-flown phase seed neutral so a roll-out in progress is not re-commanded. fwRollSmoothSeedCd = ((micros() - fwLastNavRollCmdTimeUs) < MAX_POSITION_UPDATE_INTERVAL_US) ? fwLastNavRollCmdCd : 0.0f; + fwLastNavRollCmdCd = fwRollSmoothSeedCd; // the arc engage and the handback blend from it: a stale bank must not seed them fwRollSmoothReseed = true; pt1FilterSetCutoff(&fwCrossTrackErrorRateFilterState, NAV_FW_CROSSTRACK_RATE_CUTOFF_HZ); @@ -972,13 +974,16 @@ static void fwArcPlanCornerTurn(const fwArcCtx_t *c, bool capped) cy = p1y; } // Turn-in tangency well behind us: the arc law would start far outside the circle and saturate the bank - if (fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y) >= -NAV_FW_ARC_ENTRY_PAST_CM) { + if (fwAlongLegCm(cx, cy, p1x, p1y, d1x, d1y) >= -MIN(NAV_FW_ARC_ENTRY_PAST_CM, NAV_FW_ARC_ENTRY_PAST_R * plan.r)) { fwArcEngageRampIn(&plan, dirTmp, cx, cy, c->legBearing, c->lastNavRollCmdCd); return; } + if (!navConfig()->fw.wp_tracking_accuracy) { + return; // no leg line to capture without tracking: the heading controller flies straight at the waypoint + } } - // Capped, near-reversal or past the turn-in point: no valid tangent circle - fly the bounded capture directly + // Capped, near-reversal or turn-in point well behind: no reachable tangent circle - fly the bounded capture directly fwTurn.arc.engaged = true; fwTurn.arc.bankCmd = c->lastNavRollCmdCd; // blend from the current command: no engage step fwTurn.arc.rampMs = 0.0f; diff --git a/src/test/unit/navigation_fixedwing_turn_math_unittest.cc b/src/test/unit/navigation_fixedwing_turn_math_unittest.cc index 4fd919ff9fe..0dbc05c6ff3 100644 --- a/src/test/unit/navigation_fixedwing_turn_math_unittest.cc +++ b/src/test/unit/navigation_fixedwing_turn_math_unittest.cc @@ -155,6 +155,7 @@ static float ref_offLegCm(float px, float py, float qx, float qy, float legRad) return (px - qx) * (-sin_approx(legRad)) + (py - qy) * cos_approx(legRad); } +// New helper, replaced nothing: same sum as the inline along-track terms in the coordinator static float ref_alongLegCm(float px, float py, float qx, float qy, float legRad) { return (px - qx) * cos_approx(legRad) + (py - qy) * sin_approx(legRad); @@ -429,6 +430,6 @@ TEST(NavFwTurnMathUnittest, CornerEntryTangency) EXPECT_GT(ahead, 0.0f); EXPECT_NEAR(ahead, lead, 20.0f); - // Near-parallel legs take the tangent-at-entry fallback: exactly zero, which must still engage the arc + // Near-parallel fallback (outside the planner's 30..150 deg range): exactly zero, which must still engage EXPECT_GE(cornerEntryAlongCm(px, py, 22500, px - 5000.0f, py + 9000.0f, 22700, r), 0.0f); }