]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/PropEngine.cpp
Initial revision of Andy Ross's YASim code. This is (Y)et (A)nother Flight
[flightgear.git] / src / FDM / YASim / PropEngine.cpp
1 #include "Math.hpp"
2 #include "Propeller.hpp"
3 #include "PistonEngine.hpp"
4 #include "PropEngine.hpp"
5 namespace yasim {
6
7 PropEngine::PropEngine(Propeller* prop, PistonEngine* eng, float moment)
8 {
9     // Start off at 500rpm, because the start code doesn't exist yet
10     _omega = 52.3;
11     _dir[0] = 1; _dir[1] = 0; _dir[2] = 0;
12
13     _prop = prop;
14     _eng = eng;
15     _moment = moment;
16 }
17
18 PropEngine::~PropEngine()
19 {
20     delete _prop;
21     delete _eng;
22 }
23
24 float PropEngine::getOmega()
25 {
26     return _omega;
27 }
28
29 Thruster* PropEngine::clone()
30 {
31     // FIXME: bloody mess
32     PropEngine* p = new PropEngine(_prop, _eng, _moment);
33     cloneInto(p);
34     p->_prop = new Propeller(*_prop);
35     p->_eng = new PistonEngine(*_eng);
36     return p;
37 }
38
39 void PropEngine::getThrust(float* out)
40 {
41     for(int i=0; i<3; i++) out[i] = _thrust[i];    
42 }
43
44 void PropEngine::getTorque(float* out)
45 {
46     for(int i=0; i<3; i++) out[i] = _torque[i];
47 }
48
49 void PropEngine::getGyro(float* out)
50 {
51     for(int i=0; i<3; i++) out[i] = _gyro[i];
52 }
53
54 float PropEngine::getFuelFlow()
55 {
56     return _fuelFlow;
57 }
58
59 void PropEngine::integrate(float dt)
60 {
61     float speed = -Math::dot3(_wind, _dir);
62
63     float propTorque, engTorque, thrust;
64
65     _eng->setThrottle(_throttle);
66     _eng->setMixture(_mixture);
67     
68     _prop->calc(_rho, speed, _omega,
69                 &thrust, &propTorque);
70     _eng->calc(_rho, _omega, &engTorque, &_fuelFlow);
71
72     // Turn the thrust into a vector and save it
73     Math::mul3(thrust, _dir, _thrust);
74
75     // Euler-integrate the RPM.  This doesn't need the full-on
76     // Runge-Kutta stuff.
77     _omega += dt*(engTorque-propTorque)/Math::abs(_moment);
78
79     // FIXME: Integrate the propeller governor here, when that gets
80     // implemented...
81
82     // Store the total angular momentum into _gyro
83     Math::mul3(_omega*_moment, _dir, _gyro);
84
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);
92 }
93
94 }; // namespace yasim