1 // airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
8 #include <simgear/math/interpolater.hxx>
10 #include "airspeed_indicator.hxx"
11 #include <Main/fg_props.hxx>
12 #include <Main/util.hxx>
15 // A higher number means more responsive.
16 #define RESPONSIVENESS 50.0
19 AirspeedIndicator::AirspeedIndicator ()
23 AirspeedIndicator::~AirspeedIndicator ()
28 AirspeedIndicator::init ()
31 fgGetNode("/instrumentation/airspeed-indicator/serviceable",
33 _total_pressure_node =
34 fgGetNode("/systems/pitot/total-pressure-inhg", true);
35 _static_pressure_node =
36 fgGetNode("/systems/static/pressure-inhg", true);
37 _density_node = fgGetNode("/environment/density-slugft3", true);
39 fgGetNode("/instrumentation/airspeed-indicator/indicated-speed-kt",
44 # define FPSTOKTS 0.592484
48 # define INHGTOPSF (2116.217/29.9212)
52 AirspeedIndicator::update (double dt)
54 if (_serviceable_node->getBoolValue()) {
55 double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
56 double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
57 double r = _density_node->getDoubleValue();
58 double q = ( pt - p ); // dynamic pressure
60 // Now, reverse the equation (normalize dynamic pressure to
61 // avoid "nan" results from sqrt)
62 if ( q < 0 ) { q = 0.0; }
63 double v_fps = sqrt((2 * q) / r);
65 // Publish the indicated airspeed
66 double last_speed_kt = _speed_node->getDoubleValue();
67 double current_speed_kt = v_fps * FPSTOKTS;
68 _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
70 dt * RESPONSIVENESS));
74 // end of airspeed_indicator.cxx