X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Faltimeter.cxx;h=3924ed7c92dabd7d5885acf706f41f80c0ee46c3;hb=1df5347a06d5f38bc6d6267f242d5331b7c6f02b;hp=08cfcb36e1fb623b36711bb0c35051aac9732ff3;hpb=8685e68b995ebf436c0e2a0441fc1c9c672dc8d0;p=flightgear.git diff --git a/src/Instrumentation/altimeter.cxx b/src/Instrumentation/altimeter.cxx index 08cfcb36e..3924ed7c9 100644 --- a/src/Instrumentation/altimeter.cxx +++ b/src/Instrumentation/altimeter.cxx @@ -1,93 +1,119 @@ // altimeter.cxx - an altimeter tied to the static port. // Written by David Megginson, started 2002. +// Modified by John Denker in 2007 to use a two layer atmosphere +// model in src/Environment/atmosphere.?xx // // This file is in the Public Domain and comes with no warranty. +// Example invocation, in the instrumentation.xml file: +// +// encoder +// 0 +// /systems/static/pressure-inhg +// 10 +// 0 +// +// Note non-default name, quantum, and tau values. + +#ifdef HAVE_CONFIG_H +# include +#endif + #include +#include -#include "altimeter.hxx" #include
#include
+#include +#include "altimeter.hxx" -// Altitude based on pressure difference from sea level. -// pressure difference inHG, altitude ft -static double altitude_data[][2] = { - -8.41, -8858.27, - 0.00, 0.00, - 3.05, 2952.76, - 5.86, 5905.51, - 8.41, 8858.27, - 10.74, 11811.02, - 12.87, 14763.78, - 14.78, 17716.54, - 16.55, 20669.29, - 18.13, 23622.05, - 19.62, 26574.80, - 20.82, 29527.56, - 21.96, 32480.31, - 23.01, 35433.07, - 23.91, 38385.83, - 24.71, 41338.58, - 25.40, 44291.34, - 26.00, 47244.09, - 26.51, 50196.85, - 26.96, 53149.61, - 27.35, 56102.36, - 27.68, 59055.12, - 27.98, 62007.87, - 29.62, 100000.00 // just to fill it in - -1, -1, -}; - - -Altimeter::Altimeter () - : _altitude_table(new SGInterpTable) -{ +const double hPa2inHg = 29.92 / 1013.25; - for (int i = 0; altitude_data[i][0] != -1; i++) - _altitude_table->addEntry(altitude_data[i][0], altitude_data[i][1]); +Altimeter::Altimeter ( SGPropertyNode *node, double quantum ) + : _rootNode( + fgGetNode("/instrumentation",true)-> + getChild( node->getStringValue("name", "altimeter"), + node->getIntValue("number", 0), + true)), + _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")), + _tau(node->getDoubleValue("tau", 0.1)), + _quantum(node->getDoubleValue("quantum", quantum)), + _settingInHg(29.921260) +{ + _tiedProperties.setRoot( _rootNode ); } Altimeter::~Altimeter () +{} + +double +Altimeter::getSettingInHg() const { - delete _altitude_table; + return _settingInHg; } +void +Altimeter::setSettingInHg( double value ) +{ + _settingInHg = value; +} + +double +Altimeter::getSettingHPa() const +{ + return _settingInHg / hPa2inHg; +} + +void +Altimeter::setSettingHPa( double value ) +{ + _settingInHg = value * hPa2inHg; +} + + void Altimeter::init () { - _serviceable_node = - fgGetNode("/instrumentation/altimeter/serviceable", true); - _setting_node = - fgGetNode("/instrumentation/altimeter/setting-inhg", true); - _pressure_node = - fgGetNode("/systems/static/pressure-inhg", true); - _altitude_node = - fgGetNode("/instrumentation/altimeter/indicated-altitude-ft", true); + raw_PA = 0.0; + _kollsman = 0.0; + _pressure_node = fgGetNode(_static_pressure.c_str(), true); + _serviceable_node = _rootNode->getChild("serviceable", 0, true); + _press_alt_node = _rootNode->getChild("pressure-alt-ft", 0, true); + _mode_c_node = _rootNode->getChild("mode-c-alt-ft", 0, true); + _altitude_node = _rootNode->getChild("indicated-altitude-ft", 0, true); } void -Altimeter::bind () +Altimeter::bind() { + _tiedProperties.Tie("setting-inhg", this, &Altimeter::getSettingInHg, &Altimeter::setSettingInHg ); + _tiedProperties.Tie("setting-hpa", this, &Altimeter::getSettingHPa, &Altimeter::setSettingHPa ); } void -Altimeter::unbind () +Altimeter::unbind() { + _tiedProperties.Untie(); } void Altimeter::update (double dt) { if (_serviceable_node->getBoolValue()) { + double trat = _tau > 0 ? dt/_tau : 100; double pressure = _pressure_node->getDoubleValue(); - double setting = _setting_node->getDoubleValue(); - double altitude = - fgGetLowPass(_altitude_node->getDoubleValue(), - _altitude_table->interpolate(setting - pressure), - dt * 10); - _altitude_node->setDoubleValue(altitude); + double press_alt = _press_alt_node->getDoubleValue(); + // The mechanism settles slowly toward new pressure altitude: + raw_PA = fgGetLowPass(raw_PA, _altimeter.press_alt_ft(pressure), trat); + _mode_c_node->setDoubleValue(100 * SGMiscd::round(raw_PA/100)); + _kollsman = fgGetLowPass(_kollsman, _altimeter.kollsman_ft(_settingInHg), trat); + if (_quantum) + press_alt = _quantum * SGMiscd::round(raw_PA/_quantum); + else + press_alt = raw_PA; + _press_alt_node->setDoubleValue(press_alt); + _altitude_node->setDoubleValue(press_alt - _kollsman); } }