Skip to content

Commit

Permalink
AP_Airspeed: check for baro baro data in SDP3X
Browse files Browse the repository at this point in the history
this matters for SDP3X as AP_Periph sensor with no baro
  • Loading branch information
tridge committed Aug 5, 2021
1 parent 3c0238c commit f896439
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libraries/AP_Airspeed/AP_Airspeed_SDP3X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,25 @@ float AP_Airspeed_SDP3X::_correct_pressure(float press)

AP_Baro *baro = AP_Baro::get_singleton();

if (baro == nullptr) {
return press;
float baro_pressure;
if (baro == nullptr || baro->num_instances() == 0) {
// with no baro assume sea level
baro_pressure = SSL_AIR_PRESSURE;
} else {
baro_pressure = baro->get_pressure();
}

float temperature;
if (!get_temperature(temperature)) {
return press;
// assume 25C if no temperature
temperature = 25;
}

float rho_air = baro->get_pressure() / (ISA_GAS_CONSTANT * (temperature + C_TO_KELVIN));
float rho_air = baro_pressure / (ISA_GAS_CONSTANT * (temperature + C_TO_KELVIN));
if (!is_positive(rho_air)) {
// bad pressure
return press;
}

/*
the constants in the code below come from a calibrated test of
Expand Down

0 comments on commit f896439

Please sign in to comment.