]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGSimTurbine.cpp
Curt Olson:
[flightgear.git] / src / FDM / JSBSim / FGSimTurbine.cpp
index 69fca04a9b8a709c079bbbdb307bcbef5f980fff..3558297d4b54f1b0e4cbd33ade8a58888cfe3678 100644 (file)
@@ -5,7 +5,7 @@
  Date started: 03/11/2003
  Purpose:      This module models a turbine engine.
 
- ------------- Copyright (C) 2003  David Culp (davidculp2@attbi.com) -----------
+ ------------- Copyright (C) 2003  David Culp (davidculp2@comcast.net) ---------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
@@ -33,6 +33,7 @@ on parameters given in the engine config file for this class
 HISTORY
 --------------------------------------------------------------------------------
 03/11/2003  DPC  Created
+09/08/2003  DPC  Changed Calculate() and added engine phases 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
@@ -54,7 +55,7 @@ CLASS IMPLEMENTATION
 FGSimTurbine::FGSimTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
 {
   SetDefaults();
-  FGEngine::Type=etSimTurbine;
+
   Load(cfg);
   Debug(0);
 }
@@ -67,101 +68,243 @@ FGSimTurbine::~FGSimTurbine()
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// The main purpose of Calculate() is to determine what phase the engine should
+// be in, then call the corresponding function. 
 
 double FGSimTurbine::Calculate(double dummy)
 {
-  double idlethrust, milthrust, thrust;
-  double TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
+  TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
   dt = State->Getdt() * Propulsion->GetRate();
-
-  // calculate virtual throttle position (actual +/- lag) based on
-  // FCS Throttle value (except when trimming)
-  if (dt > 0.0) {
-    Running = !Starved;
-    ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
-    if ( ThrottleCmd > throttle ) {
-      throttle += (dt * delay);
-      if (throttle > ThrottleCmd ) throttle = ThrottleCmd;
+  ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
+
+  // When trimming is finished check if user wants engine OFF or RUNNING
+  if ((phase == tpTrim) && (dt > 0)) {
+    if (Running && !Starved) {
+      phase = tpRun;
+      N2 = IdleN2;
+      N1 = IdleN1;
+      OilTemp_degK = 366.0;  
+      Cutoff = false;
       }
     else {
-      throttle -= (dt * delay * 3.0);
-      if (throttle < ThrottleCmd ) throttle = ThrottleCmd;
+      phase = tpOff;
+      Cutoff = true;
+      EGT_degC = TAT; 
       }
     }
-  else {
-    Starved = false;
-    throttle = ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
-    }
-    
-  idlethrust = MaxMilThrust * ThrustTables[0]->TotalValue();
-  milthrust = MaxMilThrust * ThrustTables[1]->TotalValue();
-
-  if (Running) {
-    thrust = milthrust * throttle * throttle;
-    if (thrust < idlethrust) thrust = idlethrust;
-    FuelFlow_pph = thrust * TSFC;
-    thrust = thrust * (1.0 - BleedDemand);
-    IdleFF = pow(MaxMilThrust, 0.2) * 107.0;
+  
+  if (!Running && Cutoff && Starter) {
+     if (phase == tpOff) phase = tpSpinUp;
+     }
+  if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
+  if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
+  if (dt == 0) phase = tpTrim;
+  if (Starved) phase = tpOff;
+  if (Stalled) phase = tpStall;
+  if (Seized) phase = tpSeize;
+  
+  switch (phase) {
+    case tpOff:    Thrust = Off(); break;
+    case tpRun:    Thrust = Run(); break;
+    case tpSpinUp: Thrust = SpinUp(); break;
+    case tpStart:  Thrust = Start(); break;
+    case tpStall:  Thrust = Stall(); break;
+    case tpSeize:  Thrust = Seize(); break;
+    case tpTrim:   Thrust = Trim(); break;
+    default: Thrust = Off();
+  }   
+
+  return Thrust;  
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Off(void)
+{
+  double qbar = Translation->Getqbar();
+  Running = false;
+  FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
+  N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
+  N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
+  EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
+  OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);  
+  OilPressure_psi = N2 * 0.62;
+  NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
+  EPR = Seek(&EPR, 1.0, 0.2, 0.2);
+  return 0.0; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Run(void)
+{
+  double idlethrust, milthrust, thrust;
+  double N2norm;   // 0.0 = idle N2, 1.0 = maximum N2
+  idlethrust = MilThrust * ThrustTables[0]->TotalValue();
+  milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
+
+  Running = true;
+  Starter = false;
+  N2 = Seek(&N2, IdleN2 + ThrottleCmd * N2_factor, delay, delay * 3.0);
+  N1 = Seek(&N1, IdleN1 + ThrottleCmd * N1_factor, delay, delay * 2.4);
+  N2norm = (N2 - IdleN2) / N2_factor;
+  thrust = idlethrust + (milthrust * N2norm * N2norm); 
+  thrust = thrust * (1.0 - BleedDemand);
+  EGT_degC = TAT + 363.1 + ThrottleCmd * 357.1;
+  OilPressure_psi = N2 * 0.62;
+  OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
+  EPR = 1.0 + thrust/MilThrust;
+
+  if (!Augmentation) {
+    FuelFlow_pph = Seek(&FuelFlow_pph, thrust * TSFC, 1000.0, 100000);
     if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
-    N1 = IdleN1 + throttle * N1_factor;
-    N2 = IdleN2 + throttle * N2_factor;
-    EGT_degC = TAT + 363.1 + ThrottleCmd * 357.1;
-    OilPressure_psi = N2 * 0.62;
-    OilTemp_degK += dt * 1.2;
-    if (OilTemp_degK > 366.0) OilTemp_degK = 366.0;
-    EPR = 1.0 + thrust/MaxMilThrust;
-    NozzlePosition = 1.0 - throttle;
-    if (Reversed) thrust = thrust * -0.2;
-    }
-  else {
-    thrust = 0.0;
-    FuelFlow_pph = 0.000001;
-    N1 -= (dt * 3.0);
-    if (N1 < (Translation->Getqbar()/10.0)) N1 = Translation->Getqbar()/10.0;
-    N2 -= (dt * 3.5);
-    if (N2 < (Translation->Getqbar()/15.0)) N2 = Translation->Getqbar()/15.0;
-    EGT_degC -= (dt * 11.7);
-    if (EGT_degC < TAT) EGT_degC = TAT;
-    OilPressure_psi = N2 * 0.62;
-    OilTemp_degK -= (dt * 0.2);
-    if (OilTemp_degK < (TAT + 273.0)) OilTemp_degK = (TAT + 273.0);
-    EPR = 1.0;
-    }
+    NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
+  }
 
   if (AugMethod == 1) {
-    if (throttle > 0.99) {Augmentation = true;} 
-      else {Augmentation = false;}
-    }
+    if ((ThrottleCmd > 0.99) && (N2 > 97.0)) {Augmentation = true;} 
+    else {Augmentation = false;}
+  }
 
   if ((Augmented == 1) && Augmentation) {
-    thrust = thrust * ThrustTables[2]->TotalValue();
-    FuelFlow_pph = thrust * ATSFC;
-    NozzlePosition = 1.0;
-    }
+    thrust = MaxThrust * ThrustTables[2]->TotalValue();
+    FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
+    NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
+  }
 
   if ((Injected == 1) && Injection)
-    thrust = thrust * ThrustTables[3]->TotalValue();  
-  
+    thrust = thrust * ThrustTables[3]->TotalValue(); 
+
   ConsumeFuel();
-  
-  return Thrust = thrust;
-  
+  if (Cutoff) phase = tpOff;
+  if (Starved) phase = tpOff;
+
+  return thrust;
 }
         
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+double FGSimTurbine::SpinUp(void)
+{
+  Running = false;
+  FuelFlow_pph = 0.0;
+  N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
+  N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
+  EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
+  OilPressure_psi = N2 * 0.62;
+  OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
+  EPR = 1.0;
+  NozzlePosition = 1.0;
+
+  return 0.0;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Start(void)
+{
+  if ((N2 > 15.0) && !Starved) {       // minimum 15% N2 needed for start
+    Cranking = true;                   // provided for sound effects signal
+    if (N2 < IdleN2) {
+      N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
+      N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
+      EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
+      FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
+      OilPressure_psi = N2 * 0.62;
+      }
+    else {
+      phase = tpRun;
+      Running = true;
+      Starter = false;
+      Cranking = false;
+      } 
+    }
+  else {                 // no start if N2 < 15%
+    phase = tpOff;
+    Starter = false;
+    }
+
+  return 0.0; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Stall(void)
+{
+  double qbar = Translation->Getqbar();
+  EGT_degC = TAT + 903.14;
+  FuelFlow_pph = IdleFF;
+  N1 = Seek(&N1, qbar/10.0, 0, N1/10.0); 
+  N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
+  if (ThrottleCmd == 0) phase = tpRun;        // clear the stall with throttle
+
+  return 0.0; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Seize(void)
+{
+    double qbar = Translation->Getqbar();
+    N2 = 0.0;
+    N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
+    FuelFlow_pph = IdleFF;
+    OilPressure_psi = 0.0;
+    OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
+    Running = false;
+    return 0.0; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Trim(void)
+{
+    double idlethrust, milthrust, thrust;
+    idlethrust = MilThrust * ThrustTables[0]->TotalValue();
+    milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
+    thrust = idlethrust + (milthrust * ThrottleCmd * ThrottleCmd);
+    return thrust; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 double FGSimTurbine::CalcFuelNeed(void)
 {
   return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::GetPowerAvailable(void) {
+  if( ThrottleCmd <= 0.77 )
+    return 64.94*ThrottleCmd;
+  else
+    return 217.38*ThrottleCmd - 117.38;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGSimTurbine::Seek(double *var, double target, double accel, double decel) {
+  double v = *var;
+  if (v > target) {
+    v -= dt * decel;
+    if (v < target) v = target;
+  } else if (v < target) {
+    v += dt * accel;
+    if (v > target) v = target;
+  }
+  return v;
+}
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 void FGSimTurbine::SetDefaults(void)
 {
-  Name = "None_Defined";
-  MaxMilThrust = 10000.0;
+  Name = "Not defined";
+  Type = etSimTurbine;
+  MilThrust = 10000.0;
+  MaxThrust = 10000.0;
   BypassRatio = 0.0;
   TSFC = 0.8;
   ATSFC = 1.7;
@@ -173,48 +316,65 @@ void FGSimTurbine::SetDefaults(void)
   AugMethod = 0;
   Injected = 0;
   BleedDemand = 0.0;
-  throttle = 0.0;
+  ThrottleCmd = 0.0;
   InletPosition = 1.0;
   NozzlePosition = 1.0;
   Augmentation = false;
   Injection = false;
   Reversed = false;
+  Cutoff = true;
+  phase = tpOff;
+  Stalled = false;
+  Seized = false;
+  Overtemp = false;
+  Fire = false;
+  EGT_degC = 0.0;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 bool FGSimTurbine::Load(FGConfigFile *Eng_cfg)
 {
-  int i;
   string token;
+
   Name = Eng_cfg->GetValue("NAME");
-  cout << Name << endl;
   Eng_cfg->GetNextConfigLine();
-  *Eng_cfg >> token >> MaxMilThrust;
-  *Eng_cfg >> token >> BypassRatio;
-  *Eng_cfg >> token >> TSFC;
-  *Eng_cfg >> token >> ATSFC;
-  *Eng_cfg >> token >> IdleN1;
-  *Eng_cfg >> token >> IdleN2;
-  *Eng_cfg >> token >> MaxN1;
-  *Eng_cfg >> token >> MaxN2;
-  *Eng_cfg >> token >> Augmented;
-  *Eng_cfg >> token >> AugMethod;
-  *Eng_cfg >> token >> Injected;
-  i=0;
-  while( Eng_cfg->GetValue() != string("/FG_SIMTURBINE") && i < 10){
-    ThrustTables.push_back( new FGCoefficient(FDMExec) );
-    ThrustTables.back()->Load(Eng_cfg);
-    i++;
+  int counter=0;
+
+  while (Eng_cfg->GetValue() != string("/FG_SIMTURBINE")) {
+    *Eng_cfg >> token;
+
+    if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
+
+    if      (token == "MILTHRUST") *Eng_cfg >> MilThrust;
+    else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
+    else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
+    else if (token == "TSFC") *Eng_cfg >> TSFC;
+    else if (token == "ATSFC") *Eng_cfg >> ATSFC;
+    else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
+    else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
+    else if (token == "MAXN1") *Eng_cfg >> MaxN1;
+    else if (token == "MAXN2") *Eng_cfg >> MaxN2;
+    else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
+    else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
+    else if (token == "INJECTED") *Eng_cfg >> Injected;
+    else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
+    else if (token == "TABLE") {
+      if (counter++ == 0) Debug(2); // print engine specs prior to table read
+      ThrustTables.push_back( new FGCoefficient(FDMExec) );
+      ThrustTables.back()->Load(Eng_cfg);
+    }
+    else cerr << "Unhandled token in Engine config file: " << token << endl;
   }
-  
-  // pre-calculations and initializations
-  delay= 1.0 / (BypassRatio + 3.0);
+
+  // Pre-calculations and initializations
+
+  delay = 60.0 / (BypassRatio + 3.0);
   N1_factor = MaxN1 - IdleN1;
   N2_factor = MaxN2 - IdleN2;
   OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
-  IdleFF = pow(MaxMilThrust, 0.2) * 107.0;  // just an estimate
-  AddFeedTank(EngineNumber);   // engine[n] feeds from tank[n]
+  IdleFF = pow(MilThrust, 0.2) * 107.0;  // just an estimate
+
   return true;
 }
 
@@ -246,6 +406,24 @@ void FGSimTurbine::Debug(int from)
     if (from == 0) { // Constructor
 
     }
+    if (from == 2) { // called from Load()
+      cout << "\n    Engine Name: "         << Name << endl;
+      cout << "      MilThrust:   "         << MilThrust << endl;
+      cout << "      MaxThrust:   "         << MaxThrust << endl;
+      cout << "      BypassRatio: "         << BypassRatio << endl;
+      cout << "      TSFC:        "         << TSFC << endl;
+      cout << "      ATSFC:       "         << ATSFC << endl;
+      cout << "      IdleN1:      "         << IdleN1 << endl;
+      cout << "      IdleN2:      "         << IdleN2 << endl;
+      cout << "      MaxN1:       "         << MaxN1 << endl;
+      cout << "      MaxN2:       "         << MaxN2 << endl;
+      cout << "      Augmented:   "         << Augmented << endl;
+      cout << "      AugMethod:   "         << AugMethod << endl;
+      cout << "      Injected:    "         << Injected << endl;
+      cout << "      MinThrottle: "         << MinThrottle << endl;
+
+      cout << endl;
+    }
   }
   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
     if (from == 0) cout << "Instantiated: FGSimTurbine" << endl;