Control-code verification

Generated control code can drift from what the designer intended. A comparison pipeline for generated C, numerical references and PX4 failsafe behavior that catches it.

The broad-domain binary32 active variant fails at step 17,868 (about 0.273 s). A separate timestamp-domain example fails at 80,161 updates; neither is a C-translation mismatch. The retained 1.57 million-step short-trace campaign is a different finite result.

Holybro X500 kit with a Pixhawk 4 controller, from the PX4 documentation. Platform reference photograph.
Holybro X500 kit with a Pixhawk 4 controller, from the PX4 documentation. Platform reference photograph.Credit: PX4 documentation contributors. CC BY 4.0. Image reproduced unchanged.Full-size imageImage source

situation

Generated control code can drift from what the designer intended through rounding, compiler behavior or a copied model that is subtly wrong, and a single passing test says little about any of them.

task

Build a comparison pipeline that separates exact intent, floating-point semantics and compiled output, and show which defects each check catches.

action

  • Built a differential harness comparing a Python model of PX4's failsafe logic with the compiled PX4 class on identical sequences.
  • Wrote a numerical specification for a stateful angular-rate filter, then compared exact-rational intent, a binary32 reference and CasADi-generated C.
  • Ran randomized campaigns and minimized the cases that exposed differences.

result

  • A directed binary32 active-variant counterexample exceeds the unchanged continuous ceiling at step 17,868 (about 0.273 s). A separate timestamp-domain case fails at 80,161 updates; C still agrees with its rounded reference.
  • Repaired model and adapter errors behind 495 disagreements in 1,500 development sequences, after which all 1,000 fresh held-out sequences agreed with the compiled firmware.
  • Completed 6,144 randomized traces covering 1,572,864 steps with zero numerical-bound violations.
  • Isolated 8,316 exact-versus-rounded branch-difference steps across 1,016 traces and reported them separately from value accuracy.
  • Caught a binary32 active variant failing its continuous ceiling and identified the rounding mechanism. The binary64 variant then passed directed host comparisons.

key numbers

Randomized development traces6,144
Exact-covered development steps1,572,864
Numerical-bound violations0 in this campaign
Exact / rounded branch differences8,316 steps across 1,016 traces

governing relations

Asymmetric slew-limited rate filter

a = h / (τ + h);  d = a·(u − x);  z = x + clip(d, −s↓·h, s↑·h);  x⁺ = clip(z, −x_max, x_max)

method and specifications

Filter parametersτ = 0.125 s and 0.25 s variants, slew 4 up and 2 down rad/s², state ±2 rad/s, input ±8 rad/s, dt up to 0.0625 s, 256 steps
Three-way comparisonExact rational intent, IEEE binary32 reference, and CasADi-generated C compiled with -std=c99 -O2 -fno-fast-math -ffp-contract=off
PX4 differential resultsDirected 36 of 36 after fixes. Random 1,005 of 1,500 before fixes, 1,500 of 1,500 replayed. Fresh reserved corpus 1,000 of 1,000.

in progress now

  • Working from the binary64 core's isolated PX4 target build toward runtime arithmetic and wrapper checks on the target.

what the numbers cover

The directed 17,868-update example uses a step below the pinned PX4 rate-loop clamp; the 80,161-update timestamp example tests its separately defined domain. Claims belong to these binary32 active variants, not every binary32 design. Randomized value admission was scoped to at most 256 steps since reset. The persistent binary64 arithmetic envelope has its own strict assumptions; target build is not target execution or flight qualification. No LLM translation campaign, PX4 wrapper qualification or flight validation is claimed.

project record

StatusIn Progress
RoleNumerical specification, generated-code qualification and differential checks
EvidenceNumerical qualification and synthetic development campaign
ToolsPython, CasADi, Clang, C, GitHub Actions, MATLAB, LaTeX

← All projects