From 01193bf86bba92e003039372d01ee80c30dfd0bf Mon Sep 17 00:00:00 2001 From: Mahima Yoga Date: Wed, 22 Jul 2026 15:22:52 +0200 Subject: [PATCH] fix(simulation): make wind affect the airspeed sensor in gz (#28042) * feat(simulation): load gz WindEffects system globally Nothing published the world wind (wind_info topic / wind entity velocity) so far, leaving the airspeed sensor and drag systems without wind data in worlds that define one. No effect in worlds without a wind definition. Signed-off-by: mahima-yoga * fix(simulation): read wind from the ECM in the gz airspeed plugin The wind_info topic is only published when the wind changes, so a model that spawns after the world has loaded misses it and simulates a wind-blind pitot: so the EKF never estimates the wind. Read the wind entity velocity from the EntityComponentManager each step instead. Signed-off-by: mahima-yoga --------- Signed-off-by: mahima-yoga --- src/modules/simulation/gz_bridge/server.config | 1 + .../simulation/gz_plugins/airspeed/AirSpeed.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/modules/simulation/gz_bridge/server.config b/src/modules/simulation/gz_bridge/server.config index 0001356a3a8..b1f88198f63 100644 --- a/src/modules/simulation/gz_bridge/server.config +++ b/src/modules/simulation/gz_bridge/server.config @@ -8,6 +8,7 @@ + diff --git a/src/modules/simulation/gz_plugins/airspeed/AirSpeed.cpp b/src/modules/simulation/gz_plugins/airspeed/AirSpeed.cpp index 8d0c74dab70..103533de1ac 100644 --- a/src/modules/simulation/gz_plugins/airspeed/AirSpeed.cpp +++ b/src/modules/simulation/gz_plugins/airspeed/AirSpeed.cpp @@ -35,6 +35,8 @@ #include #include +#include +#include using namespace px4; @@ -120,6 +122,19 @@ void AirSpeed::PreUpdate(const gz::sim::UpdateInfo &_info, // Calculate differential pressure + noise in hPa const float diff_pressure_noise = standard_normal_distribution_(random_generator_) * diff_pressure_stddev_; + + // Read the wind from the ECM: the wind_info topic is only published on wind changes, + // which the subscription misses when the model spawns after the world was loaded + const gz::sim::Entity wind_entity = _ecm.EntityByComponents(gz::sim::components::Wind()); + + if (wind_entity != gz::sim::kNullEntity) { + const auto wind_linear_velocity = _ecm.Component(wind_entity); + + if (wind_linear_velocity) { + _wind_velocity = wind_linear_velocity->Data(); + } + } + // Body-relateive air velocity gz::math::Vector3d air_relative_velocity = _vehicle_velocity - _wind_velocity; gz::math::Vector3d body_velocity = _vehicle_attitude.RotateVectorReverse(air_relative_velocity);