]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGTurbine.cpp
Encapsulate the interpolstion version of FGEnvironment and fix some bugs
[flightgear.git] / src / FDM / JSBSim / FGTurbine.cpp
index a380b4b60cf70c6f8bfa72997f31deb0f98dae42..e329f2c211e430d9ae53cfc60c30244845081ebf 100644 (file)
@@ -38,8 +38,12 @@ HISTORY
 INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
+#include <vector>
 #include "FGTurbine.h"
 
+
+namespace JSBSim {
+
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_TURBINE;
 
@@ -50,6 +54,8 @@ CLASS IMPLEMENTATION
 
 FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
 {
+  Load(cfg);
+  PowerCommand=0;
   Debug(0);
 }
 
@@ -64,12 +70,82 @@ FGTurbine::~FGTurbine()
 
 double FGTurbine::Calculate(double dummy)
 {
+  double idle,mil,aug;
+  double throttle=FCS->GetThrottlePos(EngineNumber);
+  double dt=State->Getdt();
+  if( dt > 0 ) {
+    PowerCommand+=dt*PowerLag( PowerCommand, 
+                         ThrottleToPowerCommand(throttle) );
+    if(PowerCommand > 100 )
+      PowerCommand=100;
+    else if(PowerCommand < 0 )
+      PowerCommand=0;
+                    
+  } else {
+    PowerCommand=ThrottleToPowerCommand(throttle);
+  }                         
+  
+  mil=MaxMilThrust*ThrustTables[1]->TotalValue();
+  
+  if( PowerCommand <= 50 ) {
+    idle=MaxMilThrust*ThrustTables[0]->TotalValue();
+    Thrust = idle + (mil-idle)*PowerCommand*0.02;
+  } else {
+    aug=MaxAugThrust*ThrustTables[2]->TotalValue();
+    Thrust = mil + (aug-mil)*(PowerCommand-50)*0.02;
+  }    
+  
   ConsumeFuel();
-  return 0.0;
+  
+  return Thrust;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+double FGTurbine::ThrottleToPowerCommand(double throttle) {
+  if( throttle <= 0.77 ) 
+    return 64.94*throttle;
+  else
+    return 217.38*throttle - 117.38;
+}      
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGTurbine::PowerLag(double actual_power, double power_command) {
+  double t, p2;
+  if( power_command >= 50 ) {
+    if( actual_power >= 50 ) {
+      t=5;
+      p2=power_command;
+    } else {
+      p2=60;
+      t=rtau(p2-actual_power);
+    }
+  } else {
+    if( actual_power >= 50 ) {
+      t=5;
+      p2=40;
+    } else {
+      p2=power_command;
+      t=rtau(p2-actual_power);
+    }
+  }
+  return t*(p2-actual_power);
+}    
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGTurbine::rtau(double delta_power) {
+  if( delta_power <= 25 ) 
+    return 1.0;
+  else if ( delta_power >= 50)
+    return 0.1;
+  else
+    return 1.9-0.036*delta_power;
+}
+        
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 void FGTurbine::doInlet(void)
 {
 }
@@ -113,8 +189,23 @@ void FGTurbine::doTransition(void)
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
-bool FGTurbine::Load(FGConfigFile *AC_cfg)
+bool FGTurbine::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 >> MaxAugThrust;
+  i=0;
+  while( Eng_cfg->GetValue() != string("/FG_TURBINE") && i < 10){
+    ThrustTables.push_back( new FGCoefficient(FDMExec) );
+    ThrustTables.back()->Load(Eng_cfg);
+    i++;
+  }
+
+  return true;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -162,4 +253,4 @@ void FGTurbine::Debug(int from)
     }
   }
 }
-
+}