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 pitot_port(node->getStringValue("pitot-port", "/systems/pitot")),
23 static_port(node->getStringValue("static-port", "/systems/static"))
27 AirspeedIndicator::~AirspeedIndicator ()
32 AirspeedIndicator::init ()
35 branch = "/instrumentation/" + name;
36 pitot_port += "/total-pressure-inhg";
37 static_port += "/pressure-inhg";
39 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
40 _serviceable_node = node->getChild("serviceable", 0, true);
41 _total_pressure_node = fgGetNode(pitot_port.c_str(), true);
42 _static_pressure_node = fgGetNode(static_port.c_str(), true);
43 _density_node = fgGetNode("/environment/density-slugft3", true);
44 _speed_node = node->getChild("indicated-speed-kt", 0, true);
48 # define FPSTOKTS 0.592484
52 # define INHGTOPSF (2116.217/29.9212)
56 AirspeedIndicator::update (double dt)
58 if (_serviceable_node->getBoolValue()) {
59 double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
60 double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
61 double r = _density_node->getDoubleValue();
62 double q = ( pt - p ); // dynamic pressure
64 // Now, reverse the equation (normalize dynamic pressure to
65 // avoid "nan" results from sqrt)
66 if ( q < 0 ) { q = 0.0; }
67 double v_fps = sqrt((2 * q) / r);
69 // Publish the indicated airspeed
70 double last_speed_kt = _speed_node->getDoubleValue();
71 double current_speed_kt = v_fps * FPSTOKTS;
72 _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
74 dt * RESPONSIVENESS));
78 // end of airspeed_indicator.cxx