_eng = eng;
_moment = moment;
_fuel = true;
+ _contra = false;
}
PropEngine::~PropEngine()
bool goingUp = false;
float step = 10;
- while(true) {
+
+ // If we cannot manage this in 100 iterations, give up.
+ for (int n = 0; n < 100; n++) {
float ptau, thrust;
_prop->calc(_rho, speed, _omega * _gearRatio, &thrust, &ptau);
_eng->calc(_pressure, _temp, _omega);
_eng->stabilize();
- // Compute torque as seen by the engine's end of the
- // gearbox.
+ // Do it again -- the turbo sets the target MP in the first
+ // run, stabilize sets the current to the target, then we need
+ // to run again to get the correct output torque. Clumsy, but
+ // it works without side effects (other than solver
+ // performance). In the future, the Engine objects should
+ // store state to allow them to do the work themselves.
+ _eng->calc(_pressure, _temp, _omega);
+
+ // Compute torque as seen by the engine's end of the gearbox.
+ // The propeller will be moving more slowly (for gear ratios
+ // less than one), so it's torque will be higher than the
+ // engine's, so multiply by _gearRatio to get the engine-side
+ // value.
ptau *= _gearRatio;
float etau = _eng->getTorque();
float tdiff = etau - ptau;
_eng->setFuelState(_fuel);
_prop->calc(_rho, speed, _omega * _gearRatio, &thrust, &propTorque);
+ if(_omega == 0.0)
+ _omega = 0.001; // hack to get around reports of NaNs somewhere...
+ propTorque *= _gearRatio;
_eng->calc(_pressure, _temp, _omega);
_eng->integrate(dt);
engTorque = _eng->getTorque();
_omega = 0 - _omega; // don't allow negative RPM
// FIXME: introduce proper windmilling
- // Store the total angular momentum into _gyro
- Math::mul3(_omega*momt, _dir, _gyro);
+ // Store the total angular momentum into _gyro, unless the
+ // propeller is a counter-rotating pair (which has zero net
+ // angular momentum, even though it *does* have an MoI for
+ // acceleration purposes).
+ Math::mul3(_contra ? 0 : _omega*momt, _dir, _gyro);
// Accumulate the engine torque, it acts on the body as a whole.
// (Note: engine torque, not propeller torque. They can be
// different, but the difference goes to accelerating the
// rotation. It is the engine torque that is felt at the shaft
- // and works on the body.)
+ // and works on the body.) (Note 2: contra-rotating propellers do
+ // not exert net torque on the aircraft).
float tau = _moment < 0 ? engTorque : -engTorque;
- Math::mul3(tau, _dir, _torque);
+ Math::mul3(_contra ? 0 : tau, _dir, _torque);
// Iterate the propeller governor, if we have one. Since engine
// torque is basically constant with RPM, we want to make the
// _current_ RPM. Seek to that. This is sort of a continuous
// Newton-Raphson, basically.
if(_variable) {
- float targetOmega = _minOmega + _advance*(_maxOmega-_minOmega);
+ float targetPropSpd = _minOmega + _advance*(_maxOmega-_minOmega);
+ float targetOmega = targetPropSpd / _gearRatio; // -> "engine omega"
float ratio2 = (_omega*_omega)/(targetOmega*targetOmega);
float targetTorque = engTorque * ratio2;