mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-26 01:00:36 +08:00
fix(gz_bridge): derive groundtruth dt from pose sim time (#30001)
Groundtruth velocity, acceleration and angular velocity are finite differences of /world/<name>/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 <noreply@anthropic.com>
This commit is contained in:
1 parent
07154a8eca
commit
a31a02efec
1 file changed
+10
-5
@@ -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};
|
||||
|
||||
Reference in new issue
Block a user