]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
Modified to use fgGetLowPass from utils.cxx.
[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 // Altitude based on pressure difference from sea level.
14 // pressure difference inHG, altitude ft
15 static double altitude_data[][2] = {
16     -8.41, -8858.27,
17     0.00, 0.00,
18     3.05, 2952.76,
19     5.86, 5905.51,
20     8.41, 8858.27,
21     10.74, 11811.02,
22     12.87, 14763.78,
23     14.78, 17716.54,
24     16.55, 20669.29,
25     18.13, 23622.05,
26     19.62, 26574.80,
27     20.82, 29527.56,
28     21.96, 32480.31,
29     23.01, 35433.07,
30     23.91, 38385.83,
31     24.71, 41338.58,
32     25.40, 44291.34,
33     26.00, 47244.09,
34     26.51, 50196.85,
35     26.96, 53149.61,
36     27.35, 56102.36,
37     27.68, 59055.12,
38     27.98, 62007.87,
39     29.62, 100000.00            // just to fill it in
40     -1, -1,
41 };
42
43
44 Altimeter::Altimeter ()
45     : _altitude_table(new SGInterpTable)
46 {
47
48     for (int i = 0; altitude_data[i][0] != -1; i++)
49         _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
50 }
51
52 Altimeter::~Altimeter ()
53 {
54     delete _altitude_table;
55 }
56
57 void
58 Altimeter::init ()
59 {
60     _serviceable_node =
61         fgGetNode("/instrumentation/altimeter/serviceable", true);
62     _setting_node =
63         fgGetNode("/instrumentation/altimeter/setting-inhg", true);
64     _pressure_node =
65         fgGetNode("/systems/static/pressure-inhg", true);
66     _altitude_node =
67         fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true);
68 }
69
70 void
71 Altimeter::bind ()
72 {
73 }
74
75 void
76 Altimeter::unbind ()
77 {
78 }
79
80 void
81 Altimeter::update (double dt)
82 {
83     if (_serviceable_node->getBoolValue()) {
84         double pressure = _pressure_node->getDoubleValue();
85         double setting = _setting_node->getDoubleValue();
86         double altitude =
87             fgGetLowPass(_altitude_node->getDoubleValue(),
88                          _altitude_table->interpolate(setting - pressure),
89                          dt * 10);
90         _altitude_node->setDoubleValue(altitude);
91     }
92 }
93
94 // end of altimeter.cxx