X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fairspeed_indicator.cxx;h=2b80fbd96c3b9e1c3eef2112e277557beb371f54;hb=863b0c943251fae620406ec8983e5f69e1424731;hp=46eb585c8aab0075e42bc38569cd18ed53c4abee;hpb=0a6d2b75591fa02fb38457b583790fb8c4fa22a2;p=flightgear.git diff --git a/src/Instrumentation/airspeed_indicator.cxx b/src/Instrumentation/airspeed_indicator.cxx index 46eb585c8..2b80fbd96 100644 --- a/src/Instrumentation/airspeed_indicator.cxx +++ b/src/Instrumentation/airspeed_indicator.cxx @@ -34,15 +34,12 @@ AirspeedIndicator::init () fgGetNode("/systems/pitot/total-pressure-inhg", true); _static_pressure_node = fgGetNode("/systems/static/pressure-inhg", true); + _density_node = fgGetNode("/environment/density-slugft3", true); _speed_node = fgGetNode("/instrumentation/airspeed-indicator/indicated-speed-kt", true); } -#ifndef SEA_LEVEL_DENSITY_SLUGFG3 -# define SEA_LEVEL_DENSITY_SLUGFT3 0.002378 -#endif - #ifndef FPSTOKTS # define FPSTOKTS 0.592484 #endif @@ -55,12 +52,15 @@ void AirspeedIndicator::update (double dt) { if (_serviceable_node->getBoolValue()) { - double pt = _total_pressure_node->getDoubleValue(); - double p = _static_pressure_node->getDoubleValue(); - double q = ( pt - p ) * INHGTOPSF; // dynamic pressure - - // Now, reverse the equation - double v_fps = sqrt((2 * q) / SEA_LEVEL_DENSITY_SLUGFT3); + double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF; + double p = _static_pressure_node->getDoubleValue() * INHGTOPSF; + double r = _density_node->getDoubleValue(); + double q = ( pt - p ); // dynamic pressure + + // Now, reverse the equation (normalize dynamic pressure to + // avoid "nan" results from sqrt) + if ( q < 0 ) { q = 0.0; } + double v_fps = sqrt((2 * q) / r); // Publish the indicated airspeed double last_speed_kt = _speed_node->getDoubleValue();