]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
480d6dab33894c72349aa1bd9f531e248c20093e
[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 void
39 AirspeedIndicator::bind ()
40 {
41 }
42
43 void
44 AirspeedIndicator::unbind ()
45 {
46 }
47
48
49 #ifndef SEA_LEVEL_DENSITY_SLUGFG3
50 # define SEA_LEVEL_DENSITY_SLUGFT3 0.002378
51 #endif
52
53 #ifndef FPSTOKTS
54 # define FPSTOKTS 0.592484
55 #endif
56
57 #ifndef INHGTOPSF
58 # define INHGTOPSF (2116.217/29.9212)
59 #endif
60
61 void
62 AirspeedIndicator::update (double dt)
63 {
64     if (_serviceable_node->getBoolValue()) {
65         double pt = _total_pressure_node->getDoubleValue();
66         double p = _static_pressure_node->getDoubleValue();
67         double q = ( pt - p ) * INHGTOPSF;      // dynamic pressure
68
69                                 // Now, reverse the equation
70         double v_fps = sqrt((2 * q) / SEA_LEVEL_DENSITY_SLUGFT3);
71
72         _speed_node->setDoubleValue(v_fps * FPSTOKTS);
73     }
74 }
75
76 // end of airspeed_indicator.cxx