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};