]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/vertical_speed_indicator.cxx
use simgear::strutils::rpad() instead of strncpy()
[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
36                                 // Initialize at ambient pressure
37     _internal_pressure_inhg = _pressure_node->getDoubleValue();
38 }
39
40 void
41 VerticalSpeedIndicator::update (double dt)
42 {
43                                 // model taken from steam.cxx, with change
44                                 // from 10000 to 10500 for manual factor
45     if (_serviceable_node->getBoolValue()) {
46         double pressure = _pressure_node->getDoubleValue();
47         _speed_node
48             ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500);
49         _internal_pressure_inhg =
50             fgGetLowPass(_internal_pressure_inhg,
51                          _pressure_node->getDoubleValue(),
52                          dt/6.0);
53     }
54 }
55
56 // end of vertical_speed_indicator.cxx