From b16eebf1fe708e047d3ff215840817675589c835 Mon Sep 17 00:00:00 2001 From: bresch Date: Tue, 1 Sep 2026 10:17:50 +0200 Subject: [PATCH] fix(ekf2): register a lockstep component in replay mode The replay barrier only waited for the logger, so the next imu sample could be published before ekf2, running on a work queue, had consumed the previous one. Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: bresch --- src/modules/ekf2/EKF2.cpp | 14 ++++++++++++++ src/modules/ekf2/EKF2.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/src/modules/ekf2/EKF2.cpp b/src/modules/ekf2/EKF2.cpp index 29c3e1901af..66a6591cf7e 100644 --- a/src/modules/ekf2/EKF2.cpp +++ b/src/modules/ekf2/EKF2.cpp @@ -226,6 +226,7 @@ EKF2::EKF2(bool multi_mode, const px4::wq_config_t &config, bool replay_mode): EKF2::~EKF2() { + px4_lockstep_unregister_component(_lockstep_component); perf_free(_ekf_update_perf); perf_free(_msg_missed_imu_perf); } @@ -509,6 +510,13 @@ void EKF2::Run() ScheduleDelayed(10_ms); return; } + + if (_replay_mode) { + // let the replay module wait for this instance: it publishes the next imu sample only + // once every registered component reported progress, and without this the estimator + // (running on a work queue) can be handed a new sample before it consumed the last one + _lockstep_component = px4_lockstep_register_component(); + } } if (_vehicle_command_sub.updated()) { @@ -888,6 +896,12 @@ void EKF2::Run() // re-schedule as backup timeout ScheduleDelayed(100_ms); + + if (imu_updated && _replay_mode) { + // releases the replay module to publish the next sample, so nothing of this update may be + // left to do below + px4_lockstep_progress(_lockstep_component); + } } void EKF2::VerifyParams() diff --git a/src/modules/ekf2/EKF2.hpp b/src/modules/ekf2/EKF2.hpp index b63c3c8f786..86fca701df9 100644 --- a/src/modules/ekf2/EKF2.hpp +++ b/src/modules/ekf2/EKF2.hpp @@ -279,6 +279,7 @@ private: static constexpr float sq(float x) { return x * x; }; const bool _replay_mode{false}; ///< true when we use replay data from a log + int _lockstep_component{-1}; ///< replay only: barrier the replay module waits on const bool _multi_mode; int _instance{0};