1 #include "PistonEngine.hpp"
4 PistonEngine::PistonEngine(float power, float speed)
6 // Presume a BSFC (in lb/hour per HP) of 0.45. In SI that becomes
7 // (2.2 lb/kg, 745.7 W/hp, 3600 sec/hour) 3.69e-07 kg/Ws.
8 _f0 = power * 3.69e-07;
13 // We must be at sea level under standard conditions
14 _rho0 = 1.225; // kg/m^3
16 // Further presume that takeoff is (duh) full throttle and
17 // peak-power, that means that by our efficiency function, we are
18 // at 11/8 of "ideal" fuel flow.
19 float realFlow = _f0 * (11.0/8.0);
20 _mixCoeff = realFlow * 1.1 / _omega0;
23 void PistonEngine::setThrottle(float t)
28 void PistonEngine::setMixture(float m)
33 void PistonEngine::calc(float density, float speed,
34 float* torqueOut, float* fuelFlowOut)
36 // The actual fuel flow
37 float fuel = _mixture * _mixCoeff * speed;
39 // manifold air density
40 float rho = density * _throttle;
42 // How much fuel could be burned with ideal (i.e. uncorrected!)
44 float burnable = _f0 * (rho/_rho0) * (speed/_omega0);
46 // Calculate the fuel that actually burns to produce work. The
47 // idea is that less than 5/8 of ideal, we get complete
48 // combustion. We use up all the oxygen at 1 3/8 of ideal (that
49 // is, you need to waste fuel to use all your O2). In between,
50 // interpolate. This vaguely matches a curve I copied out of a
51 // book for a single engine. Shrug.
53 float r = fuel/burnable;
54 if (burnable == 0) burned = 0;
55 else if(r < .625) burned = fuel;
56 else if(r > 1.375) burned = burnable;
57 else burned = fuel + (burnable-fuel)*(r-.625)*(4.0/3.0);
59 // And finally the power is just the reference power scaled by the
60 // amount of fuel burned.
61 float power = _P0 * burned/_f0;
63 *torqueOut = power/speed;