diff --git a/src/main/common/maths.h b/src/main/common/maths.h index d872edc0a0..690ca7c0d9 100644 --- a/src/main/common/maths.h +++ b/src/main/common/maths.h @@ -68,6 +68,12 @@ #define C_TO_KELVIN(temp) (temp + 273.15f) +// Standard Sea Level values +// Ref:https://en.wikipedia.org/wiki/Standard_sea_level +#define SSL_AIR_DENSITY 1.225f // kg/m^3 +#define SSL_AIR_PRESSURE 101325.01576f // Pascal +#define SSL_AIR_TEMPERATURE 288.15f // K + // copied from https://code.google.com/p/cxutil/source/browse/include/cxutil/utility.h#70 #define _CHOOSE2(binoper, lexpr, lvar, rexpr, rvar) \ ( __extension__ ({ \ diff --git a/src/main/drivers/pitotmeter/pitotmeter_adc.c b/src/main/drivers/pitotmeter/pitotmeter_adc.c index da68570ca9..f9c24a4f30 100644 --- a/src/main/drivers/pitotmeter/pitotmeter_adc.c +++ b/src/main/drivers/pitotmeter/pitotmeter_adc.c @@ -59,7 +59,7 @@ static void adcPitotCalculate(pitotDev_t *pitot, float *pressure, float *tempera if (pressure) *pressure = (voltage * PITOT_ADC_VOLTAGE_SCALER - PITOT_ADC_VOLTAGE_ZERO) * PITOT_ADC_VOLTAGE_TO_PRESSURE; if (temperature) - *temperature = 288.15f; // Temperature at standard sea level (288.15 K) + *temperature = SSL_AIR_TEMPERATURE; // Temperature at standard sea level } bool adcPitotDetect(pitotDev_t *pitot) diff --git a/src/main/drivers/pitotmeter/pitotmeter_virtual.c b/src/main/drivers/pitotmeter/pitotmeter_virtual.c index 3f72828517..b8af2df33a 100644 --- a/src/main/drivers/pitotmeter/pitotmeter_virtual.c +++ b/src/main/drivers/pitotmeter/pitotmeter_virtual.c @@ -74,10 +74,9 @@ static void virtualPitotCalculate(pitotDev_t *pitot, float *pressure, float *tem } } if (pressure) - //*pressure = sq(airSpeed / 100) * AIR_DENSITY_SEA_LEVEL_15C / 2 + P0; - *pressure = sq(airSpeed) * AIR_DENSITY_SEA_LEVEL_15C / 20000.0f + P0; + *pressure = sq(airSpeed) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE; if (temperature) - *temperature = 288.15f; // Temperature at standard sea level (288.15 K) + *temperature = SSL_AIR_TEMPERATURE; // Temperature at standard sea level } bool virtualPitotDetect(pitotDev_t *pitot) diff --git a/src/main/sensors/pitotmeter.c b/src/main/sensors/pitotmeter.c index 332f98e02e..c50449c59a 100644 --- a/src/main/sensors/pitotmeter.c +++ b/src/main/sensors/pitotmeter.c @@ -167,7 +167,7 @@ bool pitotIsCalibrationComplete(void) void pitotStartCalibration(void) { - zeroCalibrationStartS(&pitot.zeroCalibration, CALIBRATING_PITOT_TIME_MS, P0 * 0.00001f, false); + zeroCalibrationStartS(&pitot.zeroCalibration, CALIBRATING_PITOT_TIME_MS, SSL_AIR_PRESSURE * 0.00001f, false); } static void performPitotCalibrationCycle(void) @@ -223,7 +223,7 @@ STATIC_PROTOTHREAD(pitotThread) // // Therefore we shouldn't care about CAS/TAS and only calculate IAS since it's more indicative to the pilot and more useful in calculations // It also allows us to use pitot_scale to calibrate the dynamic pressure sensor scale - pitot.airSpeed = pitotmeterConfig()->pitot_scale * fast_fsqrtf(2.0f * fabsf(pitot.pressure - pitot.pressureZero) / AIR_DENSITY_SEA_LEVEL_15C) * 100; + pitot.airSpeed = pitotmeterConfig()->pitot_scale * fast_fsqrtf(2.0f * fabsf(pitot.pressure - pitot.pressureZero) / SSL_AIR_DENSITY) * 100; } else { performPitotCalibrationCycle(); pitot.airSpeed = 0; diff --git a/src/main/sensors/pitotmeter.h b/src/main/sensors/pitotmeter.h index b7fd3c4ca7..fffc5a9f1b 100644 --- a/src/main/sensors/pitotmeter.h +++ b/src/main/sensors/pitotmeter.h @@ -59,9 +59,6 @@ typedef struct pito_s { #ifdef USE_PITOT -#define AIR_DENSITY_SEA_LEVEL_15C 1.225f // Air density at sea level and 15 degrees Celsius -#define P0 101325.0f // standard pressure [Pa] - extern pitot_t pitot; bool pitotInit(void);