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 : _altitude_table(new SGInterpTable),
52 static_port("/systems/static")
55 for (int i = 0; altitude_data[i][0] != -1; i++)
56 _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
59 for ( i = 0; i < node->nChildren(); ++i ) {
60 SGPropertyNode *child = node->getChild(i);
61 string cname = child->getName();
62 string cval = child->getStringValue();
63 if ( cname == "name" ) {
65 } else if ( cname == "number" ) {
66 num = child->getIntValue();
67 } else if ( cname == "static-port" ) {
70 SG_LOG( SG_AUTOPILOT, SG_WARN, "Error in altimeter config logic" );
71 if ( name.length() ) {
72 SG_LOG( SG_AUTOPILOT, SG_WARN, "Section = " << name );
78 Altimeter::Altimeter ()
79 : _altitude_table(new SGInterpTable)
82 for (int i = 0; altitude_data[i][0] != -1; i++)
83 _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]);
86 Altimeter::~Altimeter ()
88 delete _altitude_table;
95 branch = "/instrumentation/" + name;
96 static_port += "/pressure-inhg";
98 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
100 _serviceable_node = node->getChild("serviceable", 0, true);
101 _setting_node = node->getChild("setting-inhg", 0, true);
102 _pressure_node = fgGetNode(static_port.c_str(), true);
103 _altitude_node = node->getChild("indicated-altitude-ft", 0, true);
105 _serviceable_node->setBoolValue(true);
106 _setting_node->setDoubleValue(29.92);
110 Altimeter::update (double dt)
112 if (_serviceable_node->getBoolValue()) {
113 double pressure = _pressure_node->getDoubleValue();
114 double setting = _setting_node->getDoubleValue();
116 // Move towards the current setting
117 double last_altitude = _altitude_node->getDoubleValue();
118 double current_altitude =
119 _altitude_table->interpolate(setting - pressure);
120 _altitude_node->setDoubleValue(fgGetLowPass(last_altitude,
122 dt * RESPONSIVENESS));
126 // end of altimeter.cxx