From 8c243a2cd6dc0f62b204c5ee76180b12fccd8d9f Mon Sep 17 00:00:00 2001 From: "A.Burak Tektas" <15087318+Abtektas@users.noreply.github.com> Date: Thu, 1 Oct 2026 20:40:06 +0300 Subject: [PATCH] fix(ekf2): stop the test replay at the end of the sensor data SensorSimulator::setSensorDataFromReplayData() read one element past the end of the replay data after consuming the last sample, and applied it if its timestamp happened to be in the past. With AddressSanitizer on macOS this aborts unit-test_EKF_withReplayData. On Linux the element was fused silently: in the last rows of iris_gps.csv the vertical velocity state ran up to 3.7 m/s. Check the index before reading a sample, and update the change indication files for the rows after the end of the replay data. Fixes #28517 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: A.Burak Tektas <15087318+Abtektas@users.noreply.github.com> --- .../test/change_indication/ekf_gsf_reset.csv | 2 +- .../ekf2/test/change_indication/iris_gps.csv | 8 ++++---- .../test/sensor_simulator/sensor_simulator.cpp | 18 +++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/modules/ekf2/test/change_indication/ekf_gsf_reset.csv b/src/modules/ekf2/test/change_indication/ekf_gsf_reset.csv index 681144b1290..efee96494b1 100644 --- a/src/modules/ekf2/test/change_indication/ekf_gsf_reset.csv +++ b/src/modules/ekf2/test/change_indication/ekf_gsf_reset.csv @@ -388,4 +388,4 @@ Timestamp,state[0],state[1],state[2],state[3],state[4],state[5],state[6],state[7 38590000,-0.66,-0.00063,-0.0024,0.75,0.04,0.17,0.014,0,0,-4.9e+02,-0.0016,-0.0062,0.00054,-0.14,0.17,-0.14,0.22,-0.00061,0.43,0.00036,0.00088,0.0035,0,0,-4.9e+02,1.5e-05,1.5e-05,0.00074,0.019,0.019,0.005,0.043,0.043,0.03,2.6e-07,2.7e-07,9.5e-07,0.0012,0.0011,6.3e-05,3.5e-06,3.2e-05,0.00037,4.2e-06,3.1e-06,0.00037,1,1,0.72 38690000,-0.66,-0.00072,-0.0024,0.75,0.04,0.18,0.021,0,0,-4.9e+02,-0.0016,-0.0062,0.00054,-0.14,0.17,-0.14,0.22,-0.00061,0.43,0.00038,0.0009,0.0035,0,0,-4.9e+02,1.5e-05,1.5e-05,0.00075,0.02,0.02,0.005,0.048,0.048,0.03,2.7e-07,2.7e-07,9.5e-07,0.0012,0.0011,6.3e-05,3.4e-06,3.2e-05,0.00037,4.2e-06,3e-06,0.00037,1,1,0.75 38790000,-0.66,-0.00059,-0.0023,0.75,0.03,0.17,0.027,0,0,-4.9e+02,-0.0016,-0.0062,0.00053,-0.14,0.17,-0.14,0.22,-0.0005,0.43,0.00039,0.00088,0.0035,0,0,-4.9e+02,1.5e-05,1.5e-05,0.00074,0.018,0.018,0.0049,0.043,0.043,0.03,2.7e-07,2.7e-07,9.5e-07,0.0011,0.0011,6.3e-05,3.3e-06,3.2e-05,0.00037,4.2e-06,2.9e-06,0.00037,1,1,0.77 -38890000,-0.66,-0.00077,-0.0024,0.75,0.02,0.17,0.53,0,0,-4.9e+02,-0.0016,-0.0062,0.00053,-0.14,0.17,-0.14,0.22,-0.0005,0.43,0.0004,0.00085,0.0035,0,0,-4.9e+02,1.5e-05,1.5e-05,0.00075,0.019,0.019,0.005,0.047,0.047,0.03,2.7e-07,2.7e-07,9.5e-07,0.0011,0.0011,6.3e-05,3.3e-06,3.2e-05,0.00037,4.2e-06,2.9e-06,0.00037,1,1,0.8 +38890000,-0.66,-0.00069,-0.0023,0.75,0.028,0.18,0.036,0,0,-4.9e+02,-0.0016,-0.0062,0.00053,-0.14,0.17,-0.14,0.22,-0.0005,0.43,0.0004,0.00085,0.0035,0,0,-4.9e+02,1.5e-05,1.5e-05,0.00075,0.019,0.019,0.005,0.047,0.047,0.03,2.7e-07,2.7e-07,9.5e-07,0.0011,0.0011,6.3e-05,3.3e-06,3.2e-05,0.00037,4.2e-06,2.9e-06,0.00037,1,1,0.8 diff --git a/src/modules/ekf2/test/change_indication/iris_gps.csv b/src/modules/ekf2/test/change_indication/iris_gps.csv index 6d20488f77e..73291d0a4f4 100644 --- a/src/modules/ekf2/test/change_indication/iris_gps.csv +++ b/src/modules/ekf2/test/change_indication/iris_gps.csv @@ -345,7 +345,7 @@ Timestamp,state[0],state[1],state[2],state[3],state[4],state[5],state[6],state[7 34290000,0.99,-0.0096,-0.014,0.17,-0.018,-0.096,-0.064,0,0,-4.9e+02,-0.0014,-0.0057,9.5e-05,0.041,-0.03,-0.14,0.2,-7.1e-06,0.43,-0.002,-0.0026,0.0013,0,0,-4.9e+02,0.00027,0.00026,0.033,0.012,0.013,0.0049,0.038,0.04,0.029,2.4e-07,2.2e-07,9.9e-07,0.024,0.023,7.9e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.26 34390000,0.99,-0.0095,-0.014,0.17,-0.02,-0.09,-0.059,0,0,-4.9e+02,-0.0014,-0.0057,8.4e-05,0.043,-0.03,-0.14,0.2,-4.7e-06,0.43,-0.0019,-0.0025,0.0013,0,0,-4.9e+02,0.00027,0.00026,0.033,0.011,0.012,0.0049,0.035,0.036,0.029,2.3e-07,2.2e-07,9.7e-07,0.024,0.023,7.9e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.28 34490000,0.99,-0.0096,-0.014,0.17,-0.023,-0.093,-0.057,0,0,-4.9e+02,-0.0014,-0.0057,9.5e-05,0.043,-0.03,-0.14,0.2,-4.6e-06,0.43,-0.002,-0.0025,0.0013,0,0,-4.9e+02,0.00027,0.00026,0.033,0.012,0.013,0.0049,0.038,0.04,0.029,2.3e-07,2.2e-07,9.7e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.31 -34590000,0.98,-0.0094,-0.014,0.17,-0.025,-0.085,0.74,0,0,-4.9e+02,-0.0014,-0.0056,8.5e-05,0.044,-0.029,-0.14,0.2,-1.3e-06,0.43,-0.002,-0.0024,0.0013,0,0,-4.9e+02,0.00026,0.00026,0.033,0.011,0.012,0.0048,0.035,0.036,0.029,2.3e-07,2.2e-07,9.6e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.33 -34690000,0.99,-0.0094,-0.013,0.17,-0.031,-0.083,1.7,0,0,-4.9e+02,-0.0014,-0.0056,8.9e-05,0.044,-0.029,-0.14,0.2,-8.9e-07,0.43,-0.002,-0.0025,0.0013,0,0,-4.9e+02,0.00026,0.00026,0.033,0.011,0.012,0.0049,0.038,0.04,0.029,2.3e-07,2.2e-07,9.5e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.36 -34790000,0.98,-0.0093,-0.013,0.17,-0.034,-0.074,2.7,0,0,-4.9e+02,-0.0014,-0.0056,7.9e-05,0.047,-0.03,-0.14,0.2,2.5e-06,0.43,-0.002,-0.0024,0.0014,0,0,-4.9e+02,0.00026,0.00025,0.033,0.011,0.011,0.0049,0.035,0.036,0.029,2.3e-07,2.2e-07,9.4e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.38 -34890000,0.99,-0.0092,-0.013,0.17,-0.04,-0.073,3.7,0,0,-4.9e+02,-0.0014,-0.0056,8.3e-05,0.047,-0.03,-0.14,0.2,2.6e-06,0.43,-0.0021,-0.0024,0.0014,0,0,-4.9e+02,0.00026,0.00026,0.033,0.012,0.013,0.0049,0.038,0.039,0.029,2.3e-07,2.2e-07,9.3e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.41 +34590000,0.99,-0.0097,-0.013,0.17,-0.02,-0.087,-0.051,0,0,-4.9e+02,-0.0014,-0.0056,8.5e-05,0.044,-0.029,-0.14,0.2,-1.3e-06,0.43,-0.002,-0.0024,0.0013,0,0,-4.9e+02,0.00026,0.00026,0.033,0.011,0.012,0.0048,0.035,0.036,0.029,2.3e-07,2.2e-07,9.6e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.33 +34690000,0.99,-0.01,-0.013,0.17,-0.02,-0.088,-0.046,0,0,-4.9e+02,-0.0014,-0.0056,9.1e-05,0.044,-0.029,-0.14,0.2,-9.9e-07,0.43,-0.002,-0.0024,0.0013,0,0,-4.9e+02,0.00026,0.00026,0.033,0.012,0.013,0.0049,0.038,0.04,0.029,2.3e-07,2.2e-07,9.5e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.36 +34790000,0.99,-0.01,-0.013,0.17,-0.018,-0.082,-0.04,0,0,-4.9e+02,-0.0014,-0.0056,8.4e-05,0.046,-0.029,-0.14,0.2,1.7e-06,0.43,-0.002,-0.0024,0.0014,0,0,-4.9e+02,0.00026,0.00025,0.033,0.011,0.012,0.0049,0.035,0.036,0.029,2.3e-07,2.2e-07,9.4e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.38 +34890000,0.99,-0.011,-0.013,0.17,-0.018,-0.085,-0.034,0,0,-4.9e+02,-0.0014,-0.0056,9.3e-05,0.046,-0.029,-0.14,0.2,1.6e-06,0.43,-0.002,-0.0024,0.0014,0,0,-4.9e+02,0.00026,0.00025,0.033,0.012,0.013,0.0049,0.038,0.04,0.029,2.3e-07,2.2e-07,9.3e-07,0.024,0.023,7.8e-05,0.0012,4e-05,0.0012,0.0012,0.0013,0.0012,1,1,0.41 diff --git a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp index 1e5f4998672..b792d5f0b2d 100644 --- a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp +++ b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp @@ -226,19 +226,11 @@ void SensorSimulator::runReplayMicroseconds(uint32_t duration) void SensorSimulator::setSensorDataFromReplayData() { if (_replay_data.size() > 0) { - sensor_info sample = _replay_data[_current_replay_data_index]; - - while (sample.timestamp < _time) { - setSingleReplaySample(sample); - - if (_current_replay_data_index < _replay_data.size()) { - _current_replay_data_index ++; - - } else { - break; - } - - sample = _replay_data[_current_replay_data_index]; + // stop at the end of the replay data instead of reading past it + while (_current_replay_data_index < _replay_data.size() + && _replay_data[_current_replay_data_index].timestamp < _time) { + setSingleReplaySample(_replay_data[_current_replay_data_index]); + _current_replay_data_index++; } } else {