From d82c6882ae905d0d8ac2822816b016883e5d196b Mon Sep 17 00:00:00 2001 From: Samuel Toledano Date: Thu, 12 Sep 2024 18:21:49 +0200 Subject: [PATCH] Fix sensor airspeed simulator units --- .../simulation/sensor_airspeed_sim/SensorAirspeedSim.cpp | 4 ++-- .../simulation/sensor_airspeed_sim/SensorAirspeedSim.hpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.cpp b/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.cpp index 7b0d9556cadf..3d83167d388e 100644 --- a/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.cpp +++ b/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.cpp @@ -129,7 +129,7 @@ void SensorAirspeedSim::Run() device_id.devid_s.address = 0; device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_SIM; - const float alt_amsl = gpos.alt; + const float alt_amsl = gpos.alt / 1000.0f; // mm to m const float temperature_local = TEMPERATURE_MSL - LAPSE_RATE * alt_amsl; const float density_ratio = powf(TEMPERATURE_MSL / temperature_local, 4.256f); const float air_density = AIR_DENSITY_MSL / density_ratio; @@ -144,7 +144,7 @@ void SensorAirspeedSim::Run() // report.timestamp_sample = time; differential_pressure.device_id = 1377548; // 1377548: DRV_DIFF_PRESS_DEVTYPE_SIM, BUS: 1, ADDR: 5, TYPE: SIMULATION differential_pressure.differential_pressure_pa = (double)diff_pressure * 100.0; // hPa to Pa; - differential_pressure.temperature = temperature_local; + differential_pressure.temperature = temperature_local + ABSOLUTE_ZERO_C; // K to C differential_pressure.timestamp = hrt_absolute_time(); _differential_pressure_pub.publish(differential_pressure); diff --git a/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.hpp b/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.hpp index 64305dcccada..3aafc9ca938e 100644 --- a/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.hpp +++ b/src/modules/simulation/sensor_airspeed_sim/SensorAirspeedSim.hpp @@ -49,6 +49,7 @@ using namespace time_literals; +static constexpr float ABSOLUTE_ZERO_C = -273.15; // absolute 0 temperature [C] static constexpr float TEMPERATURE_MSL = 288.15; // temperature at MSL [K] (15 [C]) static constexpr float PRESSURE_MSL = 101325.0; // pressure at MSL [Pa] static constexpr float LAPSE_RATE = 0.0065; // reduction in temperature with altitude for troposphere [K/m]