]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
56516da2c647adf0d84e128e083e0d10b5a47a6b
[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 //
6 // This file is in the Public Domain and comes with no warranty.
7
8 // Example invocation, in the instrumentation.xml file:
9 //      <altimeter>
10 //        <name>encoder</name>
11 //        <number>0</number>
12 //        <static-pressure>/systems/static/pressure-inhg</static-pressure>
13 //        <quantum>10</quantum>
14 //        <tau>0</tau>
15 //      </altimeter>
16 // Note non-default name, quantum, and tau values.
17
18 #include <simgear/math/interpolater.hxx>
19
20 #include <Main/fg_props.hxx>
21 #include <Main/util.hxx>
22 #include <Environment/atmosphere.hxx>
23
24 #include "altimeter.hxx"
25
26 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
27     : _name(node->getStringValue("name", "altimeter")),
28       _num(node->getIntValue("number", 0)),
29       _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
30       _tau(node->getDoubleValue("tau", 0.1)),
31       _quantum(node->getDoubleValue("quantum", quantum))
32 {}
33
34 Altimeter::~Altimeter ()
35 {}
36
37 void
38 Altimeter::init ()
39 {
40     string branch;
41     branch = "/instrumentation/" + _name;
42
43     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
44     raw_PA = 0.0;
45     _pressure_node     = fgGetNode(_static_pressure.c_str(), true);
46     _serviceable_node  = node->getChild("serviceable", 0, true);
47     _setting_node      = node->getChild("setting-inhg", 0, true);
48     _press_alt_node    = node->getChild("pressure-alt-ft", 0, true);
49     _mode_c_node       = node->getChild("mode-c-alt-ft", 0, true);
50     _altitude_node     = node->getChild("indicated-altitude-ft", 0, true);
51
52     if (_setting_node->getDoubleValue() == 0)
53         _setting_node->setDoubleValue(29.921260);
54 }
55
56 void
57 Altimeter::update (double dt)
58 {
59     if (_serviceable_node->getBoolValue()) {
60         double trat = _tau > 0 ? dt/_tau : 100;
61         double pressure = _pressure_node->getDoubleValue();
62         double setting = _setting_node->getDoubleValue();
63         double press_alt = _press_alt_node->getDoubleValue();
64         // The mechanism settles slowly toward new pressure altitude:
65         raw_PA = fgGetLowPass(raw_PA, _altimeter.press_alt_ft(pressure), trat);
66         _mode_c_node->setDoubleValue(100 * round(raw_PA/100));
67         _kollsman = fgGetLowPass(_kollsman, _altimeter.kollsman_ft(setting), trat);
68         if (_quantum)
69             press_alt = _quantum*round(raw_PA/_quantum);
70         else
71             press_alt = raw_PA;
72         _press_alt_node->setDoubleValue(press_alt);
73         _altitude_node->setDoubleValue(press_alt - _kollsman);
74     }
75 }
76
77 // end of altimeter.cxx