]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/vertical_speed_indicator.cxx
Melchior FRANZ:
[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("vertical-speed-indicator"),
16       num(0),
17       static_port("/systems/static")
18 {
19     int i;
20     for ( i = 0; i < node->nChildren(); ++i ) {
21         SGPropertyNode *child = node->getChild(i);
22         string cname = child->getName();
23         string cval = child->getStringValue();
24         if ( cname == "name" ) {
25             name = cval;
26         } else if ( cname == "number" ) {
27             num = child->getIntValue();
28         } else if ( cname == "static-port" ) {
29             static_port = cval;
30         } else {
31             SG_LOG( SG_INSTR, SG_WARN, "Error in vertical-speed-indicator config logic" );
32             if ( name.length() ) {
33                 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
34             }
35         }
36     }
37 }
38
39 VerticalSpeedIndicator::VerticalSpeedIndicator ()
40     : _internal_pressure_inhg(29.92)
41 {
42 }
43
44 VerticalSpeedIndicator::~VerticalSpeedIndicator ()
45 {
46 }
47
48 void
49 VerticalSpeedIndicator::init ()
50 {
51     string branch;
52     branch = "/instrumentation/" + name;
53     static_port += "/pressure-inhg";
54
55     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
56     _serviceable_node = node->getChild("serviceable", 0, true);
57     _pressure_node = fgGetNode(static_port.c_str(), true);
58     _speed_node = node->getChild("indicated-speed-fpm", 0, true);
59
60                                 // Initialize at ambient pressure
61     _internal_pressure_inhg = _pressure_node->getDoubleValue();
62 }
63
64 void
65 VerticalSpeedIndicator::update (double dt)
66 {
67                                 // model taken from steam.cxx, with change
68                                 // from 10000 to 10500 for manual factor
69     if (_serviceable_node->getBoolValue()) {
70         double pressure = _pressure_node->getDoubleValue();
71         _speed_node
72             ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500);
73         _internal_pressure_inhg =
74             fgGetLowPass(_internal_pressure_inhg,
75                          _pressure_node->getDoubleValue(),
76                          dt/6.0);
77     }
78 }
79
80 // end of vertical_speed_indicator.cxx