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 <mahima@auterion.com>

* 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 <mahima@auterion.com>

---------

Signed-off-by: mahima-yoga <mahima@auterion.com>
This commit is contained in:
Mahima Yoga
2026-07-22 15:22:52 +02:00
committed by GitHub
parent a6e6ebfe95
commit 01193bf86b
2 changed files with 16 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
<plugin entity_name="*" entity_type="world" filename="gz-sim-air-pressure-system" name="gz::sim::systems::AirPressure"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-air-speed-system" name="gz::sim::systems::AirSpeed"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-apply-link-wrench-system" name="gz::sim::systems::ApplyLinkWrench"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-wind-effects-system" name="gz::sim::systems::WindEffects"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-navsat-system" name="gz::sim::systems::NavSat"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-magnetometer-system" name="gz::sim::systems::Magnetometer"/>
<plugin entity_name="*" entity_type="world" filename="gz-sim-sensors-system" name="gz::sim::systems::Sensors">

View File

@@ -35,6 +35,8 @@
#include <gz/plugin/Register.hh>
#include <gz/msgs/air_speed.pb.h>
#include <gz/sim/components/LinearVelocity.hh>
#include <gz/sim/components/Wind.hh>
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<gz::sim::components::WorldLinearVelocity>(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);