// return altitude difference in meters between current pressure and a // given base_pressure in Pascal float AP_Baro::get_altitude_difference(float base_pressure, float pressure) const { float ret; float temp = get_ground_temperature() + 273.15f; float scaling = pressure / base_pressure; // This is an exact calculation that is within +-2.5m of the standard // atmosphere tables in the troposphere (up to 11,000 m amsl). ret = 153.8462f * temp * (1.0f - expf(0.190259f * logf(scaling))); return ret; }
// return current scale factor that converts from equivalent to true airspeed // valid for altitudes up to 10km AMSL // assumes standard atmosphere lapse rate float AP_Baro::get_EAS2TAS(void) { float altitude = get_altitude(); if ((fabsf(altitude - _last_altitude_EAS2TAS) < 25.0f) && !is_zero(_EAS2TAS)) { // not enough change to require re-calculating return _EAS2TAS; } // only estimate lapse rate for the difference from the ground location // provides a more consistent reading then trying to estimate a complete // ISA model atmosphere float tempK = get_ground_temperature() + C_TO_KELVIN - ISA_LAPSE_RATE * altitude; _EAS2TAS = safe_sqrt(1.225f / ((float)get_pressure() / (ISA_GAS_CONSTANT * tempK))); _last_altitude_EAS2TAS = altitude; return _EAS2TAS; }
// return altitude difference in meters between current pressure and a // given base_pressure in Pascal float AP_Baro::get_altitude_difference(float base_pressure, float pressure) const { float ret; float temp = get_ground_temperature() + 273.15f; #if HAL_CPU_CLASS <= HAL_CPU_CLASS_16 // on slower CPUs use a less exact, but faster, calculation float scaling = base_pressure / pressure; ret = logf(scaling) * temp * 29.271267f; #else // on faster CPUs use a more exact calculation float scaling = pressure / base_pressure; // This is an exact calculation that is within +-2.5m of the standard atmosphere tables // in the troposphere (up to 11,000 m amsl). ret = 153.8462f * temp * (1.0f - expf(0.190259f * logf(scaling))); #endif return ret; }