]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
Don't scale elevator by 0.5.
[flightgear.git] / src / Instrumentation / altimeter.cxx
1 // altimeter.cxx - an altimeter tied to the static port.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <simgear/math/interpolater.hxx>
7
8 #include "altimeter.hxx"
9 #include <Main/fg_props.hxx>
10 #include <Main/util.hxx>
11
12
13 // A higher number means more responsive
14 #define RESPONSIVENESS 10.0
15
16
17 // Altitude based on pressure difference from sea level.
18 // pressure difference inHG, altitude ft
19 static double altitude_data[][2] = {
20  { -8.41, -8858.27 },
21  { 0.00, 0.00 },
22  { 3.05, 2952.76 },
23  { 5.86, 5905.51 },
24  { 8.41, 8858.27 },
25  { 10.74, 11811.02 },
26  { 12.87, 14763.78 },
27  { 14.78, 17716.54 },
28  { 16.55, 20669.29 },
29  { 18.13, 23622.05 },
30  { 19.62, 26574.80 },
31  { 20.82, 29527.56 },
32  { 21.96, 32480.31 },
33  { 23.01, 35433.07 },
34  { 23.91, 38385.83 },
35  { 24.71, 41338.58 },
36  { 25.40, 44291.34 },
37  { 26.00, 47244.09 },
38  { 26.51, 50196.85 },
39  { 26.96, 53149.61 },
40  { 27.35, 56102.36 },
41  { 27.68, 59055.12 },
42  { 27.98, 62007.87 },
43  { 29.62, 100000.00 },            // just to fill it in
44  { -1, -1 }
45 };
46
47
48 Altimeter::Altimeter ()
49     : _altitude_table(new SGInterpTable)
50 {
51
52     for (int i = 0; altitude_data[i][0] != -1; i++)
53         _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
54 }
55
56 Altimeter::~Altimeter ()
57 {
58     delete _altitude_table;
59 }
60
61 void
62 Altimeter::init ()
63 {
64     _serviceable_node =
65         fgGetNode("/instrumentation/altimeter/serviceable", true);
66     _setting_node =
67         fgGetNode("/instrumentation/altimeter/setting-inhg", true);
68     _pressure_node =
69         fgGetNode("/systems/static/pressure-inhg", true);
70     _altitude_node =
71         fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true);
72 }
73
74 void
75 Altimeter::update (double dt)
76 {
77     if (_serviceable_node->getBoolValue()) {
78         double pressure = _pressure_node->getDoubleValue();
79         double setting = _setting_node->getDoubleValue();
80
81                                 // Move towards the current setting
82         double last_altitude = _altitude_node->getDoubleValue();
83         double current_altitude =
84             _altitude_table->interpolate(setting - pressure);
85         _altitude_node->setDoubleValue(fgGetLowPass(last_altitude,
86                                                     current_altitude,
87                                                     dt * RESPONSIVENESS));
88     }
89 }
90
91 // end of altimeter.cxx