]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Jet.cpp
latest updates from JSBSim
[flightgear.git] / src / FDM / YASim / Jet.cpp
index e3448a91966a63915558b9e0707a6f0a3e2b71fd..f80cac543daee572160a6247eee53b9733672b67 100644 (file)
@@ -10,6 +10,7 @@ Jet::Jet()
     _reheat = 0;
     _rotControl = 0;
     _maxRot = 0;
+    _reverseThrust = false;
 
     // Initialize parameters for an early-ish subsonic turbojet.  More
     // recent turbofans will typically have a lower vMax, epr0, and
@@ -31,6 +32,7 @@ Jet::Jet()
     // And sanify the remaining junk, just in case.
     _running = true;
     _cranking = false;
+    _fuel = true;
     _epr = 1;
     _fuelFlow = 0;
     _egt = 273;
@@ -140,24 +142,30 @@ void Jet::integrate(float dt)
     const static float T0 = Atmosphere::getStdTemperature(0);
     const static float D0 = Atmosphere::getStdDensity(0);
 
-    float speed = -Math::dot3(_wind, _dir);
+    float spd = -Math::dot3(_wind, _dir);
 
     float statT, statP, statD;
-    Atmosphere::calcStaticAir(_pressure, _temp, _rho, speed,
+    Atmosphere::calcStaticAir(_pressure, _temp, _rho, spd,
                               &statP, &statT, &statD);
     _pressureCorrect = statP/P0;
     _tempCorrect = Math::sqrt(statT/T0);
 
+    // Handle running out of fuel.  This is a hack.  What should
+    // really happen is a simulation of ram air torque on the
+    // turbine.  This just forces the engine into ground idle.
+    if(_fuel == false)
+        _throttle = 0;
+
     // Linearly taper maxThrust to zero at vMax
-    float vCorr = 1 - (speed/_vMax);
+    float vCorr = spd<0 ? 1 : (spd<_vMax ? 1-spd/_vMax : 0);
 
     float maxThrust = _maxThrust * vCorr * (statD/D0);
-    _thrust = maxThrust * _throttle;
+    float setThrust = maxThrust * _throttle;
 
     // Now get a "beta" (i.e. EPR - 1) value.  The output values are
     // expressed as functions of beta.
     float ibeta0 = 1/(_epr0 - 1);
-    float betaTarget = (_epr0 - 1) * (_thrust/_maxThrust) * (P0/_pressure)
+    float betaTarget = (_epr0 - 1) * (setThrust/_maxThrust) * (P0/_pressure)
        * (_temp/statT);
     float n2Target = _n2Min + (betaTarget*ibeta0) * (_n2Max - _n2Min);
 
@@ -173,7 +181,7 @@ void Jet::integrate(float dt)
     // The actual thrust produced is keyed to the N1 speed.  Add the
     // afterburners in at the end.
     float betaN1 =  (_epr0-1) * (_n1 - _n1Min) / (_n1Max - _n1Min);
-    _thrust *= betaN1/(betaTarget+0.00001f); // blowup protection
+    _thrust = _maxThrust * betaN1/((_epr0-1)*(P0/_pressure)*(_temp/statT));
     _thrust *= 1 + _reheat*(_abFactor-1);
 
     // Finally, calculate the output variables.   Use a 80/20 mix of
@@ -186,6 +194,9 @@ void Jet::integrate(float dt)
                                                  // 3.5 times as much
                                                  // fuel per thrust unit
     _egt = T0 + beta*ibeta0 * (_egt0 - T0);
+
+    // Thrust reverse handling:
+    if(_reverseThrust) _thrust *= -_reverseEff;
 }
 
 bool Jet::isRunning()