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.
22 #include <simgear/math/interpolater.hxx>
23 #include <simgear/math/SGMath.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Main/util.hxx>
27 #include <Environment/atmosphere.hxx>
29 #include "altimeter.hxx"
31 const double hPa2inHg = 29.92 / 1013.25;
33 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
35 fgGetNode("/instrumentation",true)->
36 getChild( node->getStringValue("name", "altimeter"),
37 node->getIntValue("number", 0),
39 _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
40 _tau(node->getDoubleValue("tau", 0.1)),
41 _quantum(node->getDoubleValue("quantum", quantum)),
42 _settingInHg(29.921260)
44 _tiedProperties.setRoot( _rootNode );
47 Altimeter::~Altimeter ()
51 Altimeter::getSettingInHg() const
57 Altimeter::setSettingInHg( double value )
63 Altimeter::getSettingHPa() const
65 return _settingInHg / hPa2inHg;
69 Altimeter::setSettingHPa( double value )
71 _settingInHg = value * hPa2inHg;
78 _pressure_node = fgGetNode(_static_pressure.c_str(), true);
79 _serviceable_node = _rootNode->getChild("serviceable", 0, true);
80 _press_alt_node = _rootNode->getChild("pressure-alt-ft", 0, true);
81 _mode_c_node = _rootNode->getChild("mode-c-alt-ft", 0, true);
82 _altitude_node = _rootNode->getChild("indicated-altitude-ft", 0, true);
97 _tiedProperties.Tie("setting-inhg", this, &Altimeter::getSettingInHg, &Altimeter::setSettingInHg );
98 _tiedProperties.Tie("setting-hpa", this, &Altimeter::getSettingHPa, &Altimeter::setSettingHPa );
104 _tiedProperties.Untie();
108 Altimeter::update (double dt)
110 if (_serviceable_node->getBoolValue()) {
111 double trat = _tau > 0 ? dt/_tau : 100;
112 double pressure = _pressure_node->getDoubleValue();
113 double press_alt = _press_alt_node->getDoubleValue();
114 // The mechanism settles slowly toward new pressure altitude:
115 _raw_PA = fgGetLowPass(_raw_PA, _altimeter.press_alt_ft(pressure), trat);
116 _mode_c_node->setDoubleValue(100 * SGMiscd::round(_raw_PA/100));
117 _kollsman = fgGetLowPass(_kollsman, _altimeter.kollsman_ft(_settingInHg), trat);
119 press_alt = _quantum * SGMiscd::round(_raw_PA/_quantum);
122 _press_alt_node->setDoubleValue(press_alt);
123 _altitude_node->setDoubleValue(press_alt - _kollsman);
127 // end of altimeter.cxx