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