AP_Baro: improved the accuracy of the barometer model

This commit is contained in:
Andrew Tridgell 2013-07-20 14:37:47 +10:00
parent c5028c04da
commit 0c6725f289

View File

@ -33,18 +33,21 @@ uint8_t AP_Baro_HIL::read()
void AP_Baro_HIL::setHIL(float altitude_msl) void AP_Baro_HIL::setHIL(float altitude_msl)
{ {
// approximate a barometer. This uses the typical base pressure in // approximate a barometer
// Canberra, Australia // see http://en.wikipedia.org/wiki/Atmospheric_pressure
const float temperature = 312; const float p0 = 101325;
const float L = 0.0065;
const float T0 = 288.15;
const float M = 0.0289644;
const float R = 8.31447;
float y = (altitude_msl - 584.0) / 29.271267; float p = p0 * pow(1.0 - (L*altitude_msl)/T0, (GRAVITY_MSS*M)/(R*L));
y /= (temperature / 10.0) + 273.15; float T = 31.2 - altitude_msl * L;
y = 1.0/exp(y);
y *= 95446.0;
_count++; _count++;
_pressure_sum += y; _pressure_sum += p;
_temperature_sum += temperature; _temperature_sum += T;
if (_count == 128) { if (_count == 128) {
// we have summed 128 values. This only happens // we have summed 128 values. This only happens
// when we stop reading the barometer for a long time // when we stop reading the barometer for a long time