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