]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cxx
Merge branch 'next' of http://git.gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / JSBSim.cxx
index f802c8c2ee4e244beea61a75df961ad89eea54c5..c6f19333645d2ea828249888173fa4b5c32b35d3 100644 (file)
@@ -144,8 +144,6 @@ FGJSBsim::FGJSBsim( double dt )
         }
     }
 
-    resetPropertyState();
-    
     fdmex = new FGFDMExec( (FGPropertyManager*)globals->get_props() );
 
     // Register ground callback.
@@ -214,15 +212,17 @@ FGJSBsim::FGJSBsim( double dt )
 
     // Set initial fuel levels if provided.
     for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
+      double d;
       SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
-      if (node->getChild("level-gal_us", 0, false) != 0) {
-        Propulsion->GetTank(i)->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
-      } else {
-        node->setDoubleValue("level-lbs", Propulsion->GetTank(i)->GetContents());
-        node->setDoubleValue("level-gal_us", Propulsion->GetTank(i)->GetContents() / 6.6);
-      }
-      node->setDoubleValue("capacity-gal_us",
-                           Propulsion->GetTank(i)->GetCapacity() / 6.6);
+      FGTank* tank = Propulsion->GetTank(i);
+
+      d = node->getNode( "density-ppg", true )->getDoubleValue();
+      if( d > 0.0 )
+        tank->SetDensity( d );
+
+      d = node->getNode( "level-lbs", true )->getDoubleValue();
+      if( d > 0.0 )
+        tank->SetContents( d );
     }
     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
 
@@ -424,6 +424,14 @@ void FGJSBsim::init()
 
 /******************************************************************************/
 
+void FGJSBsim::unbind()
+{
+  fdmex->Unbind();
+  FGInterface::unbind();
+}
+
+/******************************************************************************/
+
 // Run an iteration of the EOM (equations of motion)
 
 void FGJSBsim::update( double dt )
@@ -670,8 +678,13 @@ bool FGJSBsim::copy_to_JSBsim()
     for (i = 0; i < Propulsion->GetNumTanks(); i++) {
       SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
       FGTank * tank = Propulsion->GetTank(i);
-      tank->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
-//       tank->SetContents(node->getDoubleValue("level-lbs"));
+      double fuelDensity = node->getDoubleValue("density-ppg");
+
+      if (fuelDensity < 0.1)
+        fuelDensity = 6.0; // Use average fuel value
+
+      tank->SetDensity(fuelDensity);
+      tank->SetContents(node->getDoubleValue("level-lbs"));
     }
 
     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
@@ -909,7 +922,12 @@ bool FGJSBsim::copy_from_JSBsim()
         FGTank* tank = Propulsion->GetTank(i);
         double contents = tank->GetContents();
         double temp = tank->GetTemperature_degC();
-        node->setDoubleValue("level-gal_us", contents/6.6);
+        double fuelDensity = tank->GetDensity();
+
+        if (fuelDensity < 0.1)
+          fuelDensity = 6.0; // Use average fuel value
+
+        node->setDoubleValue("density-ppg" , fuelDensity);
         node->setDoubleValue("level-lbs", contents);
         if (temp != -9999.0) node->setDoubleValue("temperature_degC", temp);
       }
@@ -1415,21 +1433,3 @@ void FGJSBsim::update_external_forces(double t_off)
     fgSetDouble("/fdm/jsbsim/systems/hook/tailhook-pos-deg", fi);
 }
 
-void FGJSBsim::resetPropertyState()
-{
-// this code works-around bug #222:
-// http://code.google.com/p/flightgear-bugs/issues/detail?id=222
-// for whatever reason, having an existing value for the WOW
-// property causes the NaNs. Should that be fixed, this code can die
-  SGPropertyNode* gear = fgGetNode("/fdm/jsbsim/gear", false);
-  if (!gear) {
-    return;
-  }
-  
-  int index = 0;
-  SGPropertyNode* unitNode = NULL;
-  for (; (unitNode = gear->getChild("unit", index)) != NULL; ++index) {
-    unitNode->removeChild("WOW", 0, false);
-  }
-}
-