]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
Added a README for the src/Cockpit/ directory.
[flightgear.git] / src / Instrumentation / airspeed_indicator.cxx
1 // airspeed_indicator.cxx - a regular VSI.
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 AirspeedIndicator::AirspeedIndicator ()
16 {
17 }
18
19 AirspeedIndicator::~AirspeedIndicator ()
20 {
21 }
22
23 void
24 AirspeedIndicator::init ()
25 {
26     _serviceable_node =
27         fgGetNode("/instrumentation/airspeed-indicator/serviceable",
28                   true);
29     _total_pressure_node =
30         fgGetNode("/systems/pitot/total-pressure-inhg", true);
31     _static_pressure_node =
32         fgGetNode("/systems/static/pressure-inhg", true);
33     _speed_node =
34         fgGetNode("/instrumentation/airspeed-indicator/indicated-speed-kt",
35                   true);
36 }
37
38 #ifndef SEA_LEVEL_DENSITY_SLUGFG3
39 # define SEA_LEVEL_DENSITY_SLUGFT3 0.002378
40 #endif
41
42 #ifndef FPSTOKTS
43 # define FPSTOKTS 0.592484
44 #endif
45
46 #ifndef INHGTOPSF
47 # define INHGTOPSF (2116.217/29.9212)
48 #endif
49
50 void
51 AirspeedIndicator::update (double dt)
52 {
53     if (_serviceable_node->getBoolValue()) {
54         double pt = _total_pressure_node->getDoubleValue();
55         double p = _static_pressure_node->getDoubleValue();
56         double q = ( pt - p ) * INHGTOPSF;      // dynamic pressure
57
58                                 // Now, reverse the equation
59         double v_fps = sqrt((2 * q) / SEA_LEVEL_DENSITY_SLUGFT3);
60
61         _speed_node->setDoubleValue(v_fps * FPSTOKTS);
62     }
63 }
64
65 // end of airspeed_indicator.cxx