]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/propulsion/FGPropeller.cpp
Merge branch 'next' into durk-atc
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGPropeller.cpp
index 8204bb9d21cd88bd127071fee4da1e5eb43a419b..d5ed3813d3bc29b35198e6bea566b99b91be81f1 100644 (file)
@@ -48,7 +48,7 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.30 2010/05/02 15:10:07 jberndt Exp $";
+static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.33 2011/03/10 01:35:25 dpculp Exp $";
 static const char *IdHdr = ID_PROPELLER;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -105,16 +105,20 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
   for (int i=0; i<2; i++) {
     table_element = prop_element->FindNextElement("table");
     name = table_element->GetAttributeValue("name");
-    if (name == "C_THRUST") {
-      cThrust = new FGTable(PropertyManager, table_element);
-    } else if (name == "C_POWER") {
-      cPower = new FGTable(PropertyManager, table_element);
-    } else if (name == "CT_MACH") {
-      CtMach = new FGTable(PropertyManager, table_element);
-    } else if (name == "CP_MACH") {
-      CpMach = new FGTable(PropertyManager, table_element);
-    } else {
-      cerr << "Unknown table type: " << name << " in propeller definition." << endl;
+    try {
+      if (name == "C_THRUST") {
+        cThrust = new FGTable(PropertyManager, table_element);
+      } else if (name == "C_POWER") {
+        cPower = new FGTable(PropertyManager, table_element);
+      } else if (name == "CT_MACH") {
+        CtMach = new FGTable(PropertyManager, table_element);
+      } else if (name == "CP_MACH") {
+        CpMach = new FGTable(PropertyManager, table_element);
+      } else {
+        cerr << "Unknown table type: " << name << " in propeller definition." << endl;
+      }
+    } catch (std::string str) {
+      throw("Error loading propeller table:" + name + ". " + str);
     }
   }
 
@@ -181,23 +185,22 @@ FGPropeller::~FGPropeller()
 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
 // We need the velocity with respect to the wind.
 //
-// Note that PowerAvailable is the excess power available after the drag of the
-// propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
-// indicating that the propeller will not accelerate or decelerate.
 // Remembering that Torque * omega = Power, we can derive the torque on the
 // propeller and its acceleration to give a new RPM. The current RPM will be
 // used to calculate thrust.
 //
 // Because RPM could be zero, we need to be creative about what RPM is stated as.
 
-double FGPropeller::Calculate(double PowerAvailable)
+double FGPropeller::Calculate(double EnginePower)
 {
-  double omega, alpha, beta;
+  double omega, alpha, beta, PowerAvailable;
 
   double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
   double rho = fdmex->GetAtmosphere()->GetDensity();
   double RPS = RPM/60.0;
 
+  PowerAvailable = EnginePower - GetPowerRequired();
+
   // Calculate helical tip Mach
   double Area = 0.25*Diameter*Diameter*M_PI;
   double Vtip = RPS * Diameter * M_PI;
@@ -334,7 +337,7 @@ double FGPropeller::GetPowerRequired(void)
      if (CL > 1.5) CL = 1.5;
      double BladeArea = Diameter * Diameter / 32.0 * numBlades;
      vTorque(eX) = -Sense*BladeArea*Diameter*Vel*Vel*rho*0.19*CL;
-     PowerRequired = vTorque(eX)*0.2*M_PI;
+     PowerRequired = fabs(vTorque(eX))*0.2*M_PI;
   }
 
   return PowerRequired;