]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
Don't start paused for in air starts.
[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
19 AirspeedIndicator::AirspeedIndicator ()
20 {
21 }
22
23 AirspeedIndicator::~AirspeedIndicator ()
24 {
25 }
26
27 void
28 AirspeedIndicator::init ()
29 {
30     _serviceable_node =
31         fgGetNode("/instrumentation/airspeed-indicator/serviceable",
32                   true);
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);
38     _speed_node =
39         fgGetNode("/instrumentation/airspeed-indicator/indicated-speed-kt",
40                   true);
41 }
42
43 #ifndef FPSTOKTS
44 # define FPSTOKTS 0.592484
45 #endif
46
47 #ifndef INHGTOPSF
48 # define INHGTOPSF (2116.217/29.9212)
49 #endif
50
51 void
52 AirspeedIndicator::update (double dt)
53 {
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
59
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);
64
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,
69                                                  current_speed_kt,
70                                                  dt * RESPONSIVENESS));
71     }
72 }
73
74 // end of airspeed_indicator.cxx