_running = false;
_fuel = true;
_boostPressure = 0;
+ _hasSuper = false;
_oilTemp = Atmosphere::getStdTemperature(0);
_oilTempTarget = _oilTemp;
_mixCoeff = realFlow * 1.1f / _omega0;
_turbo = 1;
+ _minthrottle = 0.1;
_maxMP = 1e6; // No waste gate on non-turbo engines.
+ _wastegate = 1;
+ _charge = 1;
+ _chargeTarget = 1;
+ _turboLag = 2;
// Guess at reasonable values for these guys. Displacements run
// at about 2 cubic inches per horsepower or so, at least for
_compression = c;
}
+void PistonEngine::setMinThrottle(float m)
+{
+ _minthrottle = m;
+}
+
float PistonEngine::getMaxPower()
{
return _power0;
void PistonEngine::stabilize()
{
_oilTemp = _oilTempTarget;
+ _charge = _chargeTarget;
}
void PistonEngine::integrate(float dt)
{
_oilTemp += (_dOilTempdt * dt);
+
+ // See comments in Jet.cpp for how this decay constant works
+ float decay = 2.3f / _turboLag;
+ _charge = (_charge + dt*decay * _chargeTarget) / (1 + dt*decay);
}
void PistonEngine::calc(float pressure, float temp, float speed)
{
- if(_magnetos == 0 || speed < 60*RPM2RADPS)
- _running = false;
- else if(_fuel == false)
- _running = false;
- else
- _running = true;
+ _running = _magnetos && _fuel && (speed > 60*RPM2RADPS);
- // Calculate the factor required to modify supercharger output for
+ // Calculate the factor required to modify supercharger output for
// rpm. Assume that the normalized supercharger output ~= 1 when
- // the engine is at the nominated peak-power rpm (normalised).
- // A power equation of the form (A * B^x * x^C) has been
- // derived empirically from some representative supercharger data.
- // This provides near-linear output over the normal operating range,
- // with fall-off in the over-speed situation.
+ // the engine is at the nominal peak-power rpm. A power equation
+ // of the form (A * B^x * x^C) has been derived empirically from
+ // some representative supercharger data. This provides
+ // near-linear output over the normal operating range, with
+ // fall-off in the over-speed situation.
float rpm_norm = (speed / _omega0);
float A = 1.795206541;
float B = 0.55620178;
float C = 1.246708471;
float rpm_factor = A * Math::pow(B, rpm_norm) * Math::pow(rpm_norm, C);
+ _chargeTarget = 1 + (_boost * (_turbo-1) * rpm_factor);
+
+ if(_hasSuper) {
+ // Superchargers have no lag
+ _charge = _chargeTarget;
+ } else if(!_running) {
+ // Turbochargers only work well when the engine is actually
+ // running. The 25% number is a guesstimate from Vivian.
+ _chargeTarget = 1 + (_chargeTarget - 1) * 0.25;
+ }
// We need to adjust the minimum manifold pressure to get a
// reasonable idle speed (a "closed" throttle doesn't suck a total
// vacuum in real manifolds). This is a hack.
- float _minMP = (-0.008 * _turbo ) + 0.1;
+ float _minMP = (-0.008 * _turbo ) + _minthrottle;
+
+ _mp = pressure * _charge;
// Scale to throttle setting, clamp to wastegate
- if(_running) {
- _mp = pressure * (1 + (_boost * (_turbo-1) * rpm_factor));
+ if(_running)
_mp *= _minMP + (1 -_minMP) * _throttle;
- }
- if(_mp > _maxMP) _mp = _maxMP;
+
+ // Scale the max MP according to the WASTEGATE control input. Use
+ // the un-supercharged MP as the bottom limit.
+ float max = _wastegate * _maxMP;
+ if(max < _mp/_charge) max = _mp/_charge;
+ if(_mp > max) _mp = max;
+
// The "boost" is the delta above ambient
_boostPressure = _mp - pressure;
// pressure change can be assumed to be adiabatic. Calculate a
// temperature change, and use that to get the density.
// Note: need to model intercoolers here...
- float T = temp * Math::pow(_mp/pressure, 2.0/7.0);
+ float T = temp * Math::pow((_mp*_mp)/(pressure*pressure), 1.0/7.0);
float rho = _mp / (287.1f * T);
// The actual fuel flow is determined only by engine RPM and the