From cc1b8e3e39a1632bff3d2c9ea878b4e9e93ceb71 Mon Sep 17 00:00:00 2001 From: John Polstra Date: Thu, 12 Sep 2019 12:52:16 -0700 Subject: [PATCH] Fix an erroneous constant in the calculation of altitude from barometric pressure. The commit which introduced the error was: https://github.com/betaflight/betaflight/commit/35f0a8e4b043a59d99ead4341a7df5c35198dece It transposed (inadvertently, I believe) the last two digits of the constant 0.190259f. A nearby comment references code in Ardupilot, in which the constant is 0.190259f. --- src/main/sensors/barometer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/sensors/barometer.c b/src/main/sensors/barometer.c index 7e5c0d5c63..f0c5abbb81 100644 --- a/src/main/sensors/barometer.c +++ b/src/main/sensors/barometer.c @@ -425,7 +425,7 @@ int32_t baroCalculateAltitude(void) // calculates height from ground via baro readings // see: https://github.com/diydrones/ardupilot/blob/master/libraries/AP_Baro/AP_Baro.cpp#L140 if (isBaroCalibrationComplete()) { - BaroAlt_tmp = lrintf((1.0f - pow_approx((float)(baroPressureSum / PRESSURE_SAMPLE_COUNT) / 101325.0f, 0.190295f)) * 4433000.0f); // in cm + BaroAlt_tmp = lrintf((1.0f - pow_approx((float)(baroPressureSum / PRESSURE_SAMPLE_COUNT) / 101325.0f, 0.190259f)) * 4433000.0f); // in cm BaroAlt_tmp -= baroGroundAltitude; baro.BaroAlt = lrintf((float)baro.BaroAlt * CONVERT_PARAMETER_TO_FLOAT(barometerConfig()->baro_noise_lpf) + (float)BaroAlt_tmp * (1.0f - CONVERT_PARAMETER_TO_FLOAT(barometerConfig()->baro_noise_lpf))); // additional LPF to reduce baro noise } @@ -441,7 +441,7 @@ void performBaroCalibrationCycle(void) baroGroundPressure -= baroGroundPressure / 8; baroGroundPressure += baroPressureSum / PRESSURE_SAMPLE_COUNT; - baroGroundAltitude = (1.0f - pow_approx((baroGroundPressure / 8) / 101325.0f, 0.190295f)) * 4433000.0f; + baroGroundAltitude = (1.0f - pow_approx((baroGroundPressure / 8) / 101325.0f, 0.190259f)) * 4433000.0f; if (baroGroundPressure == savedGroundPressure) calibratingB = 0;