From 37cdedeed283f97fccb025ad39397f19f6fcab22 Mon Sep 17 00:00:00 2001 From: Balduin Date: Thu, 19 Nov 2026 09:57:18 +0100 Subject: [PATCH] test(tecs): count closed-loop simulation steps as an integer Accumulating the simulation time in float drifts (the second altitude step of a test landed at 40.0007 s) and the float loop condition could run one step more than the requested duration. Count steps instead and derive the time from the step count. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Balduin --- src/lib/tecs/TECSClosedLoopTest.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/tecs/TECSClosedLoopTest.cpp b/src/lib/tecs/TECSClosedLoopTest.cpp index de1f9f8ecad..fdefe5e07be 100644 --- a/src/lib/tecs/TECSClosedLoopTest.cpp +++ b/src/lib/tecs/TECSClosedLoopTest.cpp @@ -165,7 +165,8 @@ AircraftState aircraft_step(const TECSControl::Param &p, float dt, float throttl class TECSClosedLoopTest : public ::testing::Test { protected: - float _t{0.f}; // Simulation time [s] + int _step{0}; // Simulation step count + float _t{0.f}; // Simulation time [s], _step * DT TECSControl::Param _params{defaultParams()}; // first: the plant and the setpoints derive from it AircraftState _state{_params.equivalent_airspeed_trim, ALT_INIT}; @@ -277,8 +278,6 @@ protected: // $TECS_TEST_LOG_DIR/.csv with one row per timestep. void run(float duration) { - float t_start = _t; - if (!_tecs_initialised) { initTecs(); } @@ -301,7 +300,9 @@ protected: } } - while (_t < t_start + duration) { + const int step_end = _step + static_cast(roundf(duration / DT)); + + while (_step < step_end) { _tecs.update(DT, makeSetpoint(), makeInput(), _params, _flag); @@ -322,7 +323,8 @@ protected: (double) dbg.energy_balance_rate_sp, (double) dbg.energy_balance_rate_estimate); } - _t += DT; + _step++; + _t = _step * DT; } } };