1
0
Fork 0

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:
david 2002-02-20 04:27:22 +00:00
parent b4a9d76215
commit ad79ee4897
14 changed files with 126 additions and 17 deletions

View file

@ -139,18 +139,20 @@ void ControlMap::applyControls()
void* obj = o->object;
switch(o->type) {
case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
case REHEAT: ((Jet*)obj)->setReheat(lval); break;
case VECTOR: ((Jet*)obj)->setRotation(lval); break;
case BRAKE: ((Gear*)obj)->setBrake(lval); break;
case STEER: ((Gear*)obj)->setRotation(lval); break;
case EXTEND: ((Gear*)obj)->setExtension(lval); break;
case SLAT: ((Wing*)obj)->setSlat(lval); 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 THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
case STARTER: ((Thruster*)obj)->setStarter(bool(lval)); break;
case MAGNETOS: ((PropEngine*)obj)->setMagnetos(int(lval)); break;
case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
case REHEAT: ((Jet*)obj)->setReheat(lval); break;
case VECTOR: ((Jet*)obj)->setRotation(lval); break;
case BRAKE: ((Gear*)obj)->setBrake(lval); break;
case STEER: ((Gear*)obj)->setRotation(lval); break;
case EXTEND: ((Gear*)obj)->setExtension(lval); break;
case SLAT: ((Wing*)obj)->setSlat(lval); 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:
((Thruster*)obj)->getPistonEngine()->setBoost(lval);
break;

View file

@ -9,7 +9,8 @@ class ControlMap {
public:
~ControlMap();
enum OutputType { THROTTLE, MIXTURE, ADVANCE, REHEAT, PROP,
enum OutputType { THROTTLE, MIXTURE, STARTER, MAGNETOS,
ADVANCE, REHEAT, PROP,
BRAKE, STEER, EXTEND,
INCIDENCE, FLAP0, FLAP1, SLAT, SPOILER, VECTOR,
BOOST };

View file

@ -445,6 +445,8 @@ int FGFDM::parseOutput(const char* name)
{
if(eq(name, "THROTTLE")) return ControlMap::THROTTLE;
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, "REHEAT")) return ControlMap::REHEAT;
if(eq(name, "BOOST")) return ControlMap::BOOST;

View file

@ -29,6 +29,8 @@ Jet::Jet()
_n2 = _n2Min;
// And sanify the remaining junk, just in case.
_running = true;
_cranking = false;
_epr = 1;
_fuelFlow = 0;
_egt = 273;
@ -103,7 +105,6 @@ void Jet::setRotation(float rot)
_rotControl = rot;
}
float Jet::getN1()
{
return _n1 * _tempCorrect;
@ -187,6 +188,16 @@ void Jet::integrate(float dt)
_egt = T0 + beta*ibeta0 * (_egt0 - T0);
}
bool Jet::isRunning()
{
return _running;
}
bool Jet::isCranking()
{
return _cranking;
}
void Jet::getThrust(float* out)
{
Math::mul3(_thrust, _dir, out);

View file

@ -34,6 +34,8 @@ public:
float getEGT();
// From Thruster:
virtual bool isRunning();
virtual bool isCranking();
virtual void getThrust(float* out);
virtual void getTorque(float* out);
virtual void getGyro(float* out);
@ -60,6 +62,8 @@ private:
float _n2Min; // N2 at ground idle
float _n2Max; // N2 at takeoff thrust
bool _running; // Is the engine running?
bool _cranking; // Is the engine cranking?
float _thrust; // Current thrust
float _epr; // Current EPR
float _n1; // Current UNCORRECTED N1 (percent)

View file

@ -9,6 +9,8 @@ const static float CIN2CM = 1.6387064e-5;
PistonEngine::PistonEngine(float power, float speed)
{
_boost = 1;
_running = false;
_cranking = false;
// 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.
@ -69,6 +71,16 @@ void PistonEngine::setThrottle(float t)
_throttle = t;
}
void PistonEngine::setStarter(bool s)
{
_starter = s;
}
void PistonEngine::setMagnetos(int m)
{
_magnetos = m;
}
void PistonEngine::setMixture(float m)
{
_mixture = m;
@ -79,6 +91,16 @@ void PistonEngine::setBoost(float boost)
_boost = boost;
}
bool PistonEngine::isRunning()
{
return _running;
}
bool PistonEngine::isCranking()
{
return _cranking;
}
float PistonEngine::getTorque()
{
return _torque;
@ -101,6 +123,20 @@ float PistonEngine::getEGT()
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
// turbocharging and reduced by the throttle setting. According
// to Dave Luff, minimum throttle at sea level corresponds to 6"

View file

@ -12,12 +12,16 @@ public:
void setCompression(float c);
void setThrottle(float throttle);
void setStarter(bool starter);
void setMagnetos(int magnetos);
void setMixture(float mixture);
void setBoost(float boost); // fraction of turbo-mul used
float getMaxPower(); // max sea-level power
void calc(float pressure, float temp, float speed);
bool isRunning();
bool isCranking();
float getTorque();
float getFuelFlow();
float getMP();
@ -37,10 +41,14 @@ private:
// Runtime settables:
float _throttle;
bool _starter; // true=engaged, false=disengaged
int _magnetos; // 0=off, 1=right, 2=left, 3=both
float _mixture;
float _boost;
// Runtime state/output:
bool _running;
bool _cranking;
float _mp;
float _torque;
float _fuelFlow;

View file

@ -23,6 +23,11 @@ PropEngine::~PropEngine()
delete _eng;
}
void PropEngine::setMagnetos(int pos)
{
_magnetos = pos;
}
void PropEngine::setAdvance(float advance)
{
_advance = Math::clamp(advance, 0, 1);
@ -35,6 +40,16 @@ void PropEngine::setVariableProp(float min, float max)
_maxOmega = max;
}
bool PropEngine::isRunning()
{
return _eng->isRunning();
}
bool PropEngine::isCranking()
{
return _eng->isCranking();
}
float PropEngine::getOmega()
{
return _omega;
@ -67,6 +82,8 @@ void PropEngine::stabilize()
{
float speed = -Math::dot3(_wind, _dir);
_eng->setThrottle(_throttle);
_eng->setStarter(_starter);
_eng->setMagnetos(true); // FIXME: otherwise, an infinite loop
_eng->setMixture(_mixture);
if(_variable) {
@ -109,6 +126,8 @@ void PropEngine::integrate(float dt)
float propTorque, engTorque, thrust;
_eng->setThrottle(_throttle);
_eng->setStarter(_starter);
_eng->setMagnetos(_magnetos);
_eng->setMixture(_mixture);
_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
// 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
Math::mul3(_omega*_moment, _dir, _gyro);

View file

@ -13,6 +13,7 @@ public:
PropEngine(Propeller* prop, PistonEngine* eng, float moment);
virtual ~PropEngine();
void setMagnetos(int magnetos);
void setAdvance(float advance);
void setVariableProp(float min, float max);
@ -21,6 +22,8 @@ public:
virtual Propeller* getPropeller() { return _prop; }
// Dynamic output
virtual bool isRunning();
virtual bool isCranking();
virtual void getThrust(float* out);
virtual void getTorque(float* out);
virtual void getGyro(float* out);
@ -38,6 +41,7 @@ private:
PistonEngine* _eng;
bool _variable;
int _magnetos; // 0=off, 1=right, 2=left, 3=both
float _advance; // control input, 0-1
float _maxOmega;
float _minOmega;

View file

@ -13,6 +13,16 @@ void SimpleJet::setThrust(float thrust)
_thrust = thrust;
}
bool SimpleJet::isRunning()
{
return true;
}
bool SimpleJet::isCranking()
{
return false;
}
void SimpleJet::getThrust(float* out)
{
Math::mul3(_thrust * _throttle, _dir, out);

View file

@ -11,6 +11,8 @@ class SimpleJet : public Thruster
public:
SimpleJet();
void setThrust(float thrust);
virtual bool isRunning();
virtual bool isCranking();
virtual void getThrust(float* out);
virtual void getTorque(float* out);
virtual void getGyro(float* out);

View file

@ -9,6 +9,7 @@ Thruster::Thruster()
for(i=0; i<3; i++) _pos[i] = _wind[i] = 0;
_throttle = 0;
_mixture = 0;
_starter = false;
_pressure = _temp = _rho = 0;
}
@ -49,6 +50,11 @@ void Thruster::setMixture(float mixture)
_mixture = Math::clamp(mixture, 0, 1);
}
void Thruster::setStarter(bool starter)
{
_starter = starter;
}
void Thruster::setWind(float* wind)
{
int i;

View file

@ -30,8 +30,11 @@ public:
// Controls
void setThrottle(float throttle);
void setMixture(float mixture);
void setStarter(bool starter);
// Dynamic output
virtual bool isRunning()=0;
virtual bool isCranking()=0;
virtual void getThrust(float* out)=0;
virtual void getTorque(float* out)=0;
virtual void getGyro(float* out)=0;
@ -48,6 +51,7 @@ protected:
float _dir[3];
float _throttle;
float _mixture;
bool _starter; // true=engaged, false=disengaged
float _wind[3];
float _pressure;

View file

@ -419,8 +419,8 @@ void YASim::copyFromYASim()
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
Thruster* t = model->getThruster(i);
node->setBoolValue("running", true);
node->setBoolValue("cranking", false);
node->setBoolValue("running", t->isRunning());
node->setBoolValue("cranking", t->isCranking());
// Note: assumes all tanks have the same fuel density!
node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow()