]> git.mxchange.org Git - flightgear.git/blob - src/Systems/vacuum.cxx
cab464404fdd8dc89cea069683d978dc3472b802
[flightgear.git] / src / Systems / vacuum.cxx
1 // vacuum.cxx - a vacuum pump connected to the aircraft engine.
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 "vacuum.hxx"
11 #include <Main/fg_props.hxx>
12
13
14 VacuumSystem::VacuumSystem ( SGPropertyNode *node )
15     :
16     _name(node->getStringValue("name", "vacuum")),
17     _num(node->getIntValue("number", 0)),
18     _scale(node->getDoubleValue("scale", 1.0))
19 {
20     _rpms.clear();
21     int i;
22     for ( i = 0; i < node->nChildren(); ++i ) {
23         SGPropertyNode *child = node->getChild(i);
24         string cname = child->getName();
25         string cval = child->getStringValue();
26         if ( cname == "rpm" ) {
27             _rpms.push_back(cval);
28         } else {
29             SG_LOG( SG_SYSTEMS, SG_WARN, "Error in vacuum config logic" );
30             if ( _name.length() ) {
31                 SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << _name );
32             }
33         }
34     }
35 }
36
37 VacuumSystem::~VacuumSystem ()
38 {
39 }
40
41 void
42 VacuumSystem::init()
43 {
44     unsigned int i;
45     string branch;
46     branch = "/systems/" + _name;
47
48     SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
49     _serviceable_node = node->getChild("serviceable", 0, true);
50     for ( i = 0; i < _rpms.size(); i++ ) {
51       SGPropertyNode_ptr _rpm_node = fgGetNode(_rpms[i].c_str(), true);
52       _rpm_nodes.push_back( _rpm_node );
53     }
54     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
55     _suction_node = node->getChild("suction-inhg", 0, true);
56 }
57
58 void
59 VacuumSystem::bind ()
60 {
61 }
62
63 void
64 VacuumSystem::unbind ()
65 {
66 }
67
68 void
69 VacuumSystem::update (double dt)
70 {
71     // Model taken from steam.cxx
72
73     double suction;
74     unsigned int i;
75
76     if (!_serviceable_node->getBoolValue()) {
77         suction = 0.0;
78     } else {
79         // select the source with the max rpm
80         double rpm = 0.0;
81         for ( i = 0; i < _rpm_nodes.size(); i++ ) {
82           double tmp = _rpm_nodes[i]->getDoubleValue() * _scale;
83           if ( tmp > rpm ) {
84             rpm = tmp;
85           }
86         }
87         double pressure = _pressure_node->getDoubleValue();
88         // This magic formula yields about 4 inhg at 700 rpm
89         suction = pressure * rpm / (rpm + 4875.0);
90
91         // simple regulator model that clamps smoothly to about 5 inhg
92         // over a normal rpm range
93         double max = (rpm > 0 ? 5.39 - 1.0 / ( rpm * 0.00111 ) : 0);
94         if ( suction < 0.0 ) suction = 0.0;
95         if ( suction > max ) suction = max;
96     }
97     _suction_node->setDoubleValue(suction);
98 }
99
100 // end of vacuum.cxx