2011/1/29 Ron Jensen <[email protected]>:
>
> +      double fuelDensity = Propulsion->GetTank(i)->GetDensity();
>
> ( ... )
>
> + Propulsion->GetTank(i)->GetContents() / fuelDensity);
>
>
> Should we guard against GetDensity() returning 0?

Correct.

Please find an updated version of the patch that uses the standard
fuel density (6.0 lbs/gal) if the density is too low or negative ( <
0.1). This is assuming that if the density goes below that threshold
it can only be an error. Another policy would be to clamp the value to
0.1.

Suggestions ?

Also, unlike the existing code base, this patch is assuming that the
fuel weight is the reference and that the fuel volume should be
adjusted to the fuel density modifications. When the fuel temperature
drops, its volume decreases but its weight is not changing. I would
think that this does not break backward compatibility : the
fuel/payload menu is checking the fuel volume against the tank
capacity and is reacting well to density modifications in the property
tree. But I would like to have other opinions.

This version 3 of the patches supersedes the other two.

Cheers,

Bertrand.
diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx
index a9e9be7..2e75e44 100644
--- a/src/FDM/JSBSim/JSBSim.cxx
+++ b/src/FDM/JSBSim/JSBSim.cxx
@@ -213,14 +213,28 @@ FGJSBsim::FGJSBsim( double dt )
     // Set initial fuel levels if provided.
     for (unsigned int i = 0; i < Propulsion->GetNumTanks(); i++) {
       SGPropertyNode * node = fgGetNode("/consumables/fuel/tank", i, true);
+      FGTank* tank = Propulsion->GetTank(i);
+      double fuelDensity;
+
+      if (node->getChild("density-ppg", 0, false) != 0) {
+        fuelDensity = node->getDoubleValue("density-ppg");
+        tank->SetDensity(fuelDensity);
+      }
+      else {
+        fuelDensity = tank->GetDensity();
+        node->setDoubleValue("density-ppg", fuelDensity);
+      }
+
+      if (fuelDensity < 0.1)
+        fuelDensity = 6.0; // Use average fuel value
+
       if (node->getChild("level-gal_us", 0, false) != 0) {
-        Propulsion->GetTank(i)->SetContents(node->getDoubleValue("level-gal_us") * 6.6);
+        tank->SetContents(node->getDoubleValue("level-gal_us") * fuelDensity);
       } else {
-        node->setDoubleValue("level-lbs", Propulsion->GetTank(i)->GetContents());
-        node->setDoubleValue("level-gal_us", Propulsion->GetTank(i)->GetContents() / 6.6);
+        node->setDoubleValue("level-lbs", tank->GetContents());
+        node->setDoubleValue("level-gal_us", tank->GetContents() / fuelDensity);
       }
-      node->setDoubleValue("capacity-gal_us",
-                           Propulsion->GetTank(i)->GetCapacity() / 6.6);
+      node->setDoubleValue("capacity-gal_us", tank->GetCapacity() / fuelDensity);
     }
     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
 
@@ -695,8 +709,14 @@ 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-gal_us") * fuelDensity);
+      tank->SetContents(node->getDoubleValue("level-lbs"));
     }
 
     Propulsion->SetFuelFreeze((fgGetNode("/sim/freeze/fuel",true))->getBoolValue());
@@ -934,7 +954,13 @@ 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-gal_us", contents/fuelDensity);
         node->setDoubleValue("level-lbs", contents);
         if (temp != -9999.0) node->setDoubleValue("temperature_degC", temp);
       }
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to