From 5e90649a6e0bd9408ab98b1ccf2d3ad3abca0ac7 Mon Sep 17 00:00:00 2001 From: Josh Henderson Date: Mon, 16 Aug 2021 03:14:21 -0400 Subject: [PATCH] SITL: fix MS5525 for temp <20C and negative pressures --- libraries/SITL/SIM_MS5525.cpp | 41 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/libraries/SITL/SIM_MS5525.cpp b/libraries/SITL/SIM_MS5525.cpp index b56ceebccb..ab7b7675c3 100644 --- a/libraries/SITL/SIM_MS5525.cpp +++ b/libraries/SITL/SIM_MS5525.cpp @@ -14,11 +14,11 @@ void MS5525::convert_forward(int32_t D1, int32_t D2, float &P_Pa, float &Temp_C) const uint8_t Q6 = Qx_coeff[5]; // this is the forward conversion copied from the driver: - int64_t dT = D2 - int64_t(prom[5]) * (1UL< 1) { - AP_HAL::panic("Invalid conversion"); + if (fabs(f_P_Pa - P_Pa) > 0.1) { + AP_HAL::panic("Invalid pressure conversion"); } - if (fabs(f_Temp_C - Temp_C) > 0.1) { - AP_HAL::panic("Invalid conversion"); + if (fabs(f_Temp_C - Temp_C) > 0.01) { + AP_HAL::panic("Invalid temperature conversion"); } } void MS5525::get_pressure_temperature_readings(float &P_Pa, float &Temp_C) { - Temp_C = 25.0f; + float sim_alt = AP::sitl()->state.altitude; + sim_alt += 2 * rand_float(); + + float sigma, delta, theta; + AP_Baro::SimpleAtmosphere(sim_alt * 0.001f, sigma, delta, theta); + + // To Do: Add a sensor board temperature offset parameter + Temp_C = (SSL_AIR_TEMPERATURE * theta - C_TO_KELVIN) + 25.0; P_Pa = AP::sitl()->state.airspeed_raw_pressure[0]; }