]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/vertical_speed_indicator.cxx
adf: fix "in-range" node
[flightgear.git] / src / Instrumentation / vertical_speed_indicator.cxx
1 // vertical_speed_indicator.cxx - a regular VSI.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6 #include <simgear/math/interpolater.hxx>
7
8 #include "vertical_speed_indicator.hxx"
9 #include <Main/fg_props.hxx>
10 #include <Main/util.hxx>
11
12
13 VerticalSpeedIndicator::VerticalSpeedIndicator ( SGPropertyNode *node )
14     : _internal_pressure_inhg(29.92),
15       _name(node->getStringValue("name", "vertical-speed-indicator")),
16       _num(node->getIntValue("number", 0)),
17       _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg"))
18 {
19 }
20
21 VerticalSpeedIndicator::~VerticalSpeedIndicator ()
22 {
23 }
24
25 void
26 VerticalSpeedIndicator::init ()
27 {
28     string branch;
29     branch = "/instrumentation/" + _name;
30
31     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
32     _serviceable_node = node->getChild("serviceable", 0, true);
33     _pressure_node = fgGetNode(_static_pressure.c_str(), true);
34     _speed_node = node->getChild("indicated-speed-fpm", 0, true);
35     _speed_up_node = fgGetNode("/sim/speed-up", true);
36
37                                 // Initialize at ambient pressure
38     _internal_pressure_inhg = _pressure_node->getDoubleValue();
39 }
40
41 void
42 VerticalSpeedIndicator::update (double dt)
43 {
44                                 // model taken from steam.cxx, with change
45                                 // from 10000 to 10500 for manual factor
46     if (_serviceable_node->getBoolValue()) {
47         double pressure = _pressure_node->getDoubleValue();
48         double speed_up = _speed_up_node->getDoubleValue();
49         if( speed_up > 1 )
50             dt *= speed_up;
51         _speed_node
52             ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500);
53         _internal_pressure_inhg =
54             fgGetLowPass(_internal_pressure_inhg,
55                          _pressure_node->getDoubleValue(),
56                          dt/6.0);
57     }
58 }
59
60 // end of vertical_speed_indicator.cxx