2 #include "Propeller.hpp"
3 #include "PistonEngine.hpp"
4 #include "PropEngine.hpp"
7 PropEngine::PropEngine(Propeller* prop, PistonEngine* eng, float moment)
9 // Start off at 500rpm, because the start code doesn't exist yet
11 _dir[0] = 1; _dir[1] = 0; _dir[2] = 0;
18 PropEngine::~PropEngine()
24 float PropEngine::getOmega()
29 Thruster* PropEngine::clone()
32 PropEngine* p = new PropEngine(_prop, _eng, _moment);
34 p->_prop = new Propeller(*_prop);
35 p->_eng = new PistonEngine(*_eng);
39 void PropEngine::getThrust(float* out)
41 for(int i=0; i<3; i++) out[i] = _thrust[i];
44 void PropEngine::getTorque(float* out)
46 for(int i=0; i<3; i++) out[i] = _torque[i];
49 void PropEngine::getGyro(float* out)
51 for(int i=0; i<3; i++) out[i] = _gyro[i];
54 float PropEngine::getFuelFlow()
59 void PropEngine::integrate(float dt)
61 float speed = -Math::dot3(_wind, _dir);
63 float propTorque, engTorque, thrust;
65 _eng->setThrottle(_throttle);
66 _eng->setMixture(_mixture);
68 _prop->calc(_rho, speed, _omega,
69 &thrust, &propTorque);
70 _eng->calc(_rho, _omega, &engTorque, &_fuelFlow);
72 // Turn the thrust into a vector and save it
73 Math::mul3(thrust, _dir, _thrust);
75 // Euler-integrate the RPM. This doesn't need the full-on
77 _omega += dt*(engTorque-propTorque)/Math::abs(_moment);
79 // FIXME: Integrate the propeller governor here, when that gets
82 // Store the total angular momentum into _gyro
83 Math::mul3(_omega*_moment, _dir, _gyro);
85 // Accumulate the engine torque, it acta on the body as a whole.
86 // (Note: engine torque, not propeller torque. They can be
87 // different, but the difference goes to accelerating the
88 // rotation. It is the engine torque that is felt at the shaft
89 // and works on the body.)
90 float tau = _moment < 0 ? engTorque : -engTorque;
91 Math::mul3(tau, _dir, _torque);