1 // altimeter.cxx - an altimeter tied to the static port.
2 // Written by David Megginson, started 2002.
3 // Modified by John Denker in 2007 to use a two layer atmosphere
4 // model in src/Environment/atmosphere.?xx
6 // This file is in the Public Domain and comes with no warranty.
8 // Example invocation, in the instrumentation.xml file:
10 // <name>encoder</name>
12 // <static-pressure>/systems/static/pressure-inhg</static-pressure>
13 // <quantum>10</quantum>
16 // Note non-default name, quantum, and tau values.
18 #include <simgear/math/interpolater.hxx>
19 #include <simgear/math/SGMath.hxx>
21 #include <Main/fg_props.hxx>
22 #include <Main/util.hxx>
23 #include <Environment/atmosphere.hxx>
25 #include "altimeter.hxx"
27 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
28 : _name(node->getStringValue("name", "altimeter")),
29 _num(node->getIntValue("number", 0)),
30 _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
31 _tau(node->getDoubleValue("tau", 0.1)),
32 _quantum(node->getDoubleValue("quantum", quantum))
35 Altimeter::~Altimeter ()
42 branch = "/instrumentation/" + _name;
44 SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
46 _pressure_node = fgGetNode(_static_pressure.c_str(), true);
47 _serviceable_node = node->getChild("serviceable", 0, true);
48 _setting_node = node->getChild("setting-inhg", 0, true);
49 _press_alt_node = node->getChild("pressure-alt-ft", 0, true);
50 _mode_c_node = node->getChild("mode-c-alt-ft", 0, true);
51 _altitude_node = node->getChild("indicated-altitude-ft", 0, true);
53 if (_setting_node->getDoubleValue() == 0)
54 _setting_node->setDoubleValue(29.921260);
58 Altimeter::update (double dt)
60 if (_serviceable_node->getBoolValue()) {
61 double trat = _tau > 0 ? dt/_tau : 100;
62 double pressure = _pressure_node->getDoubleValue();
63 double setting = _setting_node->getDoubleValue();
64 double press_alt = _press_alt_node->getDoubleValue();
65 // The mechanism settles slowly toward new pressure altitude:
66 raw_PA = fgGetLowPass(raw_PA, _altimeter.press_alt_ft(pressure), trat);
67 _mode_c_node->setDoubleValue(100 * SGMiscd::round(raw_PA/100));
68 _kollsman = fgGetLowPass(_kollsman, _altimeter.kollsman_ft(setting), trat);
70 press_alt = _quantum * SGMiscd::round(raw_PA/_quantum);
73 _press_alt_node->setDoubleValue(press_alt);
74 _altitude_node->setDoubleValue(press_alt - _kollsman);
78 // end of altimeter.cxx