Conversation
Move the bank-from-radius, bearing/unit-vector, circle-centre, line intersection, smoothstep and slew expressions that the turn coordinator repeated at up to ten sites into one extern TU, and reuse the planning radius in the loiter stabiliser instead of duplicating its formula. Expressions, operand order and lrintf placement are unchanged; a unit test compares every helper bit-exactly against the replaced inline code. MATEKF722 -384 B flash, MATEKH743 -896 B, RAM unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…blocks dtMs, the heading error to the leg and the bank slew step were computed up to three times per tick; the landing-approach turn-mode rule, the bank clamp and the debug release were spelled out at two or three places each. The arc's debug channels are written under one mode test. Values and write order are unchanged. MATEKF722 -192 B flash. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The five ramp-in engages, three capture fallbacks and two S stagings each spelled out the same state assignments, the turn plan triple (radius, bank, ease time) was computed at three places, and the steady arc law existed once for the WP arc and once for the loiter circle. Each is now one function; the arc statics move to file scope so the helpers can write them. Values, evaluation order and read points are unchanged. MATEKF722 -256 B flash. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Thirty-odd file-scope and function-local statics of the arc coordinator, S sequencer, hand-back fade, turn feed-forward, loiter stabiliser and energy guard become fwTurnState_t (148 B) and fwBankGuardState_t (64 B), so the feature's RAM is one sizeof each, and the controller reset's predictor half is one function with exactly the previous reset set. Renames only; a reverse-applied rename map diffs clean against the previous revision. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…steps updateFwTurnArc nested up to eight levels over 350 lines. Its branches are now named functions - one per turn-mode planner, the two S-sequencer halves, leg-change retarget, leg-line capture, roll-out lead and the three phase steps - fed by one per-tick context. Bodies are extracted verbatim (per-block normalised diff is byte-identical); the only control flow edits are inverted early returns on integer guards. MATEKF722 and MATEKH743 flash unchanged, MATEKF405 +448 B from -O2 inlining layout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #11996 249 targets built. Find your board's
|
|
@sensei-hacker something seems to be off with the flash/ram check. The numbers don't match at all compared to my local builds. And apparently also not to your local builds since your 8k match exactly the baseline. and compared to baseline my results are the ones in this post for the refactor. But the flash check shows entirely different. |
|
We can compare and contrast #11998 |
|
Need to do some fixes first. It was not a perfect refactor and on the way I found a race condition causing WP not to hit. Caused by an old bug from remaining and reused turn smoothing code. When all is finished and validated I will compare again. |
wpTurnSmoothingActive was cleared at the start of every position tick and re-asserted by FLY_BY while inside the lead distance, but FLY_INTO sets it exactly once at the S pickup. The consumer runs from the nav FSM at RX cadence, so the one-tick window was missed at random and the aircraft flew a full circle back to a waypoint it had already passed (151 deg corner, where no geometric check can fire). The flag now stays set until isWaypointReached consumes it; it is cleared on waypoint activation (as before) and on any nav state change, so a verdict cannot leak into RTH or landing states. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Multi-line blocks that narrated the code or its history are cut to one or two lines stating the constraint or measured fact behind it; comments that restated the statement below them are removed. Comments only, the binary is byte-identical. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoOptimize fixed-wing turn coordinator and fix waypoint event race
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
|
Validated in HITL so far. not more than 0.5m course deviation (no wind) in deterministic comparison of different turn modes with tracking on and off. behavior unchanged, debug shows no deviation in trigger and process values except that found bug that was uncovered and fixed in f85f5ff |
Code Review by Qodo
1.
|
The extracted helper rejected with `fabsf(cross) <= min`, which lets a NaN cross product through and would engage an arc on NaN coordinates; the original sites tested `> min` and fell back. Restored as the positive test, with a NaN case in the unit test. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Follow-up to #11812 after the flash/RAM feedback. Five behaviour-identical refactoring commits on the turn coordinator, one measurable step each. HITL before/after replay done (same mission, MATEKF765,
debug_mode FW_TURN): per corner the arc phase sequence and its durations, engage distance, radius, exit course and ease time are identical between the pre-branch build and this head (see "HITL comparison" below). The last commit is a small behaviour fix found during that replay, kept separate.Measured cost of #11812 (MATEKF722, -Os, LTO, commit before the merge vs the merge)
+8044 B flash, +248 B RAM.
updateFwTurnArcalone was 4832 B (isolated with NOINLINE).What this PR does
navigation_fixedwing_turn_math.c(bank-from-radius, bearing/unit vector, circle centre, line intersection, smoothstep, slew) + a unit test thatmemcmps each helper against the verbatim original expressionfwTurnState_t(148 B) +fwBankGuardState_t(64 B), zero-initialised, one reset function with exactly the previous reset set (perdocs/development/ram-and-flash-optimization.md)updateFwTurnArcsplit into per-mode planners, the two S-sequencer halves, leg-change retarget, leg-line capture, roll-out lead and the three phase steps, fed by one per-tick context: 351 lines / brace depth 8 → 90 lines / depth 3Totals at the head: MATEKF722 −780 B flash / −8 B RAM, MATEKF405 −12 B / −24 B, MATEKH743 −1100 B / 0.
Evidence that behaviour is unchanged
FAST_MATHtrig.make check573/573 after every step; zero warnings on MATEKF722, MATEKF405, MATEKH743 and SITL.-ffp-contract=fast, so FMA fuse decisions after moved inlining boundaries cannot be proven on the host. The HITL replay covers this.Notes
memsetthe arc block:arc.bankCmdandarc.easeMsare read after a controller reset by a still-established loiter circle. S stage, loiter ratchet and the guard's filters were never part of the reset and still are not.Honest bottom line
The state-scope and nesting points are addressed. The bit-exact refactor recovers about 10 % of the flash: at -Os + LTO GCC was already folding most of the duplication, and the remaining ~7 KB is the geometry itself (trig calls of four turn modes). Going further means a per-target build flag that drops modes, or behaviour changes, which I would rather discuss than decide here.
HITL comparison (LOG00051 pre-branch vs LOG00052 this head, COORD_FLYINTO + tracking 5 m)
Max bank command, actual roll and the mean command-vs-attitude error match to within 0.5° per corner. Residual differences are the flight's own noise (separate HITL runs).
Bug found during the replay (last commit,
f85f5ff4a)The FLY_INTO pickup marks the WP reached by setting
wpTurnSmoothingActiveonce, butcalculateVirtualPositionTarget_FWcleared that flag at the start of every position tick and the consumer (isWaypointReached, run from the nav FSM at RX cadence) missed the one-tick window at random. At corners where no geometric reached-check can fire (151° at WP6 in this mission) the aircraft then flew a full circle back to the passed waypoint. Seen in both builds, on different waypoints, so it is a race and not a refactor effect. The flag is now an event: set once, cleared only when consumed, on waypoint activation, and on any nav state change so it cannot leak into RTH or landing. FLY_BY is unaffected (it re-asserted the flag every tick anyway). This commit is the only behaviour change in the PR.🤖 Generated with Claude Code