]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/vertical_speed_indicator.cxx
Roy Vegard Ovesen:
[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_AUTOPILOT, SG_WARN, "Error in vertical-speed-indicator config logic" );
32             if ( name.length() ) {
33                 SG_LOG( SG_AUTOPILOT, 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     _serviceable_node->setBoolValue(true);
61                                 // Initialize at ambient pressure
62     _internal_pressure_inhg = _pressure_node->getDoubleValue();
63 }
64
65 void
66 VerticalSpeedIndicator::update (double dt)
67 {
68                                 // model taken from steam.cxx, with change
69                                 // from 10000 to 10500 for manual factor
70     if (_serviceable_node->getBoolValue()) {
71         double pressure = _pressure_node->getDoubleValue();
72         _speed_node
73             ->setDoubleValue((_internal_pressure_inhg - pressure) * 10500);
74         _internal_pressure_inhg =
75             fgGetLowPass(_internal_pressure_inhg,
76                          _pressure_node->getDoubleValue(),
77                          dt/6.0);
78     }
79 }
80
81 // end of vertical_speed_indicator.cxx