]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/altimeter.cxx
Make voiceplayer independent
[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 #ifdef HAVE_CONFIG_H
19 #  include <config.h>
20 #endif
21
22 #include <simgear/math/interpolater.hxx>
23 #include <simgear/math/SGMath.hxx>
24
25 #include <Main/fg_props.hxx>
26 #include <Main/util.hxx>
27 #include <Environment/atmosphere.hxx>
28
29 #include "altimeter.hxx"
30
31 Altimeter::Altimeter ( SGPropertyNode *node, double quantum )
32     : _name(node->getStringValue("name", "altimeter")),
33       _num(node->getIntValue("number", 0)),
34       _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg")),
35       _tau(node->getDoubleValue("tau", 0.1)),
36       _quantum(node->getDoubleValue("quantum", quantum))
37 {}
38
39 Altimeter::~Altimeter ()
40 {}
41
42 void
43 Altimeter::init ()
44 {
45     string branch;
46     branch = "/instrumentation/" + _name;
47
48     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
49     raw_PA = 0.0;
50     _kollsman = 0.0;
51     _pressure_node     = fgGetNode(_static_pressure.c_str(), true);
52     _serviceable_node  = node->getChild("serviceable", 0, true);
53     _setting_node      = node->getChild("setting-inhg", 0, true);
54     _press_alt_node    = node->getChild("pressure-alt-ft", 0, true);
55     _mode_c_node       = node->getChild("mode-c-alt-ft", 0, true);
56     _altitude_node     = node->getChild("indicated-altitude-ft", 0, true);
57
58     if (_setting_node->getDoubleValue() == 0)
59         _setting_node->setDoubleValue(29.921260);
60 }
61
62 void
63 Altimeter::update (double dt)
64 {
65     if (_serviceable_node->getBoolValue()) {
66         double trat = _tau > 0 ? dt/_tau : 100;
67         double pressure = _pressure_node->getDoubleValue();
68         double setting = _setting_node->getDoubleValue();
69         double press_alt = _press_alt_node->getDoubleValue();
70         // The mechanism settles slowly toward new pressure altitude:
71         raw_PA = fgGetLowPass(raw_PA, _altimeter.press_alt_ft(pressure), trat);
72         _mode_c_node->setDoubleValue(100 * SGMiscd::round(raw_PA/100));
73         _kollsman = fgGetLowPass(_kollsman, _altimeter.kollsman_ft(setting), trat);
74         if (_quantum)
75             press_alt = _quantum * SGMiscd::round(raw_PA/_quantum);
76         else
77             press_alt = raw_PA;
78         _press_alt_node->setDoubleValue(press_alt);
79         _altitude_node->setDoubleValue(press_alt - _kollsman);
80     }
81 }
82
83 // end of altimeter.cxx