]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
5d5c6c39e801b02479e32e11cdfa933cf0eb54b7
[flightgear.git] / src / Instrumentation / airspeed_indicator.cxx
1 // airspeed_indicator.cxx - a regular pitot-static airspeed indicator.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <math.h>
7
8 #include <simgear/math/interpolater.hxx>
9
10 #include "airspeed_indicator.hxx"
11 #include <Main/fg_props.hxx>
12 #include <Main/util.hxx>
13
14
15 // A higher number means more responsive.
16 #define RESPONSIVENESS 50.0
17
18 AirspeedIndicator::AirspeedIndicator ( SGPropertyNode *node )
19     :
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"))
24 {
25 }
26
27 AirspeedIndicator::~AirspeedIndicator ()
28 {
29 }
30
31 void
32 AirspeedIndicator::init ()
33 {
34     string branch;
35     branch = "/instrumentation/" + name;
36     pitot_port += "/total-pressure-inhg";
37     static_port += "/pressure-inhg";
38
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);
45 }
46
47 #ifndef FPSTOKTS
48 # define FPSTOKTS 0.592484
49 #endif
50
51 #ifndef INHGTOPSF
52 # define INHGTOPSF (2116.217/29.9212)
53 #endif
54
55 void
56 AirspeedIndicator::update (double dt)
57 {
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
63
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);
68
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,
73                                                  current_speed_kt,
74                                                  dt * RESPONSIVENESS));
75     }
76 }
77
78 // end of airspeed_indicator.cxx