]> git.mxchange.org Git - flightgear.git/blobdiff - src/Systems/pitot.cxx
Fix line endings
[flightgear.git] / src / Systems / pitot.cxx
index 0a58805b53ca1ecd649044add09dc33d6e9268b0..3851f53fd3c4471b86b9b0da0526145a01475ee5 100644 (file)
@@ -8,8 +8,34 @@
 #include <Main/util.hxx>
 
 
-PitotSystem::PitotSystem ()
+
+PitotSystem::PitotSystem ( SGPropertyNode *node )
+    :
+    name("pitot"),
+    num(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 {
+            SG_LOG( SG_SYSTEMS, SG_WARN, "Error in systems config logic" );
+            if ( name.length() ) {
+                SG_LOG( SG_SYSTEMS, SG_WARN, "Section = " << name );
+            }
+        }
+    }
+}
+
+PitotSystem::PitotSystem ( int i )
 {
+    num = i;
+    name = "pitot";
 }
 
 PitotSystem::~PitotSystem ()
@@ -19,12 +45,15 @@ PitotSystem::~PitotSystem ()
 void
 PitotSystem::init ()
 {
-    _serviceable_node = fgGetNode("/systems/pitot[0]/serviceable", true);
+    string branch;
+    branch = "/systems/" + name;
+
+    SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+    _serviceable_node = node->getChild("serviceable", 0, true);
     _pressure_node = fgGetNode("/environment/pressure-inhg", true);
     _density_node = fgGetNode("/environment/density-slugft3", true);
-    _velocity_node = fgGetNode("/velocities/uBody-fps", true);
-    _total_pressure_node =
-        fgGetNode("/systems/pitot[0]/total-pressure-inhg", true);
+    _velocity_node = fgGetNode("/velocities/airspeed-kt", true);
+    _total_pressure_node = node->getChild("total-pressure-inhg", 0, true);
 }
 
 void
@@ -37,17 +66,30 @@ PitotSystem::unbind ()
 {
 }
 
+#ifndef INHGTOPSF
+# define INHGTOPSF (2116.217/29.9212)
+#endif
+
+#ifndef PSFTOINHG
+# define PSFTOINHG (1/INHGTOPSF)
+#endif
+
+#ifndef KTTOFPS
+# define KTTOFPS 1.68781
+#endif
+
+
 void
 PitotSystem::update (double dt)
 {
     if (_serviceable_node->getBoolValue()) {
                                 // The pitot tube sees the forward
                                 // velocity in the body axis.
-        double p = _pressure_node->getDoubleValue();
+        double p = _pressure_node->getDoubleValue() * INHGTOPSF;
         double r = _density_node->getDoubleValue();
-        double v = _velocity_node->getDoubleValue();
-        double q = 0.5 * r * v * v; // dynamic pressure
-        _total_pressure_node->setDoubleValue(p + q);
+        double v = _velocity_node->getDoubleValue() * KTTOFPS;
+        double q = 0.5 * r * v * v; // dynamic
+        _total_pressure_node->setDoubleValue((p + q) * PSFTOINHG);
     }
 }