Added minimal support for magnetos, so that engines can be shut off.
The starter isn't working yet, so the engine just springs to life.
This commit is contained in:
parent
b4a9d76215
commit
ad79ee4897
14 changed files with 126 additions and 17 deletions
|
@ -139,18 +139,20 @@ void ControlMap::applyControls()
|
||||||
|
|
||||||
void* obj = o->object;
|
void* obj = o->object;
|
||||||
switch(o->type) {
|
switch(o->type) {
|
||||||
case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
|
case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
|
||||||
case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
|
case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
|
||||||
case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
|
case STARTER: ((Thruster*)obj)->setStarter(bool(lval)); break;
|
||||||
case REHEAT: ((Jet*)obj)->setReheat(lval); break;
|
case MAGNETOS: ((PropEngine*)obj)->setMagnetos(int(lval)); break;
|
||||||
case VECTOR: ((Jet*)obj)->setRotation(lval); break;
|
case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
|
||||||
case BRAKE: ((Gear*)obj)->setBrake(lval); break;
|
case REHEAT: ((Jet*)obj)->setReheat(lval); break;
|
||||||
case STEER: ((Gear*)obj)->setRotation(lval); break;
|
case VECTOR: ((Jet*)obj)->setRotation(lval); break;
|
||||||
case EXTEND: ((Gear*)obj)->setExtension(lval); break;
|
case BRAKE: ((Gear*)obj)->setBrake(lval); break;
|
||||||
case SLAT: ((Wing*)obj)->setSlat(lval); break;
|
case STEER: ((Gear*)obj)->setRotation(lval); break;
|
||||||
case FLAP0: ((Wing*)obj)->setFlap0(lval, rval); break;
|
case EXTEND: ((Gear*)obj)->setExtension(lval); break;
|
||||||
case FLAP1: ((Wing*)obj)->setFlap1(lval, rval); break;
|
case SLAT: ((Wing*)obj)->setSlat(lval); break;
|
||||||
case SPOILER: ((Wing*)obj)->setSpoiler(lval, rval); break;
|
case FLAP0: ((Wing*)obj)->setFlap0(lval, rval); break;
|
||||||
|
case FLAP1: ((Wing*)obj)->setFlap1(lval, rval); break;
|
||||||
|
case SPOILER: ((Wing*)obj)->setSpoiler(lval, rval); break;
|
||||||
case BOOST:
|
case BOOST:
|
||||||
((Thruster*)obj)->getPistonEngine()->setBoost(lval);
|
((Thruster*)obj)->getPistonEngine()->setBoost(lval);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,7 +9,8 @@ class ControlMap {
|
||||||
public:
|
public:
|
||||||
~ControlMap();
|
~ControlMap();
|
||||||
|
|
||||||
enum OutputType { THROTTLE, MIXTURE, ADVANCE, REHEAT, PROP,
|
enum OutputType { THROTTLE, MIXTURE, STARTER, MAGNETOS,
|
||||||
|
ADVANCE, REHEAT, PROP,
|
||||||
BRAKE, STEER, EXTEND,
|
BRAKE, STEER, EXTEND,
|
||||||
INCIDENCE, FLAP0, FLAP1, SLAT, SPOILER, VECTOR,
|
INCIDENCE, FLAP0, FLAP1, SLAT, SPOILER, VECTOR,
|
||||||
BOOST };
|
BOOST };
|
||||||
|
|
|
@ -445,6 +445,8 @@ int FGFDM::parseOutput(const char* name)
|
||||||
{
|
{
|
||||||
if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
|
if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
|
||||||
if(eq(name, "MIXTURE")) return ControlMap::MIXTURE;
|
if(eq(name, "MIXTURE")) return ControlMap::MIXTURE;
|
||||||
|
if(eq(name, "STARTER")) return ControlMap::STARTER;
|
||||||
|
if(eq(name, "MAGNETOS")) return ControlMap::MAGNETOS;
|
||||||
if(eq(name, "ADVANCE")) return ControlMap::ADVANCE;
|
if(eq(name, "ADVANCE")) return ControlMap::ADVANCE;
|
||||||
if(eq(name, "REHEAT")) return ControlMap::REHEAT;
|
if(eq(name, "REHEAT")) return ControlMap::REHEAT;
|
||||||
if(eq(name, "BOOST")) return ControlMap::BOOST;
|
if(eq(name, "BOOST")) return ControlMap::BOOST;
|
||||||
|
|
|
@ -29,6 +29,8 @@ Jet::Jet()
|
||||||
_n2 = _n2Min;
|
_n2 = _n2Min;
|
||||||
|
|
||||||
// And sanify the remaining junk, just in case.
|
// And sanify the remaining junk, just in case.
|
||||||
|
_running = true;
|
||||||
|
_cranking = false;
|
||||||
_epr = 1;
|
_epr = 1;
|
||||||
_fuelFlow = 0;
|
_fuelFlow = 0;
|
||||||
_egt = 273;
|
_egt = 273;
|
||||||
|
@ -103,7 +105,6 @@ void Jet::setRotation(float rot)
|
||||||
_rotControl = rot;
|
_rotControl = rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float Jet::getN1()
|
float Jet::getN1()
|
||||||
{
|
{
|
||||||
return _n1 * _tempCorrect;
|
return _n1 * _tempCorrect;
|
||||||
|
@ -187,6 +188,16 @@ void Jet::integrate(float dt)
|
||||||
_egt = T0 + beta*ibeta0 * (_egt0 - T0);
|
_egt = T0 + beta*ibeta0 * (_egt0 - T0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Jet::isRunning()
|
||||||
|
{
|
||||||
|
return _running;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Jet::isCranking()
|
||||||
|
{
|
||||||
|
return _cranking;
|
||||||
|
}
|
||||||
|
|
||||||
void Jet::getThrust(float* out)
|
void Jet::getThrust(float* out)
|
||||||
{
|
{
|
||||||
Math::mul3(_thrust, _dir, out);
|
Math::mul3(_thrust, _dir, out);
|
||||||
|
|
|
@ -34,6 +34,8 @@ public:
|
||||||
float getEGT();
|
float getEGT();
|
||||||
|
|
||||||
// From Thruster:
|
// From Thruster:
|
||||||
|
virtual bool isRunning();
|
||||||
|
virtual bool isCranking();
|
||||||
virtual void getThrust(float* out);
|
virtual void getThrust(float* out);
|
||||||
virtual void getTorque(float* out);
|
virtual void getTorque(float* out);
|
||||||
virtual void getGyro(float* out);
|
virtual void getGyro(float* out);
|
||||||
|
@ -60,6 +62,8 @@ private:
|
||||||
float _n2Min; // N2 at ground idle
|
float _n2Min; // N2 at ground idle
|
||||||
float _n2Max; // N2 at takeoff thrust
|
float _n2Max; // N2 at takeoff thrust
|
||||||
|
|
||||||
|
bool _running; // Is the engine running?
|
||||||
|
bool _cranking; // Is the engine cranking?
|
||||||
float _thrust; // Current thrust
|
float _thrust; // Current thrust
|
||||||
float _epr; // Current EPR
|
float _epr; // Current EPR
|
||||||
float _n1; // Current UNCORRECTED N1 (percent)
|
float _n1; // Current UNCORRECTED N1 (percent)
|
||||||
|
|
|
@ -9,6 +9,8 @@ const static float CIN2CM = 1.6387064e-5;
|
||||||
PistonEngine::PistonEngine(float power, float speed)
|
PistonEngine::PistonEngine(float power, float speed)
|
||||||
{
|
{
|
||||||
_boost = 1;
|
_boost = 1;
|
||||||
|
_running = false;
|
||||||
|
_cranking = false;
|
||||||
|
|
||||||
// Presume a BSFC (in lb/hour per HP) of 0.45. In SI that becomes
|
// Presume a BSFC (in lb/hour per HP) of 0.45. In SI that becomes
|
||||||
// (2.2 lb/kg, 745.7 W/hp, 3600 sec/hour) 7.62e-08 kg/Ws.
|
// (2.2 lb/kg, 745.7 W/hp, 3600 sec/hour) 7.62e-08 kg/Ws.
|
||||||
|
@ -69,6 +71,16 @@ void PistonEngine::setThrottle(float t)
|
||||||
_throttle = t;
|
_throttle = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PistonEngine::setStarter(bool s)
|
||||||
|
{
|
||||||
|
_starter = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PistonEngine::setMagnetos(int m)
|
||||||
|
{
|
||||||
|
_magnetos = m;
|
||||||
|
}
|
||||||
|
|
||||||
void PistonEngine::setMixture(float m)
|
void PistonEngine::setMixture(float m)
|
||||||
{
|
{
|
||||||
_mixture = m;
|
_mixture = m;
|
||||||
|
@ -79,6 +91,16 @@ void PistonEngine::setBoost(float boost)
|
||||||
_boost = boost;
|
_boost = boost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PistonEngine::isRunning()
|
||||||
|
{
|
||||||
|
return _running;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PistonEngine::isCranking()
|
||||||
|
{
|
||||||
|
return _cranking;
|
||||||
|
}
|
||||||
|
|
||||||
float PistonEngine::getTorque()
|
float PistonEngine::getTorque()
|
||||||
{
|
{
|
||||||
return _torque;
|
return _torque;
|
||||||
|
@ -101,6 +123,20 @@ float PistonEngine::getEGT()
|
||||||
|
|
||||||
void PistonEngine::calc(float pressure, float temp, float speed)
|
void PistonEngine::calc(float pressure, float temp, float speed)
|
||||||
{
|
{
|
||||||
|
if (_magnetos == 0) {
|
||||||
|
_running = false;
|
||||||
|
_mp = _rho0;
|
||||||
|
_torque = 0;
|
||||||
|
_fuelFlow = 0;
|
||||||
|
_egt = 80; // FIXME: totally made-up
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_running = true;
|
||||||
|
_cranking = false;
|
||||||
|
|
||||||
|
// TODO: degrade performance on single magneto
|
||||||
|
|
||||||
// Calculate manifold pressure as ambient pressure modified for
|
// Calculate manifold pressure as ambient pressure modified for
|
||||||
// turbocharging and reduced by the throttle setting. According
|
// turbocharging and reduced by the throttle setting. According
|
||||||
// to Dave Luff, minimum throttle at sea level corresponds to 6"
|
// to Dave Luff, minimum throttle at sea level corresponds to 6"
|
||||||
|
|
|
@ -12,12 +12,16 @@ public:
|
||||||
void setCompression(float c);
|
void setCompression(float c);
|
||||||
|
|
||||||
void setThrottle(float throttle);
|
void setThrottle(float throttle);
|
||||||
|
void setStarter(bool starter);
|
||||||
|
void setMagnetos(int magnetos);
|
||||||
void setMixture(float mixture);
|
void setMixture(float mixture);
|
||||||
void setBoost(float boost); // fraction of turbo-mul used
|
void setBoost(float boost); // fraction of turbo-mul used
|
||||||
|
|
||||||
float getMaxPower(); // max sea-level power
|
float getMaxPower(); // max sea-level power
|
||||||
|
|
||||||
void calc(float pressure, float temp, float speed);
|
void calc(float pressure, float temp, float speed);
|
||||||
|
bool isRunning();
|
||||||
|
bool isCranking();
|
||||||
float getTorque();
|
float getTorque();
|
||||||
float getFuelFlow();
|
float getFuelFlow();
|
||||||
float getMP();
|
float getMP();
|
||||||
|
@ -37,10 +41,14 @@ private:
|
||||||
|
|
||||||
// Runtime settables:
|
// Runtime settables:
|
||||||
float _throttle;
|
float _throttle;
|
||||||
|
bool _starter; // true=engaged, false=disengaged
|
||||||
|
int _magnetos; // 0=off, 1=right, 2=left, 3=both
|
||||||
float _mixture;
|
float _mixture;
|
||||||
float _boost;
|
float _boost;
|
||||||
|
|
||||||
// Runtime state/output:
|
// Runtime state/output:
|
||||||
|
bool _running;
|
||||||
|
bool _cranking;
|
||||||
float _mp;
|
float _mp;
|
||||||
float _torque;
|
float _torque;
|
||||||
float _fuelFlow;
|
float _fuelFlow;
|
||||||
|
|
|
@ -23,6 +23,11 @@ PropEngine::~PropEngine()
|
||||||
delete _eng;
|
delete _eng;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PropEngine::setMagnetos(int pos)
|
||||||
|
{
|
||||||
|
_magnetos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
void PropEngine::setAdvance(float advance)
|
void PropEngine::setAdvance(float advance)
|
||||||
{
|
{
|
||||||
_advance = Math::clamp(advance, 0, 1);
|
_advance = Math::clamp(advance, 0, 1);
|
||||||
|
@ -35,6 +40,16 @@ void PropEngine::setVariableProp(float min, float max)
|
||||||
_maxOmega = max;
|
_maxOmega = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PropEngine::isRunning()
|
||||||
|
{
|
||||||
|
return _eng->isRunning();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropEngine::isCranking()
|
||||||
|
{
|
||||||
|
return _eng->isCranking();
|
||||||
|
}
|
||||||
|
|
||||||
float PropEngine::getOmega()
|
float PropEngine::getOmega()
|
||||||
{
|
{
|
||||||
return _omega;
|
return _omega;
|
||||||
|
@ -67,6 +82,8 @@ void PropEngine::stabilize()
|
||||||
{
|
{
|
||||||
float speed = -Math::dot3(_wind, _dir);
|
float speed = -Math::dot3(_wind, _dir);
|
||||||
_eng->setThrottle(_throttle);
|
_eng->setThrottle(_throttle);
|
||||||
|
_eng->setStarter(_starter);
|
||||||
|
_eng->setMagnetos(true); // FIXME: otherwise, an infinite loop
|
||||||
_eng->setMixture(_mixture);
|
_eng->setMixture(_mixture);
|
||||||
|
|
||||||
if(_variable) {
|
if(_variable) {
|
||||||
|
@ -109,6 +126,8 @@ void PropEngine::integrate(float dt)
|
||||||
float propTorque, engTorque, thrust;
|
float propTorque, engTorque, thrust;
|
||||||
|
|
||||||
_eng->setThrottle(_throttle);
|
_eng->setThrottle(_throttle);
|
||||||
|
_eng->setStarter(_starter);
|
||||||
|
_eng->setMagnetos(_magnetos);
|
||||||
_eng->setMixture(_mixture);
|
_eng->setMixture(_mixture);
|
||||||
|
|
||||||
_prop->calc(_rho, speed, _omega, &thrust, &propTorque);
|
_prop->calc(_rho, speed, _omega, &thrust, &propTorque);
|
||||||
|
@ -126,7 +145,7 @@ void PropEngine::integrate(float dt)
|
||||||
|
|
||||||
// Clamp to a 500 rpm idle. This should probably be settable, and
|
// Clamp to a 500 rpm idle. This should probably be settable, and
|
||||||
// needs to go away when the startup code gets written.
|
// needs to go away when the startup code gets written.
|
||||||
if(_omega < 52.3) _omega = 52.3;
|
// if(_omega < 52.3) _omega = 52.3;
|
||||||
|
|
||||||
// Store the total angular momentum into _gyro
|
// Store the total angular momentum into _gyro
|
||||||
Math::mul3(_omega*_moment, _dir, _gyro);
|
Math::mul3(_omega*_moment, _dir, _gyro);
|
||||||
|
|
|
@ -13,6 +13,7 @@ public:
|
||||||
PropEngine(Propeller* prop, PistonEngine* eng, float moment);
|
PropEngine(Propeller* prop, PistonEngine* eng, float moment);
|
||||||
virtual ~PropEngine();
|
virtual ~PropEngine();
|
||||||
|
|
||||||
|
void setMagnetos(int magnetos);
|
||||||
void setAdvance(float advance);
|
void setAdvance(float advance);
|
||||||
void setVariableProp(float min, float max);
|
void setVariableProp(float min, float max);
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ public:
|
||||||
virtual Propeller* getPropeller() { return _prop; }
|
virtual Propeller* getPropeller() { return _prop; }
|
||||||
|
|
||||||
// Dynamic output
|
// Dynamic output
|
||||||
|
virtual bool isRunning();
|
||||||
|
virtual bool isCranking();
|
||||||
virtual void getThrust(float* out);
|
virtual void getThrust(float* out);
|
||||||
virtual void getTorque(float* out);
|
virtual void getTorque(float* out);
|
||||||
virtual void getGyro(float* out);
|
virtual void getGyro(float* out);
|
||||||
|
@ -38,6 +41,7 @@ private:
|
||||||
PistonEngine* _eng;
|
PistonEngine* _eng;
|
||||||
|
|
||||||
bool _variable;
|
bool _variable;
|
||||||
|
int _magnetos; // 0=off, 1=right, 2=left, 3=both
|
||||||
float _advance; // control input, 0-1
|
float _advance; // control input, 0-1
|
||||||
float _maxOmega;
|
float _maxOmega;
|
||||||
float _minOmega;
|
float _minOmega;
|
||||||
|
|
|
@ -13,6 +13,16 @@ void SimpleJet::setThrust(float thrust)
|
||||||
_thrust = thrust;
|
_thrust = thrust;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SimpleJet::isRunning()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimpleJet::isCranking()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void SimpleJet::getThrust(float* out)
|
void SimpleJet::getThrust(float* out)
|
||||||
{
|
{
|
||||||
Math::mul3(_thrust * _throttle, _dir, out);
|
Math::mul3(_thrust * _throttle, _dir, out);
|
||||||
|
|
|
@ -11,6 +11,8 @@ class SimpleJet : public Thruster
|
||||||
public:
|
public:
|
||||||
SimpleJet();
|
SimpleJet();
|
||||||
void setThrust(float thrust);
|
void setThrust(float thrust);
|
||||||
|
virtual bool isRunning();
|
||||||
|
virtual bool isCranking();
|
||||||
virtual void getThrust(float* out);
|
virtual void getThrust(float* out);
|
||||||
virtual void getTorque(float* out);
|
virtual void getTorque(float* out);
|
||||||
virtual void getGyro(float* out);
|
virtual void getGyro(float* out);
|
||||||
|
|
|
@ -9,6 +9,7 @@ Thruster::Thruster()
|
||||||
for(i=0; i<3; i++) _pos[i] = _wind[i] = 0;
|
for(i=0; i<3; i++) _pos[i] = _wind[i] = 0;
|
||||||
_throttle = 0;
|
_throttle = 0;
|
||||||
_mixture = 0;
|
_mixture = 0;
|
||||||
|
_starter = false;
|
||||||
_pressure = _temp = _rho = 0;
|
_pressure = _temp = _rho = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +50,11 @@ void Thruster::setMixture(float mixture)
|
||||||
_mixture = Math::clamp(mixture, 0, 1);
|
_mixture = Math::clamp(mixture, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Thruster::setStarter(bool starter)
|
||||||
|
{
|
||||||
|
_starter = starter;
|
||||||
|
}
|
||||||
|
|
||||||
void Thruster::setWind(float* wind)
|
void Thruster::setWind(float* wind)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -30,8 +30,11 @@ public:
|
||||||
// Controls
|
// Controls
|
||||||
void setThrottle(float throttle);
|
void setThrottle(float throttle);
|
||||||
void setMixture(float mixture);
|
void setMixture(float mixture);
|
||||||
|
void setStarter(bool starter);
|
||||||
|
|
||||||
// Dynamic output
|
// Dynamic output
|
||||||
|
virtual bool isRunning()=0;
|
||||||
|
virtual bool isCranking()=0;
|
||||||
virtual void getThrust(float* out)=0;
|
virtual void getThrust(float* out)=0;
|
||||||
virtual void getTorque(float* out)=0;
|
virtual void getTorque(float* out)=0;
|
||||||
virtual void getGyro(float* out)=0;
|
virtual void getGyro(float* out)=0;
|
||||||
|
@ -48,6 +51,7 @@ protected:
|
||||||
float _dir[3];
|
float _dir[3];
|
||||||
float _throttle;
|
float _throttle;
|
||||||
float _mixture;
|
float _mixture;
|
||||||
|
bool _starter; // true=engaged, false=disengaged
|
||||||
|
|
||||||
float _wind[3];
|
float _wind[3];
|
||||||
float _pressure;
|
float _pressure;
|
||||||
|
|
|
@ -419,8 +419,8 @@ void YASim::copyFromYASim()
|
||||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||||
Thruster* t = model->getThruster(i);
|
Thruster* t = model->getThruster(i);
|
||||||
|
|
||||||
node->setBoolValue("running", true);
|
node->setBoolValue("running", t->isRunning());
|
||||||
node->setBoolValue("cranking", false);
|
node->setBoolValue("cranking", t->isCranking());
|
||||||
|
|
||||||
// Note: assumes all tanks have the same fuel density!
|
// Note: assumes all tanks have the same fuel density!
|
||||||
node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow()
|
node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow()
|
||||||
|
|
Loading…
Reference in a new issue