]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/propulsion/FGPropeller.cpp
Andreas Gaeb: fix #222 (JSBSIm reset problems)
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGPropeller.cpp
index 55ea67ffe1f1726abc3dbe3ae5d94f30b1ab95cc..f83f961b8e7aea224b62c5dab8fb1e1cd62ae11e 100644 (file)
@@ -5,7 +5,7 @@
  Date started: 08/24/00
  Purpose:      Encapsulates the propeller object
 
- ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 2000  Jon S. Berndt (jon@jsbsim.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -35,16 +35,20 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#include <iostream>
 #include <sstream>
 
 #include "FGPropeller.h"
-#include <models/FGPropagate.h>
-#include <models/FGAtmosphere.h>
-#include <models/FGAuxiliary.h>
+#include "models/FGPropagate.h"
+#include "models/FGAtmosphere.h"
+#include "models/FGAuxiliary.h"
+#include "input_output/FGXMLElement.h"
+
+using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.32 2010/10/21 03:27:40 jberndt Exp $";
 static const char *IdHdr = ID_PROPELLER;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -72,6 +76,9 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
   Reverse_coef = 0.0;
   GearRatio = 1.0;
   CtFactor = CpFactor = 1.0;
+  ConstantSpeed = 0;
+  cThrust = cPower = CtMach = CpMach = 0;
+  Vinduced = 0.0;
 
   if (prop_element->FindElement("ixx"))
     Ixx = prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2");
@@ -87,19 +94,31 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
     MaxPitch = prop_element->FindElementValueAsNumber("maxpitch");
   if (prop_element->FindElement("minrpm"))
     MinRPM = prop_element->FindElementValueAsNumber("minrpm");
-  if (prop_element->FindElement("maxrpm"))
+  if (prop_element->FindElement("maxrpm")) {
     MaxRPM = prop_element->FindElementValueAsNumber("maxrpm");
+    ConstantSpeed = 1;
+    }
+  if (prop_element->FindElement("constspeed"))
+    ConstantSpeed = (int)prop_element->FindElementValueAsNumber("constspeed");
   if (prop_element->FindElement("reversepitch"))
     ReversePitch = prop_element->FindElementValueAsNumber("reversepitch");
   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 {
-      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);
     }
   }
 
@@ -125,16 +144,26 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
   vTorque.InitMatrix();
   D4 = Diameter*Diameter*Diameter*Diameter;
   D5 = D4*Diameter;
-
-  char property_name[80];
-  snprintf(property_name, 80, "propulsion/engine[%d]/advance-ratio", EngineNum);
-  PropertyManager->Tie( property_name, &J );
-  snprintf(property_name, 80, "propulsion/engine[%d]/blade-angle", EngineNum);
-  PropertyManager->Tie( property_name, &Pitch );
-  snprintf(property_name, 80, "propulsion/engine[%d]/thrust-coefficient", EngineNum);
-  PropertyManager->Tie( property_name, this, &FGPropeller::GetThrustCoefficient );
-  snprintf(property_name, 80, "propulsion/engine[%d]/propeller-rpm", EngineNum);
-  PropertyManager->Tie( property_name, this, &FGPropeller::GetRPM );
+  Pitch = MinPitch;
+
+  string property_name, base_property_name;
+  base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
+  property_name = base_property_name + "/advance-ratio";
+  PropertyManager->Tie( property_name.c_str(), &J );
+  property_name = base_property_name + "/blade-angle";
+  PropertyManager->Tie( property_name.c_str(), &Pitch );
+  property_name = base_property_name + "/thrust-coefficient";
+  PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetThrustCoefficient );
+  property_name = base_property_name + "/propeller-rpm";
+  PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetRPM );
+  property_name = base_property_name + "/helical-tip-Mach";
+  PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetHelicalTipMach );
+  property_name = base_property_name + "/constant-speed-mode";
+  PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetConstantSpeed,
+                      &FGPropeller::SetConstantSpeed );
+  property_name = base_property_name + "/prop-induced-velocity_fps";
+  PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetInducedVelocity,
+                      &FGPropeller::SetInducedVelocity );
 
   Debug(0);
 }
@@ -145,6 +174,8 @@ FGPropeller::~FGPropeller()
 {
   delete cThrust;
   delete cPower;
+  delete CtMach;
+  delete CpMach;
 
   Debug(1);
 }
@@ -171,13 +202,27 @@ double FGPropeller::Calculate(double PowerAvailable)
   double rho = fdmex->GetAtmosphere()->GetDensity();
   double RPS = RPM/60.0;
 
-  if (RPS > 0.00) J = Vel / (Diameter * RPS); // Calculate J normally
-  else            J = 1000.0;                 // Set J to a high number
+  // Calculate helical tip Mach
+  double Area = 0.25*Diameter*Diameter*M_PI;
+  double Vtip = RPS * Diameter * M_PI;
+  HelicalTipMach = sqrt(Vtip*Vtip + Vel*Vel) / 
+                   fdmex->GetAtmosphere()->GetSoundSpeed(); 
 
