]> git.mxchange.org Git - flightgear.git/blob - src/Systems/vacuum.cxx
allow to trigger widgets via accelerator key, which is defined via "keynum"
[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     scale(1.0)
15
16 {
17     rpms.clear();
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             rpms.push_back(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     rpms.clear();
45     scale = 1.0;
46 }
47
48 VacuumSystem::~VacuumSystem ()
49 {
50 }
51
52 void
53 VacuumSystem::init()
54 {
55     unsigned int i;
56     string branch;
57     branch = "/systems/" + name;
58
59     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
60     _serviceable_node = node->getChild("serviceable", 0, true);
61     for ( i = 0; i < rpms.size(); i++ ) {
62       SGPropertyNode_ptr _rpm_node = fgGetNode(rpms[i].c_str(), true);
63       _rpm_nodes.push_back( _rpm_node );
64     }
65     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
66     _suction_node = node->getChild("suction-inhg", 0, true);
67 }
68
69 void
70 VacuumSystem::bind ()
71 {
72 }
73
74 void
75 VacuumSystem::unbind ()
76 {
77 }
78
79 void
80 VacuumSystem::update (double dt)
81 {
82     // Model taken from steam.cxx
83
84     double suction;
85     unsigned int i;
86
87     if (!_serviceable_node->getBoolValue()) {
88         suction = 0.0;
89     } else {
90         // select the source with the max rpm
91         double rpm = 0.0;
92         for ( i = 0; i < _rpm_nodes.size(); i++ ) {
93           double tmp = _rpm_nodes[i]->getDoubleValue() * scale;
94           if ( tmp > rpm ) {
95             rpm = tmp;
96           }
97         }
98         double pressure = _pressure_node->getDoubleValue();
99         // This magic formula yields about 4 inhg at 700 rpm
100         suction = pressure * rpm / (rpm + 4875.0);
101
102         // simple regulator model that clamps smoothly to about 5 inhg
103         // over a normal rpm range
104         double max = (rpm > 0 ? 5.39 - 1.0 / ( rpm * 0.00111 ) : 0);
105         if ( suction < 0.0 ) suction = 0.0;
106         if ( suction > max ) suction = max;
107     }
108     _suction_node->setDoubleValue(suction);
109 }
110
111 // end of vacuum.cxx