From a31a02efecdc6839cea8e975ced470fe7553f54f Mon Sep 17 00:00:00 2001 From: Balduin Date: Wed, 25 Nov 2026 16:33:32 +0100 Subject: [PATCH] fix(gz_bridge): derive groundtruth dt from pose sim time (#30001) Groundtruth velocity, acceleration and angular velocity are finite differences of /world//pose/info poses. dt was taken from PX4 arrival time and capped at 0.1 s. gz throttles pose publishing in wall time (~60 Hz), so at PX4_SIM_SPEED_FACTOR=10 consecutive poses are ~0.167 s apart in sim time, while dt was capped at 0.1 s. Logged groundtruth velocity came out 1.68x d(position)/dt on all axes (exactly 1.00 at speed factor 1). sensor_airspeed_sim consumes it, so simulated airspeed was too high and got rejected by the airspeed validator. Use the Pose_V header stamp (sim time) for dt and timestamp_sample, drop the cap, and skip messages whose stamp does not advance. Assisted-by: Claude Opus 5.5 --- src/modules/simulation/gz_bridge/GZBridge.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/simulation/gz_bridge/GZBridge.cpp b/src/modules/simulation/gz_bridge/GZBridge.cpp index f460b658910..98cdc382702 100644 --- a/src/modules/simulation/gz_bridge/GZBridge.cpp +++ b/src/modules/simulation/gz_bridge/GZBridge.cpp @@ -638,12 +638,17 @@ void GZBridge::imuCallback(const gz::msgs::IMU &msg, uint8_t instance_index) void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &msg) { const uint64_t timestamp = hrt_absolute_time(); + const uint64_t timestamp_sample = msg.header().stamp().sec() * 1000000ULL + msg.header().stamp().nsec() / 1000; + + if (timestamp_sample <= _timestamp_prev) { + return; + } for (int p = 0; p < msg.pose_size(); p++) { if (msg.pose(p).name() == _model_name) { - const double dt = math::constrain((timestamp - _timestamp_prev) * 1e-6, 0.001, 0.1); - _timestamp_prev = timestamp; + const double dt = (timestamp_sample - _timestamp_prev) * 1e-6; + _timestamp_prev = timestamp_sample; gz::msgs::Vector3d pose_position = msg.pose(p).position(); gz::msgs::Quaternion pose_orientation = msg.pose(p).orientation(); @@ -660,7 +665,7 @@ void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &msg) // publish attitude groundtruth vehicle_attitude_s vehicle_attitude_groundtruth{}; - vehicle_attitude_groundtruth.timestamp_sample = timestamp; + vehicle_attitude_groundtruth.timestamp_sample = timestamp_sample; vehicle_attitude_groundtruth.q[0] = q_nb.W(); vehicle_attitude_groundtruth.q[1] = q_nb.X(); vehicle_attitude_groundtruth.q[2] = q_nb.Y(); @@ -671,7 +676,7 @@ void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &msg) // publish angular velocity groundtruth const matrix::Eulerf euler{matrix::Quatf(vehicle_attitude_groundtruth.q)}; vehicle_angular_velocity_s vehicle_angular_velocity_groundtruth{}; - vehicle_angular_velocity_groundtruth.timestamp_sample = timestamp; + vehicle_angular_velocity_groundtruth.timestamp_sample = timestamp_sample; const matrix::Vector3f angular_velocity = (euler - _euler_prev) / dt; _euler_prev = euler; angular_velocity.copyTo(vehicle_angular_velocity_groundtruth.xyz); @@ -680,7 +685,7 @@ void GZBridge::poseInfoCallback(const gz::msgs::Pose_V &msg) _angular_velocity_ground_truth_pub.publish(vehicle_angular_velocity_groundtruth); vehicle_local_position_s local_position_groundtruth{}; - local_position_groundtruth.timestamp_sample = timestamp; + local_position_groundtruth.timestamp_sample = timestamp_sample; // position ENU -> NED const matrix::Vector3d position{pose_position.y(), pose_position.x(), -pose_position.z()}; const matrix::Vector3d velocity{(position - _position_prev) / dt};