1
0
Fork 0

Fix NaNs in the VSI when pressure reading is invalid

Detect zero/very low pressure reading and avoid generating NaNs in the
main update code. Thanks to Johnathan Redpath for the report.
This commit is contained in:
James Turner 2019-02-06 20:48:18 +00:00
parent dee1998979
commit df7988fb49
2 changed files with 21 additions and 8 deletions

View file

@ -71,8 +71,21 @@ void
VerticalSpeedIndicator::update (double dt)
{
if (_serviceable_node->getBoolValue()) {
double pressure_inHg = _pressure_node->getDoubleValue() ;
double pressure_Pa = pressure_inHg * SG_INHG_TO_PA;
const double pressure_inHg = _pressure_node->getDoubleValue() ;
const double pressure_Pa = pressure_inHg * SG_INHG_TO_PA;
// this occurs if the static pressure source didn't report valid data
// yet. Don't continue processing here since we will generate NaNs
// when dividing by zero
if (_casing_pressure_Pa < 1e-3) {
if (pressure_Pa > 1e3) {
// once the pressure becomes valid, reinit
reinit();
} else {
return; // no more processing
}
}
double Fsign = 0.;
double orifice_mach = 0.0;

View file

@ -45,13 +45,13 @@ public:
private:
double _casing_pressure_Pa;
double _casing_airmass_kg;
double _casing_density_kgpm3;
double _orifice_massflow_kgps;
double _casing_pressure_Pa = 0.0;
double _casing_airmass_kg = 0.0;
double _casing_density_kgpm3 = 0.0;
double _orifice_massflow_kgps = 0.0;
std::string _name;
int _num;
const std::string _name;
const int _num;
std::string _static_pressure;
std::string _static_temperature;