From 24aafe12b73a9fd236ca2bacbd5c1779489eaf70 Mon Sep 17 00:00:00 2001 From: bresch Date: Mon, 16 Nov 2026 17:41:14 +0100 Subject: [PATCH] test(ekf2): make the simulated GNSS position follow the trajectory The trajectory only set the GNSS velocity, so the position stayed fixed and contradicted it as soon as both were fused. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: bresch --- .../ekf2/test/sensor_simulator/sensor_simulator.cpp | 13 ++++++++++--- .../ekf2/test/sensor_simulator/sensor_simulator.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp index 1e5f4998672..39877fd93c8 100644 --- a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp +++ b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.cpp @@ -358,6 +358,11 @@ void SensorSimulator::setSensorDataFromTrajectory() const Vector3f vel_world{_trajectory[0].getCurrentVelocity(), _trajectory[1].getCurrentVelocity(), _trajectory[2].getCurrentVelocity()}; + const Vector3f pos_world{_trajectory[0].getCurrentPosition(), + _trajectory[1].getCurrentPosition(), + _trajectory[2].getCurrentPosition()}; + const Vector3f delta_pos_world = pos_world - _trajectory_position_prev; + _trajectory_position_prev = pos_world; // IMU const Vector3f earth_gravity = {0.0f, 0.0f, -CONSTANTS_ONE_G}; @@ -397,9 +402,11 @@ void SensorSimulator::setSensorDataFromTrajectory() } if (_gps.isRunning()) { - /* _gps.setAltitude(); */ - /* _gps.setLatitude(); */ - /* _gps.setLongitude(); */ + LatLonAlt gps_position(_gps.getData().lat, _gps.getData().lon, _gps.getData().alt); + gps_position += delta_pos_world; + _gps.setLatitude(gps_position.latitude_deg()); + _gps.setLongitude(gps_position.longitude_deg()); + _gps.setAltitude(gps_position.altitude()); _gps.setVelocity(vel_world); } } diff --git a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.h b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.h index d77a88255ed..6c2fe76201b 100644 --- a/src/modules/ekf2/test/sensor_simulator/sensor_simulator.h +++ b/src/modules/ekf2/test/sensor_simulator/sensor_simulator.h @@ -134,6 +134,7 @@ public: Vio _vio; VelocitySmoothing _trajectory[3]; + Vector3f _trajectory_position_prev{}; private: void setSensorDataToDefault();