_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);
}
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;
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();
}
// 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);
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;
}
}
+ float fuelDensity = _airplane.getFuelDensity(0); // HACK
for(i=0; i<_thrusters.size(); i++) {
EngRec* er = (EngRec*)_thrusters.get(i);
Thruster* t = er->eng;