]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
5ae7543324d253e23a919e979154a7106ed845eb
[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     _speed_node =
38         fgGetNode("/instrumentation/airspeed-indicator/indicated-speed-kt",
39                   true);
40 }
41
42 #ifndef SEA_LEVEL_DENSITY_SLUGFG3
43 # define SEA_LEVEL_DENSITY_SLUGFT3 0.002378
44 #endif
45
46 #ifndef FPSTOKTS
47 # define FPSTOKTS 0.592484
48 #endif
49
50 #ifndef INHGTOPSF
51 # define INHGTOPSF (2116.217/29.9212)
52 #endif
53
54 void
55 AirspeedIndicator::update (double dt)
56 {
57     if (_serviceable_node->getBoolValue()) {
58         double pt = _total_pressure_node->getDoubleValue();
59         double p = _static_pressure_node->getDoubleValue();
60         double q = ( pt - p ) * INHGTOPSF;      // dynamic pressure
61
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) / SEA_LEVEL_DENSITY_SLUGFT3);
66
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,
71                                                  current_speed_kt,
72                                                  dt * RESPONSIVENESS));
73     }
74 }
75
76 // end of airspeed_indicator.cxx