]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/vertical_speed_indicator.cxx
Fix a dumb bug in NavDisplay text-enable.
[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 #ifdef HAVE_CONFIG_H
7 #  include "config.h"
8 #endif
9
10 #include <simgear/math/interpolater.hxx>
11
12 #include "vertical_speed_indicator.hxx"
13 #include <Main/fg_props.hxx>
14 #include <Main/util.hxx>
15
16 using std::string;
17
18 VerticalSpeedIndicator::VerticalSpeedIndicator ( SGPropertyNode *node )
19     : _internal_pressure_inhg(29.92),
20       _name(node->getStringValue("name", "vertical-speed-indicator")),
21       _num(node->getIntValue("number", 0)),
22       _static_pressure(node->getStringValue("static-pressure", "/systems/static/pressure-inhg"))
23 {
24 }
25
26 VerticalSpeedIndicator::~VerticalSpeedIndicator ()
27 {
28 }
29
30 void
31 VerticalSpeedIndicator::init ()
32 {
33     string branch;
34     branch = "/instrumentation/" + _name;
35
36     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
37     _serviceable_node = node->getChild("serviceable", 0, true);
38     _pressure_node = fgGetNode(_static_pressure.c_str(), true);
39     _speed_node = node->getChild("indicated-speed-fpm", 0, true);
40     _speed_up_node = fgGetNode("/sim/speed-up", true);
41
42                                 // Initialize at ambient pressure
43     _internal_pressure_inhg = _pressure_node->getDoubleValue();
44 }
45
46 void
47 VerticalSpeedIndicator::update (double dt)
48 {
49                                 // model taken from steam.cxx, with change
50                                 // from 10000 to 10500 for manual factor
51     if (_serviceable_node->getBoolValue()) {
52         double pressure = _pressure_node->getDoubleValue();
53         double speed_up = _speed_up_node->getDoubleValue();
54         if( speed_up > 1 )
55             dt *= speed_up;
56         _speed_node
57             ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500);
58         _internal_pressure_inhg =
59             fgGetLowPass(_internal_pressure_inhg,
60                          _pressure_node->getDoubleValue(),
61                          dt/6.0);
62     }
63 }
64
65 // end of vertical_speed_indicator.cxx