1 // altimeter.cxx - an altimeter tied to the static port.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain and comes with no warranty.
6 #include <simgear/math/interpolater.hxx>
8 #include "altimeter.hxx"
9 #include <Main/fg_props.hxx>
10 #include <Main/util.hxx>
13 // A higher number means more responsive
14 #define RESPONSIVENESS 10.0
17 // Altitude based on pressure difference from sea level.
18 // pressure difference inHG, altitude ft
19 static double altitude_data[][2] = {
43 { 29.62, 100000.00 }, // just to fill it in
48 Altimeter::Altimeter ()
49 : _altitude_table(new SGInterpTable)
52 for (int i = 0; altitude_data[i][0] != -1; i++)
53 _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
56 Altimeter::~Altimeter ()
58 delete _altitude_table;
65 fgGetNode("/instrumentation/altimeter/serviceable", true);
67 fgGetNode("/instrumentation/altimeter/setting-inhg", true);
69 fgGetNode("/systems/static/pressure-inhg", true);
71 fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true);
75 Altimeter::update (double dt)
77 if (_serviceable_node->getBoolValue()) {
78 double pressure = _pressure_node->getDoubleValue();
79 double setting = _setting_node->getDoubleValue();
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,
87 dt * RESPONSIVENESS));
91 // end of altimeter.cxx