Refactoring in preparation to add a turbine engine to YASim. The
PistonEngine class has grown an "Engine" superclass. Some other stuff moved around too, and I cleaned up some property naming while I was in there. This hasn't been tested very thorougly, hopefully I didn't break anything.
This commit is contained in:
parent
a6466e7d2f
commit
b1c964030d
10 changed files with 95 additions and 121 deletions
|
@ -206,7 +206,7 @@ void ControlMap::applyControls(float dt)
|
|||
case ROTORENGINEON: ((Rotor*)obj)->setEngineOn((int)lval); break;
|
||||
case REVERSE_THRUST: ((Jet*)obj)->setReverse(lval != 0); break;
|
||||
case BOOST:
|
||||
((Thruster*)obj)->getPistonEngine()->setBoost(lval);
|
||||
((PistonEngine*)((Thruster*)obj)->getEngine())->setBoost(lval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
45
src/FDM/YASim/Engine.hpp
Normal file
45
src/FDM/YASim/Engine.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef _ENGINE_HPP
|
||||
#define _ENGINE_HPP
|
||||
|
||||
namespace yasim {
|
||||
|
||||
class PistonEngine;
|
||||
|
||||
//
|
||||
// Interface for the "Engine" part of a PropEngine object. This is a
|
||||
// virtual class, intended to be implemented by stuff like
|
||||
// PistonEngine and TurbineEngine, and maybe exotics like
|
||||
// SolarElectricEngine, etc...
|
||||
//
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
virtual PistonEngine* isPistonEngine() { return 0; }
|
||||
|
||||
void setThrottle(float throttle) { _throttle = throttle; }
|
||||
void setStarter(bool starter) { _starter = starter; }
|
||||
void setMagnetos(int magnetos) { _magnetos = magnetos; }
|
||||
void setMixture(float mixture) { _mixture = mixture; }
|
||||
void setBoost(float boost) { _boost = boost; }
|
||||
void setFuelState(bool hasFuel) { _fuel = hasFuel; }
|
||||
void setRunning(bool r) { _running = r; }
|
||||
|
||||
bool isRunning() { return _running; }
|
||||
virtual bool isCranking() { return false; }
|
||||
|
||||
virtual void calc(float pressure, float temp, float speed) = 0;
|
||||
virtual float getTorque() = 0;
|
||||
virtual float getFuelFlow() = 0;
|
||||
|
||||
protected:
|
||||
float _throttle;
|
||||
bool _starter; // true=engaged, false=disengaged
|
||||
int _magnetos; // 0=off, 1=right, 2=left, 3=both
|
||||
float _mixture;
|
||||
float _boost;
|
||||
bool _fuel;
|
||||
bool _running;
|
||||
};
|
||||
|
||||
}; // namespace yasim
|
||||
#endif // _ENGINE_HPP
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include "Math.hpp"
|
||||
#include "Jet.hpp"
|
||||
#include "SimpleJet.hpp"
|
||||
#include "Gear.hpp"
|
||||
|
@ -436,41 +437,43 @@ void FGFDM::setOutputProperties()
|
|||
for(i=0; i<_thrusters.size(); i++) {
|
||||
EngRec* er = (EngRec*)_thrusters.get(i);
|
||||
Thruster* t = er->eng;
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
|
||||
sprintf(buf, "%s/fuel-flow-gph", er->prefix);
|
||||
fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
|
||||
// Set: running, cranking, prop-thrust, max-hp, power-pct
|
||||
node->setBoolValue("running", t->isRunning());
|
||||
node->setBoolValue("cranking", t->isCranking());
|
||||
|
||||
float tmp[3];
|
||||
t->getThrust(tmp);
|
||||
float lbs = Math::mag3(tmp) * (KG2LBS/9.8);
|
||||
node->setFloatValue("prop-thrust", lbs); // Deprecated name
|
||||
node->setFloatValue("thrust-lbs", lbs);
|
||||
|
||||
node->setFloatValue("fuel-flow-gph",
|
||||
(t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
|
||||
|
||||
if(t->getPropEngine()) {
|
||||
PropEngine* p = t->getPropEngine();
|
||||
|
||||
sprintf(buf, "%s/rpm", er->prefix);
|
||||
fgSetFloat(buf, p->getOmega() / RPM2RAD);
|
||||
}
|
||||
|
||||
if(t->getPistonEngine()) {
|
||||
PistonEngine* p = t->getPistonEngine();
|
||||
|
||||
sprintf(buf, "%s/mp-osi", er->prefix);
|
||||
fgSetFloat(buf, p->getMP() * (1/INHG2PA));
|
||||
|
||||
sprintf(buf, "%s/egt-degf", er->prefix);
|
||||
fgSetFloat(buf, p->getEGT() * K2DEGF + K2DEGFOFFSET);
|
||||
node->setFloatValue("rpm", p->getOmega() * (1/RPM2RAD));
|
||||
|
||||
if(p->getEngine()->isPistonEngine()) {
|
||||
PistonEngine* pe = p->getEngine()->isPistonEngine();
|
||||
node->setFloatValue("mp-osi", pe->getMP() * (1/INHG2PA));
|
||||
node->setFloatValue("mp-inhg", pe->getMP() * (1/INHG2PA));
|
||||
node->setFloatValue("egt-degf",
|
||||
pe->getEGT() * K2DEGF + K2DEGFOFFSET);
|
||||
// } else if(p->isTurbineEngine()) {
|
||||
// TurbineEngine* te = p->isTurbineEngine();
|
||||
}
|
||||
}
|
||||
|
||||
if(t->getJet()) {
|
||||
Jet* j = t->getJet();
|
||||
|
||||
sprintf(buf, "%s/n1", er->prefix);
|
||||
fgSetFloat(buf, j->getN1());
|
||||
|
||||
sprintf(buf, "%s/n2", er->prefix);
|
||||
fgSetFloat(buf, j->getN2());
|
||||
|
||||
sprintf(buf, "%s/epr", er->prefix);
|
||||
fgSetFloat(buf, j->getEPR());
|
||||
|
||||
sprintf(buf, "%s/egt-degf", er->prefix);
|
||||
fgSetFloat(buf, j->getEGT() * K2DEGF + K2DEGFOFFSET);
|
||||
node->setFloatValue("n1", j->getN1());
|
||||
node->setFloatValue("n2", j->getN2());
|
||||
node->setFloatValue("epr", j->getEPR());
|
||||
node->setFloatValue("egr-degf",
|
||||
j->getEGT() * K2DEGF + K2DEGFOFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,41 +68,6 @@ float PistonEngine::getMaxPower()
|
|||
return _power0;
|
||||
}
|
||||
|
||||
void PistonEngine::setThrottle(float t)
|
||||
{
|
||||
_throttle = t;
|
||||
}
|
||||
|
||||
void PistonEngine::setRunning(bool r)
|
||||
{
|
||||
_running = r;
|
||||
}
|
||||
|
||||
void PistonEngine::setStarter(bool s)
|
||||
{
|
||||
_cranking = s;
|
||||
}
|
||||
|
||||
void PistonEngine::setMagnetos(int m)
|
||||
{
|
||||
_magnetos = m;
|
||||
}
|
||||
|
||||
void PistonEngine::setMixture(float m)
|
||||
{
|
||||
_mixture = m;
|
||||
}
|
||||
|
||||
void PistonEngine::setBoost(float boost)
|
||||
{
|
||||
_boost = boost;
|
||||
}
|
||||
|
||||
bool PistonEngine::isRunning()
|
||||
{
|
||||
return _running;
|
||||
}
|
||||
|
||||
bool PistonEngine::isCranking()
|
||||
{
|
||||
return _cranking;
|
||||
|
|
|
@ -1,35 +1,28 @@
|
|||
#ifndef _PISTONENGINE_HPP
|
||||
#define _PISTONENGINE_HPP
|
||||
|
||||
#include "Engine.hpp"
|
||||
|
||||
namespace yasim {
|
||||
|
||||
class PistonEngine {
|
||||
class PistonEngine : public Engine {
|
||||
public:
|
||||
virtual PistonEngine* isPistonEngine() { return this; }
|
||||
|
||||
// Initializes an engine from known "takeoff" parameters.
|
||||
PistonEngine(float power, float spd);
|
||||
void setTurboParams(float mul, float maxMP);
|
||||
void setDisplacement(float d);
|
||||
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
|
||||
void setFuelState(bool hasFuel) { _fuel = hasFuel; }
|
||||
|
||||
// For solver use
|
||||
void setRunning(bool r);
|
||||
|
||||
float getMaxPower(); // max sea-level power
|
||||
|
||||
void calc(float pressure, float temp, float speed);
|
||||
bool isRunning();
|
||||
bool isCranking();
|
||||
float getTorque();
|
||||
float getFuelFlow();
|
||||
float getMP();
|
||||
float getEGT();
|
||||
float getMaxPower(); // max sea-level power
|
||||
|
||||
virtual void calc(float pressure, float temp, float speed);
|
||||
virtual float getTorque();
|
||||
virtual float getFuelFlow();
|
||||
|
||||
private:
|
||||
// Static configuration:
|
||||
|
@ -43,16 +36,7 @@ private:
|
|||
float _displacement; // piston stroke volume
|
||||
float _compression; // compression ratio (>1)
|
||||
|
||||
// Runtime settables:
|
||||
float _throttle;
|
||||
bool _starter; // true=engaged, false=disengaged
|
||||
int _magnetos; // 0=off, 1=right, 2=left, 3=both
|
||||
float _mixture;
|
||||
float _boost;
|
||||
bool _fuel;
|
||||
|
||||
// Runtime state/output:
|
||||
bool _running;
|
||||
bool _cranking;
|
||||
float _mp;
|
||||
float _torque;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "Math.hpp"
|
||||
#include "Propeller.hpp"
|
||||
#include "PistonEngine.hpp"
|
||||
#include "Engine.hpp"
|
||||
#include "PropEngine.hpp"
|
||||
namespace yasim {
|
||||
|
||||
PropEngine::PropEngine(Propeller* prop, PistonEngine* eng, float moment)
|
||||
PropEngine::PropEngine(Propeller* prop, Engine* eng, float moment)
|
||||
{
|
||||
// Start off at 500rpm, because the start code doesn't exist yet
|
||||
_omega = 52.3f;
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
namespace yasim {
|
||||
|
||||
class Propeller;
|
||||
class PistonEngine;
|
||||
class Engine;
|
||||
|
||||
class PropEngine : public Thruster {
|
||||
public:
|
||||
PropEngine(Propeller* prop, PistonEngine* eng, float moment);
|
||||
PropEngine(Propeller* prop, Engine* eng, float moment);
|
||||
virtual ~PropEngine();
|
||||
|
||||
void setMagnetos(int magnetos);
|
||||
|
@ -20,7 +20,7 @@ public:
|
|||
void setGearRatio(float ratio) { _gearRatio = ratio; }
|
||||
|
||||
virtual PropEngine* getPropEngine() { return this; }
|
||||
virtual PistonEngine* getPistonEngine() { return _eng; }
|
||||
virtual Engine* getEngine() { return _eng; }
|
||||
virtual Propeller* getPropeller() { return _prop; }
|
||||
|
||||
// Dynamic output
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
private:
|
||||
float _moment;
|
||||
Propeller* _prop;
|
||||
PistonEngine* _eng;
|
||||
Engine* _eng;
|
||||
|
||||
bool _variable;
|
||||
int _magnetos; // 0=off, 1=right, 2=left, 3=both
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace yasim {
|
|||
class Jet;
|
||||
class PropEngine;
|
||||
class Propeller;
|
||||
class PistonEngine;
|
||||
class Engine;
|
||||
|
||||
class Thruster {
|
||||
public:
|
||||
|
@ -19,7 +19,7 @@ public:
|
|||
virtual Jet* getJet() { return 0; }
|
||||
virtual PropEngine* getPropEngine() { return 0; }
|
||||
virtual Propeller* getPropeller() { return 0; }
|
||||
virtual PistonEngine* getPistonEngine() { return 0; }
|
||||
virtual Engine* getEngine() { return 0; }
|
||||
|
||||
// Static data
|
||||
void getPosition(float* out);
|
||||
|
|
|
@ -443,28 +443,4 @@ void YASim::copyFromYASim()
|
|||
node->setBoolValue("wow", g->getCompressFraction() != 0);
|
||||
node->setFloatValue("compression-norm", g->getCompressFraction());
|
||||
}
|
||||
|
||||
for(i=0; i<model->numThrusters(); i++) {
|
||||
SGPropertyNode * node = fgGetNode("engines/engine", i, true);
|
||||
Thruster* t = model->getThruster(i);
|
||||
|
||||
node->setBoolValue("running", t->isRunning());
|
||||
node->setBoolValue("cranking", t->isCranking());
|
||||
|
||||
float tmp[3];
|
||||
t->getThrust(tmp);
|
||||
node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);
|
||||
|
||||
PropEngine* pe = t->getPropEngine();
|
||||
if(pe) {
|
||||
node->setDoubleValue("rpm", pe->getOmega() * RAD2RPM);
|
||||
|
||||
pe->getTorque(tmp);
|
||||
float power = Math::mag3(tmp) * pe->getOmega();
|
||||
float maxPower = pe->getPistonEngine()->getMaxPower();
|
||||
|
||||
node->setDoubleValue("max-hp", maxPower * W2HP);
|
||||
node->setDoubleValue("power-pct", 100 * power/maxPower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ bool fgSetFloat (const char * name, float val) { return false; }
|
|||
bool fgSetBool(char const * name, bool val) { return false; }
|
||||
bool fgGetBool(char const * name, bool def) { return false; }
|
||||
SGPropertyNode* fgGetNode (const char * path, bool create) { return 0; }
|
||||
SGPropertyNode* fgGetNode (const char * path, int i, bool create) { return 0; }
|
||||
float fgGetFloat (const char * name, float defaultValue) { return 0; }
|
||||
float fgGetDouble (const char * name, double defaultValue) { return 0; }
|
||||
float fgSetDouble (const char * name, double defaultValue) { return 0; }
|
||||
|
|
Loading…
Add table
Reference in a new issue