]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/airspeed_indicator.cxx
27f2f0f175298e1aefd2d9b9cbc0dc6650527763
[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 void
58 AirspeedIndicator::update (double dt)
59 {
60     if (_serviceable_node->getBoolValue()) {
61         double pt = _total_pressure_node->getDoubleValue();
62         double p = _static_pressure_node->getDoubleValue();
63         double q = pt - p;      // dynamic pressure
64
65                                 // Now, reverse the equation
66         double v_fps = sqrt((2 * q) / SEA_LEVEL_DENSITY_SLUGFT3);
67
68         _speed_node->setDoubleValue(v_fps * FPSTOKTS);
69     }
70 }
71
72 // end of airspeed_indicator.cxx