Skip to content

Commit

Permalink
Fix sensor airspeed simulator units
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Toledano committed Dec 20, 2024
1 parent a62757d commit d82c688
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d82c688

Please sign in to comment.