]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
Make various PUI widgets private.
[flightgear.git] / src / Instrumentation / altimeter.cxx
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
5 // Last modified by Eric van den Berg, 25 Nov 2012
6 //
7 // This file is in the Public Domain and comes with no warranty.
8
9 // Example invocation, in the instrumentation.xml file:
10 //      <altimeter>
11 //        <name>encoder</name>
12 //        <number>0</number>
13 //        <static-pressure>/systems/static/pressure-inhg</static-pressure>
14 //        <quantum>10</quantum>
15 //        <tau>0</tau>
16 //      </altimeter>
17 // Note non-default name, quantum, and tau values.
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include <simgear/constants.h>
24 #include <simgear/math/interpolater.hxx>
25 #include <simgear/math/SGMath.hxx>
26
27 #include <Main/fg_props.hxx>
28 #include <Main/util.hxx>
29 #include <Environment/atmosphere.hxx>
30
31 #include "altimeter.hxx"
32
33 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
34     : _rootNode( 
35        fgGetNode("/instrumentation",true)->
36            getChild( node->getStringValue("name", "altimeter"),
37                      node->getIntValue("number", 0),
38                      true)),
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)
43 {
44     _tiedProperties.setRoot( _rootNode );
45 }
46
47 Altimeter::~Altimeter ()
48 {}
49
50 double
51 Altimeter::getSettingInHg() const
52 {
53     return _settingInHg;
54 }
55
56 void
57 Altimeter::setSettingInHg( double value )
58 {
59     _settingInHg = value;
60 }
61
62 double
63 Altimeter::getSettingHPa() const
64 {
65     return _settingInHg * SG_INHG_TO_PA / 100;
66 }
67
68 void
69 Altimeter::setSettingHPa( double value )
70 {
71     _settingInHg = value * SG_PA_TO_INHG * 100;
72 }
73
74
75 void
76 Altimeter::init ()
77 {
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);
83
84     reinit();
85 }
86
87 void
88 Altimeter::reinit ()
89 {
90     _raw_PA = 0.0;
91     _kollsman = 0.0;
92 }
93
94 void
95 Altimeter::bind()
96 {
97     _tiedProperties.Tie("setting-inhg", this, &Altimeter::getSettingInHg, &Altimeter::setSettingInHg );
98     _tiedProperties.Tie("setting-hpa", this, &Altimeter::getSettingHPa, &Altimeter::setSettingHPa );
99 }
100
101 void
102 Altimeter::unbind()
103 {
104     _tiedProperties.Untie();
105 }
106
107 void
108 Altimeter::update (double dt)
109 {
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);
118         if (_quantum)
119             press_alt = _quantum * SGMiscd::round(_raw_PA/_quantum);
120         else
121             press_alt = _raw_PA;
122         _press_alt_node->setDoubleValue(press_alt);
123         _altitude_node->setDoubleValue(press_alt - _kollsman);
124     }
125 }
126
127 // end of altimeter.cxx