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
18 AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node )
20 _name(node->getStringValue("name", "airspeed-indicator")),
21 _num(node->getIntValue("number", 0)),
22 _total_pressure(node->getStringValue("total-pressure", "/systems/pitot/total-pressure-inhg")),
23 _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg"))
27 AirspeedIndicator::~AirspeedIndicator ()
32 AirspeedIndicator::init ()
35 branch = "/instrumentation/" + _name;
37 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
38 _serviceable_node = node->getChild("serviceable", 0, true);
39 _total_pressure_node = fgGetNode(_total_pressure.c_str(), true);
40 _static_pressure_node = fgGetNode(_static_pressure.c_str(), true);
41 _density_node = fgGetNode("/environment/density-slugft3", true);
42 _speed_node = node->getChild("indicated-speed-kt", 0, true);
46 # define FPSTOKTS 0.592484
50 # define INHGTOPSF (2116.217/29.9212)
54 AirspeedIndicator::update (double dt)
56 if (_serviceable_node->getBoolValue()) {
57 double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
58 double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
59 double r = _density_node->getDoubleValue();
60 double q = ( pt - p ); // dynamic pressure
62 // Now, reverse the equation (normalize dynamic pressure to
63 // avoid "nan" results from sqrt)
64 if ( q < 0 ) { q = 0.0; }
65 double v_fps = sqrt((2 * q) / r);
67 // Publish the indicated airspeed
68 double last_speed_kt = _speed_node->getDoubleValue();
69 double current_speed_kt = v_fps * FPSTOKTS;
70 _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
72 dt * RESPONSIVENESS));
76 // end of airspeed_indicator.cxx