1
0
Fork 0

YASim now supports the new fuel.nas fuel management system. It

reads the /consumables tree for input to determine weights, but
places output only in /engines/engine[n]/fuel-consumed-lbs where
it gets picked up by the Nasal code.
This commit is contained in:
andy 2004-03-27 04:07:18 +00:00
parent 17b6142a76
commit c62048d5e2
4 changed files with 50 additions and 46 deletions

View file

@ -78,32 +78,9 @@ void Airplane::iterate(float dt)
_model.iterate();
}
void Airplane::consumeFuel(float dt)
void Airplane::calcFuelWeights()
{
// This is a really simple implementation that assumes all engines
// draw equally from all tanks in proportion to the amount of fuel
// stored there. Needs to be fixed, but that has to wait for a
// decision as to what the property interface will look like.
int i, outOfFuel = 0;
float fuelFlow = 0, totalFuel = 0.00001; // <-- overflow protection
for(i=0; i<_thrusters.size(); i++)
fuelFlow += ((ThrustRec*)_thrusters.get(i))->thruster->getFuelFlow();
for(i=0; i<_tanks.size(); i++)
totalFuel += ((Tank*)_tanks.get(i))->fill;
for(i=0; i<_tanks.size(); i++) {
Tank* t = (Tank*)_tanks.get(i);
t->fill -= dt * fuelFlow * (t->fill/totalFuel);
if(t->fill <= 0) {
t->fill = 0;
outOfFuel = 1;
}
}
if(outOfFuel)
for(int i=0; i<_thrusters.size(); i++)
((ThrustRec*)_thrusters.get(i))->thruster->setFuelState(false);
// Set the tank masses on the RigidBody
for(i=0; i<_tanks.size(); i++) {
for(int i=0; i<_tanks.size(); i++) {
Tank* t = (Tank*)_tanks.get(i);
_model.getBody()->setMass(t->handle, t->fill);
}
@ -233,6 +210,11 @@ float Airplane::getFuel(int tank)
return ((Tank*)_tanks.get(tank))->fill;
}
float Airplane::setFuel(int tank, float fuel)
{
((Tank*)_tanks.get(tank))->fill = fuel;
}
float Airplane::getFuelDensity(int tank)
{
return ((Tank*)_tanks.get(tank))->density;

View file

@ -18,7 +18,7 @@ public:
~Airplane();
void iterate(float dt);
void consumeFuel(float dt);
void calcFuelWeights();
ControlMap* getControlMap();
Model* getModel();
@ -60,9 +60,14 @@ public:
int numGear();
Gear* getGear(int g);
int numThrusters() { return _thrusters.size(); }
Thruster* getThruster(int n) {
return ((ThrustRec*)_thrusters.get(n))->thruster; }
int numTanks();
void setFuelFraction(float frac); // 0-1, total amount of fuel
float getFuel(int tank); // in kg!
float setFuel(int tank, float fuel); // in kg!
float getFuelDensity(int tank); // kg/m^3
float getTankCapacity(int tank);

View file

@ -82,9 +82,24 @@ void FGFDM::iterate(float dt)
getExternalInput(dt);
_airplane.iterate(dt);
if(fgGetBool("/sim/freeze/fuel") != true)
_airplane.consumeFuel(dt);
// Do fuel stuff (FIXME: should stash SGPropertyNode objects here)
char buf[256];
for(int i=0; i<_airplane.numThrusters(); i++) {
Thruster* t = _airplane.getThruster(i);
sprintf(buf, "/engines/engine[%d]/out-of-fuel", i);
t->setFuelState(!fgGetBool(buf));
sprintf(buf, "/engines/engine[%d]/fuel-consumed-lbs", i);
double consumed = fgGetDouble(buf) + dt * t->getFuelFlow();
fgSetDouble(buf, consumed);
}
for(int i=0; i<_airplane.numTanks(); i++) {
sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
_airplane.setFuel(i, LBS2KG * fgGetFloat(buf));
}
_airplane.calcFuelWeights();
setOutputProperties();
}
@ -98,6 +113,23 @@ void FGFDM::init()
// Allows the user to start with something other than full fuel
_airplane.setFuelFraction(fgGetFloat("/sim/fuel-fraction", 1));
// Read out the resulting fuel state
char buf[256];
for(int i=0; i<_airplane.numTanks(); i++) {
sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
fgSetDouble(buf, _airplane.getFuel(i) * KG2LBS);
double density = _airplane.getFuelDensity(i);
sprintf(buf, "/consumables/fuel/tank[%d]/density-ppg", i);
fgSetDouble(buf, density * (KG2LBS/CM2GALS));
sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
fgSetDouble(buf, _airplane.getFuel(i) * CM2GALS / density);
sprintf(buf, "/consumables/fuel/tank[%d]/capacity-gal_us", i);
fgSetDouble(buf, CM2GALS * _airplane.getTankCapacity(i)/density);
}
// This has a nasty habit of being false at startup. That's not
// good.
fgSetBool("/controls/gear/gear-down", true);
@ -372,24 +404,6 @@ void FGFDM::setOutputProperties()
p->prop->setFloatValue(val);
}
float totalFuel = 0, totalCap = 0;
float fuelDensity = 720; // in kg/m^3, default to gasoline: ~6 lb/gal
for(i=0; i<_airplane.numTanks(); i++) {
fuelDensity = _airplane.getFuelDensity(i);
sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
fgSetFloat(buf, CM2GALS*_airplane.getFuel(i)/fuelDensity);
sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
fgSetFloat(buf, KG2LBS*_airplane.getFuel(i));
totalFuel += _airplane.getFuel(i);
totalCap += _airplane.getTankCapacity(i);
}
if(totalCap != 0) {
fgSetFloat("/consumables/fuel/total-fuel-lbs", KG2LBS*totalFuel);
fgSetFloat("/consumables/fuel/total-fuel-gals",
CM2GALS*totalFuel/fuelDensity);
fgSetFloat("/consumables/fuel/total-fuel-norm", totalFuel/totalCap);
}
for(i=0; i<_airplane.getNumRotors(); i++) {
Rotor*r=(Rotor*)_airplane.getRotor(i);
int j = 0;
@ -418,6 +432,7 @@ void FGFDM::setOutputProperties()
}
}
float fuelDensity = _airplane.getFuelDensity(0); // HACK
for(i=0; i<_thrusters.size(); i++) {
EngRec* er = (EngRec*)_thrusters.get(i);
Thruster* t = er->eng;

View file

@ -14,6 +14,8 @@ 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; }
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; }
static const float RAD2DEG = 57.2957795131;