]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Propeller.cpp
Add support for a turbo prop condition lever.
[flightgear.git] / src / FDM / YASim / Propeller.cpp
1 #include <stdio.h>
2
3 #include "Atmosphere.hpp"
4 #include "Math.hpp"
5 #include "Propeller.hpp"
6 namespace yasim {
7
8 Propeller::Propeller(float radius, float v, float omega,
9                      float rho, float power)
10 {
11     // Initialize numeric constants:
12     _lambdaPeak = Math::pow(5.0, -1.0/4.0);
13     _beta = 1.0f/(Math::pow(5.0f, -1.0f/4.0f) - Math::pow(5.0f, -5.0f/4.0f));
14
15     _r = radius;
16     _etaC = 0.85f; // make this settable?
17
18     _j0 = v/(omega*_lambdaPeak);
19     _baseJ0 = _j0;
20
21     float V2 = v*v + (_r*omega)*(_r*omega);
22     _f0 = 2*_etaC*power/(rho*v*V2);
23
24     _matchTakeoff = false;
25     _manual = false;
26     _proppitch = 0;
27     _propfeather = 0;
28 }
29
30 void Propeller::setTakeoff(float omega0, float power0)
31 {
32     // Takeoff thrust coefficient at lambda==0
33     _matchTakeoff = true;
34     float V2 = _r*omega0 * _r*omega0;
35     float gamma = _etaC * _beta / _j0;
36     float torque = power0 / omega0;
37     float density = Atmosphere::getStdDensity(0);
38     _tc0 = (torque * gamma) / (0.5f * density * V2 * _f0);
39 }
40     
41 void Propeller::modPitch(float mod)
42 {
43     _j0 *= mod;
44     if(_j0 < 0.25f*_baseJ0) _j0 = 0.25f*_baseJ0;
45     if(_j0 > 4*_baseJ0)     _j0 = 4*_baseJ0;
46 }
47
48 void Propeller::setManualPitch()
49 {
50     _manual = true;
51 }
52
53 void Propeller::setPropPitch(float proppitch)
54 {
55     // makes only positive range of axis effective.
56     _proppitch = Math::clamp(proppitch, 0, 1);
57 }
58
59 void Propeller::setPropFeather(int state)
60 {
61     // 0 = normal, 1 = feathered
62     _propfeather = (state != 0);
63 }
64
65 void Propeller::calc(float density, float v, float omega,
66                      float* thrustOut, float* torqueOut)
67 {
68     // For manual pitch, exponentially modulate the J0 value between
69     // 0.25 and 4.  A prop pitch of 0.5 results in no change from the
70     // base value.
71     if (_manual) 
72         _j0 = _baseJ0 * Math::pow(2, 2 - 4*_proppitch);
73     
74     float tipspd = _r*omega;
75     float V2 = v*v + tipspd*tipspd;
76
77     // Sanify
78     if(v < 0) v = 0;
79     if(omega < 0.001) omega = 0.001;
80
81     float J = v/omega;    // Advance ratio
82     float lambda = J/_j0; // Unitless scalar advance ratio
83
84     // There's an undefined point at lambda == 1.
85     if(lambda == 1.0f) lambda = 0.9999f;
86
87     float l4 = lambda*lambda; l4 = l4*l4;   // lambda^4
88     float gamma = (_etaC*_beta/_j0)*(1-l4); // thrust/torque ratio
89
90     // Compute a thrust coefficient, with clamping at very low
91     // lambdas (fast propeller / slow aircraft).
92     float tc = (1 - lambda) / (1 - _lambdaPeak);
93     if(_matchTakeoff && tc > _tc0) tc = _tc0;
94
95     float thrust = 0.5f * density * V2 * _f0 * tc;
96     float torque = thrust/gamma;
97     if(lambda > 1) {
98         // This is the negative thrust / windmilling regime.  Throw
99         // out the efficiency graph approach and instead simply
100         // extrapolate the existing linear thrust coefficient and a
101         // torque coefficient that crosses the axis at a preset
102         // windmilling speed.  The tau0 value is an analytically
103         // calculated (i.e. don't mess with it) value for a torque
104         // coefficient at lamda==1.
105         float tau0 = (0.25f * _j0) / (_etaC * _beta * (1 - _lambdaPeak));
106         float lambdaWM = 1.2f; // lambda of zero torque (windmilling)
107         torque = tau0 - tau0 * (lambda - 1) / (lambdaWM - 1);
108         torque *= 0.5f * density * V2 * _f0;
109     }
110
111     *thrustOut = thrust;
112     *torqueOut = torque;
113 }
114
115 }; // namespace yasim