-  if (MaxPitch == MinPitch)  ThrustCoeff = cThrust->GetValue(J);
-  else                       ThrustCoeff = cThrust->GetValue(J, Pitch);
+  if (RPS > 0.0) J = Vel / (Diameter * RPS); // Calculate J normally
+  else           J = Vel / Diameter;      
+
+  if (MaxPitch == MinPitch) {    // Fixed pitch prop
+         ThrustCoeff = cThrust->GetValue(J);
+  } else {                       // Variable pitch prop
+         ThrustCoeff = cThrust->GetValue(J, Pitch);
+  }
+  // Apply optional scaling factor to Ct (default value = 1)
   ThrustCoeff *= CtFactor;
 
+  // Apply optional Mach effects from CT_MACH table
+  if (CtMach) ThrustCoeff *= CtMach->GetValue(HelicalTipMach);
+
   if (P_Factor > 0.0001) {
     alpha = fdmex->GetAuxiliary()->Getalpha();
     beta  = fdmex->GetAuxiliary()->Getbeta();
@@ -186,6 +231,11 @@ double FGPropeller::Calculate(double PowerAvailable)
   }
 
   Thrust = ThrustCoeff*RPS*RPS*D4*rho;
+
+  // From B. W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics"
+  // first edition, eqn. 6.15 (propeller analysis chapter).
+  Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area)));
+
   omega = RPS*2.0*M_PI;
 
   vFn(1) = Thrust;
@@ -198,14 +248,16 @@ double FGPropeller::Calculate(double PowerAvailable)
   vH(eY) = 0.0;
   vH(eZ) = 0.0;
 
-  if (omega > 0.0) ExcessTorque = GearRatio * PowerAvailable / omega;
-  else             ExcessTorque = GearRatio * PowerAvailable / 1.0;
+  if (omega > 0.0) ExcessTorque = PowerAvailable / omega;
+  else             ExcessTorque = PowerAvailable / 1.0;
 
   RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
 
-  if (RPM < 1.0) RPM = 0; // Engine friction stops rotation arbitrarily at 1 RPM.
+  if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
 
-  vMn = fdmex->GetPropagate()->GetPQR()*vH + vTorque;
+  // Transform Torque and momentum first, as PQR is used in this
+  // equation and cannot be transformed itself.
+  vMn = fdmex->GetPropagate()->GetPQR()*(Transform()*vH) + Transform()*vTorque;
 
   return Thrust; // return thrust in pounds
 }
@@ -216,19 +268,23 @@ double FGPropeller::GetPowerRequired(void)
 {
   double cPReq, J;
   double rho = fdmex->GetAtmosphere()->GetDensity();
+  double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
   double RPS = RPM / 60.0;
 
-  if (RPS != 0) J = fdmex->GetAuxiliary()->GetAeroUVW(eU) / (Diameter * RPS);
-  else          J = 1000.0; // Set J to a high number
+  if (RPS != 0.0) J = Vel / (Diameter * RPS);
+  else            J = Vel / Diameter; 
 
-  if (MaxPitch == MinPitch) { // Fixed pitch prop
-    Pitch = MinPitch;
+  if (MaxPitch == MinPitch) {   // Fixed pitch prop
     cPReq = cPower->GetValue(J);
+
   } else {                      // Variable pitch prop
 
-    if (MaxRPM != MinRPM) {   // fixed-speed prop
+    if (ConstantSpeed != 0) {   // Constant Speed Mode
 
       // do normal calculation when propeller is neither feathered nor reversed
+      // Note:  This method of feathering and reversing was added to support the
+      //        turboprop model.  It's left here for backward compatablity, but
+      //        now feathering and reversing should be done in Manual Pitch Mode.
       if (!Feathered) {
         if (!Reversed) {
 
@@ -236,8 +292,7 @@ double FGPropeller::GetPowerRequired(void)
           double dRPM = rpmReq - RPM;
           // The pitch of a variable propeller cannot be changed when the RPMs are
           // too low - the oil pump does not work.
-          if (RPM > 200) Pitch -= dRPM / 10;
-
+          if (RPM > 200) Pitch -= dRPM * deltaT;
           if (Pitch < MinPitch)       Pitch = MinPitch;
           else if (Pitch > MaxPitch)  Pitch = MaxPitch;
 
@@ -261,19 +316,29 @@ double FGPropeller::GetPowerRequired(void)
         Pitch += (MaxPitch - Pitch) / 300; // just a guess (about 5 sec to fully feathered)
       }
 
-    } else { // Variable Speed Prop
-      Pitch = MinPitch + (MaxPitch - MinPitch) * Advance;
+    } else { // Manual Pitch Mode, pitch is controlled externally
+
     }
+  
     cPReq = cPower->GetValue(J, Pitch);
   }
+
+  // Apply optional scaling factor to Cp (default value = 1)
   cPReq *= CpFactor;
 
-  if (RPS > 0) {
+  // Apply optional Mach effects from CP_MACH table
+  if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);
+
+  if (RPS > 0.1) {
     PowerRequired = cPReq*RPS*RPS*RPS*D5*rho;
     vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
   } else {
-    PowerRequired = 0.0;
-    vTorque(eX) = 0.0;
+     // For a stationary prop we have to estimate torque first.
+     double CL = (90.0 - Pitch) / 20.0;
+     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 = fabs(vTorque(eX))*0.2*M_PI;
   }
 
   return PowerRequired;