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 ( SGPropertyNode *node )
49 : _name(node->getStringValue("name", "altimeter")),
50 _num(node->getIntValue("number", 0)),
51 _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
52 _altitude_table(new SGInterpTable)
55 for (i = 0; altitude_data[i][0] != -1; i++)
56 _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
59 Altimeter::~Altimeter ()
61 delete _altitude_table;
68 branch = "/instrumentation/" + _name;
70 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
72 _serviceable_node = node->getChild("serviceable", 0, true);
73 _setting_node = node->getChild("setting-inhg", 0, true);
74 _pressure_node = fgGetNode(_static_pressure.c_str(), true);
75 _altitude_node = node->getChild("indicated-altitude-ft", 0, true);
79 Altimeter::update (double dt)
81 if (_serviceable_node->getBoolValue()) {
82 double pressure = _pressure_node->getDoubleValue();
83 double setting = _setting_node->getDoubleValue();
85 // Move towards the current setting
86 double last_altitude = _altitude_node->getDoubleValue();
87 double current_altitude =
88 _altitude_table->interpolate(setting - pressure);
89 _altitude_node->setDoubleValue(fgGetLowPass(last_altitude,
91 dt * RESPONSIVENESS));
95 // end of altimeter.cxx