]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/vacuum.cxx
Add a *really* crude model of ITT, Oil Temp, and Oil Pressure. This
[flightgear.git] / src / Systems / vacuum.cxx
index 19bde57773912bd073779970f47bd67dc4650bc6..256e6efaff80c07a9290f13df02126a39fe84861 100644 (file)
@@ -7,8 +7,42 @@
 #include <Main/fg_props.hxx>
 
 
-VacuumSystem::VacuumSystem ()
+VacuumSystem::VacuumSystem ( SGPropertyNode *node )
+    :
+    name("vacuum"),
+    num(0),
+    rpm("/engines/engine[0]/rpm"),
+    scale(1.0)
+
 {
+    int i;
+    for ( i = 0; i < node->nChildren(); ++i ) {
+        SGPropertyNode *child = node->getChild(i);
+        string cname = child->getName();
+        string cval = child->getStringValue();
+        if ( cname == "name" ) {
+            name = cval;
+        } else if ( cname == "number" ) {
+            num = child->getIntValue();
+        } else if ( cname == "rpm" ) {
+            rpm = cval;
+        } else if ( cname == "scale" ) {
+            scale = child->getDoubleValue();
+        } else {
+            SG_LOG( SG_SYSTEMS, SG_WARN, "Error in vacuum config logic" );
+            if ( name.length() ) {
+                SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name );
+            }
+        }
+    }
+}
+
+VacuumSystem::VacuumSystem( int i )
+{
+    name = "vacuum";
+    num = i;
+    rpm = "/engines/engine[0]/rpm";
+    scale = 1.0;
 }
 
 VacuumSystem::~VacuumSystem ()
@@ -16,14 +50,16 @@ VacuumSystem::~VacuumSystem ()
 }
 
 void
-VacuumSystem::init ()
+VacuumSystem::init()
 {
-                                // TODO: allow index of pump and engine
-                                // to be configured.
-    _serviceable_node = fgGetNode("/systems/vacuum[0]/serviceable", true);
-    _rpm_node = fgGetNode("/engines/engine[0]/rpm", true);
+    string branch;
+    branch = "/systems/" + name;
+
+    SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+    _serviceable_node = node->getChild("serviceable", 0, true);
+    _rpm_node = fgGetNode(rpm.c_str(), true);
     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
-    _suction_node = fgGetNode("/systems/vacuum[0]/suction-inhg", true);
+    _suction_node = node->getChild("suction-inhg", 0, true);
 }
 
 void
@@ -46,11 +82,16 @@ VacuumSystem::update (double dt)
     if (!_serviceable_node->getBoolValue()) {
         suction = 0.0;
     } else {
-        double rpm = _rpm_node->getDoubleValue();
+        double rpm = _rpm_node->getDoubleValue() * scale;
         double pressure = _pressure_node->getDoubleValue();
-        suction = pressure * rpm / (rpm + 10000.0);
-        if (suction > 5.0)
-            suction = 5.0;
+        // This magic formula yields about 4 inhg at 700 rpm
+        suction = pressure * rpm / (rpm + 4875.0);
+
+        // simple regulator model that clamps smoothly to about 5 inhg
+        // over a normal rpm range
+        double max = (rpm > 0 ? 5.39 - 1.0 / ( rpm * 0.00111 ) : 0);
+        if ( suction < 0.0 ) suction = 0.0;
+        if ( suction > max ) suction = max;
     }
     _suction_node->setDoubleValue(suction);
 }