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("airspeed-indicator"),
22 pitot_port("/systems/pitot"),
23 static_port("/systems/static")
26 for ( i = 0; i < node->nChildren(); ++i ) {
27 SGPropertyNode *child = node->getChild(i);
28 string cname = child->getName();
29 string cval = child->getStringValue();
30 if ( cname == "name" ) {
32 } else if ( cname == "number" ) {
33 num = child->getIntValue();
34 } else if ( cname == "pitot-port" ) {
36 } else if ( cname == "static-port" ) {
39 SG_LOG( SG_INSTR, SG_WARN, "Error in aispeed-indicator config logic" );
40 if ( name.length() ) {
41 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
48 AirspeedIndicator::AirspeedIndicator ( int i )
50 name("airspeed-indicator"),
52 pitot_port("/systems/pitot"),
53 static_port("/systems/static")
58 AirspeedIndicator::~AirspeedIndicator ()
63 AirspeedIndicator::init ()
66 branch = "/instrumentation/" + name;
67 pitot_port += "/total-pressure-inhg";
68 static_port += "/pressure-inhg";
70 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
71 _serviceable_node = node->getChild("serviceable", 0, true);
72 _total_pressure_node = fgGetNode(pitot_port.c_str(), true);
73 _static_pressure_node = fgGetNode(static_port.c_str(), true);
74 _density_node = fgGetNode("/environment/density-slugft3", true);
75 _speed_node = node->getChild("indicated-speed-kt", 0, true);
79 # define FPSTOKTS 0.592484
83 # define INHGTOPSF (2116.217/29.9212)
87 AirspeedIndicator::update (double dt)
89 if (_serviceable_node->getBoolValue()) {
90 double pt = _total_pressure_node->getDoubleValue() * INHGTOPSF;
91 double p = _static_pressure_node->getDoubleValue() * INHGTOPSF;
92 double r = _density_node->getDoubleValue();
93 double q = ( pt - p ); // dynamic pressure
95 // Now, reverse the equation (normalize dynamic pressure to
96 // avoid "nan" results from sqrt)
97 if ( q < 0 ) { q = 0.0; }
98 double v_fps = sqrt((2 * q) / r);
100 // Publish the indicated airspeed
101 double last_speed_kt = _speed_node->getDoubleValue();
102 double current_speed_kt = v_fps * FPSTOKTS;
103 _speed_node->setDoubleValue(fgGetLowPass(last_speed_kt,
105 dt * RESPONSIVENESS));
109 // end of airspeed_indicator.cxx