]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGPropeller.cpp
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGPropeller.cpp
index 36b7e0e930c87269bab1e772246b9154774ec58c..1bd9118ef6de4cfe8401b8e1d437f923c182d4aa 100644 (file)
@@ -36,6 +36,7 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGPropeller.h"
+#include "FGFCS.h"
 
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_PROPELLER;
@@ -44,17 +45,21 @@ static const char *IdHdr = ID_PROPELLER;
 CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+// This class currently makes certain assumptions when calculating torque and 
+// p-factor. That is, that the axis of rotation is the X axis of the aircraft -
+// not just the X-axis of the engine/propeller. This may or may not work for a 
+// helicopter.
 
 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
 {
   string token;
   int rows, cols;
 
-  MaxPitch = MinPitch = 0.0;
+  MaxPitch = MinPitch = P_Factor = Sense = Pitch = 0.0;
 
   Name = Prop_cfg->GetValue("NAME");
   Prop_cfg->GetNextConfigLine();
-  while (Prop_cfg->GetValue() != "/FG_PROPELLER") {
+  while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
     *Prop_cfg >> token;
     if (token == "IXX") {
       *Prop_cfg >> Ixx;
@@ -67,20 +72,19 @@ FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(e
       *Prop_cfg >> MinPitch;
     } else if (token == "MAXPITCH") {
       *Prop_cfg >> MaxPitch;
-    } else if (token == "EFFICIENCY") {
-      *Prop_cfg >> rows >> cols;
-      if (cols == 1) Efficiency = new FGTable(rows);
-           else           Efficiency = new FGTable(rows, cols);
-      *Efficiency << *Prop_cfg;
+    } else if (token == "MINRPM") {
+      *Prop_cfg >> MinRPM;
+    } else if (token == "MAXRPM") {
+      *Prop_cfg >> MaxRPM;
     } else if (token == "C_THRUST") {
       *Prop_cfg >> rows >> cols;
       if (cols == 1) cThrust = new FGTable(rows);
-           else           cThrust = new FGTable(rows, cols);
+      else           cThrust = new FGTable(rows, cols);
       *cThrust << *Prop_cfg;
     } else if (token == "C_POWER") {
       *Prop_cfg >> rows >> cols;
       if (cols == 1) cPower = new FGTable(rows);
-           else           cPower = new FGTable(rows, cols);
+      else           cPower = new FGTable(rows, cols);
       *cPower << *Prop_cfg;
     } else if (token == "EOF") {
       cerr << "      End of file reached" <<  endl;
@@ -90,35 +94,20 @@ FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(e
     }
   }
 
-  if (debug_lvl > 0) {
-    cout << "\n    Propeller Name: " << Name << endl;
-    cout << "      IXX = " << Ixx << endl;
-    cout << "      Diameter = " << Diameter << " ft." << endl;
-    cout << "      Number of Blades  = " << numBlades << endl;
-    cout << "      Minimum Pitch  = " << MinPitch << endl;
-    cout << "      Maximum Pitch  = " << MaxPitch << endl;
-    cout << "      Efficiency: " <<  endl;
-    Efficiency->Print();
-    cout << "      Thrust Coefficient: " <<  endl;
-    cThrust->Print();
-    cout << "      Power Coefficient: " <<  endl;
-    cPower->Print();
-  }
-
   Type = ttPropeller;
   RPM = 0;
+  vTorque.InitMatrix();
 
-  if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
+  Debug(0);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 FGPropeller::~FGPropeller()
 {
-  if (Efficiency) delete Efficiency;
   if (cThrust)    delete cThrust;
   if (cPower)     delete cPower;
-  if (debug_lvl & 2) cout << "Destroyed:    FGPropeller" << endl;
+  Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -135,15 +124,16 @@ FGPropeller::~FGPropeller()
 //
 // Because RPM could be zero, we need to be creative about what RPM is stated as.
 
-float FGPropeller::Calculate(float PowerAvailable)
+double FGPropeller::Calculate(double PowerAvailable)
 {
-  float J, C_Thrust, omega;
-  float Vel = (fdmex->GetTranslation()->GetvAero())(1);
-  float rho = fdmex->GetAtmosphere()->GetDensity();
-  float RPS = RPM/60.0;
+  double J, C_Thrust, omega;
+  double Vel = fdmex->GetTranslation()->GetAeroUVW(eU);
+  double rho = fdmex->GetAtmosphere()->GetDensity();
+  double RPS = RPM/60.0;
+  double alpha, beta;
 
   if (RPM > 0.10) {
-    J = Vel / (Diameter * RPM / 60.0);
+    J = Vel / (Diameter * RPS);
   } else {
     J = 0.0;
   }
@@ -154,43 +144,153 @@ float FGPropeller::Calculate(float PowerAvailable)
     C_Thrust = cThrust->GetValue(J, Pitch);
   }
 
+  if (P_Factor > 0.0001) {
+    alpha = fdmex->GetTranslation()->Getalpha();
+    beta  = fdmex->GetTranslation()->Getbeta();
+    SetActingLocationY( GetLocationY() + P_Factor*alpha*Sense);
+    SetActingLocationZ( GetLocationZ() + P_Factor*beta*Sense);
+  } else if (P_Factor < 0.000) {
+    cerr << "P-Factor value in config file must be greater than zero" << endl;
+  }
+
   Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
-  vFn(1) = Thrust;
   omega = RPS*2.0*M_PI;
 
+  // Check for windmilling.
+  double radius = Diameter * 0.375; // 75% of radius
+  double windmill_cutoff = tan(Pitch * 1.745329E-2) * omega * radius;
+  if (Vel > windmill_cutoff)
+    Thrust = -Thrust;
+
+  vFn(1) = Thrust;
+
+  // The Ixx value and rotation speed given below are for rotation about the
+  // natural axis of the engine. The transform takes place in the base class
+  // FGForce::GetBodyForces() function.
+
+  vH(eX) = Ixx*omega*Sense;
+  vH(eY) = 0.0;
+  vH(eZ) = 0.0;
+
   if (omega <= 5) omega = 1.0;
 
-  Torque = PowerAvailable / omega;
-  RPM = (RPS + ((Torque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
+  ExcessTorque = PowerAvailable / omega;
+  RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
+
+                               // The friction from the engine should
+                               // stop it somewhere; I chose an
+                               // arbitrary point.
+  if (RPM < 5.0)
+    RPM = 0;
+
+  vMn = fdmex->GetRotation()->GetPQR()*vH + vTorque*Sense;
+
   return Thrust; // return thrust in pounds
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGPropeller::GetPowerRequired(void)
+double FGPropeller::GetPowerRequired(void)
 {
   if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
 
-  float cPReq, RPS = RPM / 60.0;
+  double cPReq, RPS = RPM / 60.0;
 
-  float J = (fdmex->GetTranslation()->GetvAero())(1) / (Diameter * RPS);
-  float rho = fdmex->GetAtmosphere()->GetDensity();
+  double J = fdmex->GetTranslation()->GetAeroUVW(eU) / (Diameter * RPS);
+  double rho = fdmex->GetAtmosphere()->GetDensity();
 
   if (MaxPitch == MinPitch) { // Fixed pitch prop
+    Pitch = MinPitch;
     cPReq = cPower->GetValue(J);
   } else {                    // Variable pitch prop
+    double advance = fdmex->GetFCS()->GetPropAdvance(ThrusterNumber);
+
+    if (MaxRPM != MinRPM) {   // fixed-speed prop
+      double rpmReq = MinRPM + (MaxRPM - MinRPM) * advance;
+      double dRPM = rpmReq - RPM;
+
+      Pitch -= dRPM / 10;
+
+      if (Pitch < MinPitch)       Pitch = MinPitch;
+      else if (Pitch > MaxPitch)  Pitch = MaxPitch;
+
+    } else {
+      Pitch = MaxPitch - (MaxPitch - MinPitch) * advance;
+    }
     cPReq = cPower->GetValue(J, Pitch);
   }
 
   PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
                                                        *Diameter*rho;
+  vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
+
   return PowerRequired;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGPropeller::Debug(void)
+FGColumnVector3 FGPropeller::GetPFactor()
+{
+  double px=0.0, py, pz;
+
+  py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
+  pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
+
+  return FGColumnVector3(px, py, pz);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//    The bitmasked value choices are as follows:
+//    unset: In this case (the default) JSBSim would only print
+//       out the normally expected messages, essentially echoing
+//       the config files as they are read. If the environment
+//       variable is not set, debug_lvl is set to 1 internally
+//    0: This requests JSBSim not to output any messages
+//       whatsoever.
+//    1: This value explicity requests the normal JSBSim
+//       startup messages
+//    2: This value asks for a message to be printed out when
+//       a class is instantiated
+//    4: When this value is set, a message is displayed when a
+//       FGModel object executes its Run() method
+//    8: When this value is set, various runtime state variables
+//       are printed out periodically
+//    16: When set various parameters are sanity checked and
+//       a message is printed out when they go out of bounds
+
+void FGPropeller::Debug(int from)
 {
-    //TODO: Add your source code here
+  if (debug_lvl <= 0) return;
+
+  if (debug_lvl & 1) { // Standard console startup message output
+    if (from == 0) { // Constructor
+      cout << "\n    Propeller Name: " << Name << endl;
+      cout << "      IXX = " << Ixx << endl;
+      cout << "      Diameter = " << Diameter << " ft." << endl;
+      cout << "      Number of Blades  = " << numBlades << endl;
+      cout << "      Minimum Pitch  = " << MinPitch << endl;
+      cout << "      Maximum Pitch  = " << MaxPitch << endl;
+      cout << "      Thrust Coefficient: " <<  endl;
+      cThrust->Print();
+      cout << "      Power Coefficient: " <<  endl;
+      cPower->Print();
+    }
+  }
+  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
+    if (from == 0) cout << "Instantiated: FGPropeller" << endl;
+    if (from == 1) cout << "Destroyed:    FGPropeller" << endl;
+  }
+  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
+  }
+  if (debug_lvl & 8 ) { // Runtime state variables
+  }
+  if (debug_lvl & 16) { // Sanity checking
+  }
+  if (debug_lvl & 64) {
+    if (from == 0) { // Constructor
+      cout << IdSrc << endl;
+      cout << IdHdr << endl;
+    }
+  }
 }