]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/Propeller.cpp
Reverse the sense of manual propellers. Low numbers == fast
[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 }
28
29 void Propeller::setTakeoff(float omega0, float power0)
30 {
31     // Takeoff thrust coefficient at lambda==0
32     _matchTakeoff = true;
33     float V2 = _r*omega0 * _r*omega0;
34     float gamma = _etaC * _beta / _j0;
35     float torque = power0 / omega0;
36     float density = Atmosphere::getStdDensity(0);
37     _tc0 = (torque * gamma) / (0.5f * density * V2 * _f0);
38 }
39     
40 void Propeller::modPitch(float mod)
41 {
42     _j0 *= mod;
43     if(_j0 < 0.25f*_baseJ0) _j0 = 0.25f*_baseJ0;
44     if(_j0 > 4*_baseJ0)     _j0 = 4*_baseJ0;
45 }
46
47 void Propeller::setManualPitch()
48 {
49     _manual = true;
50 }
51
52 void Propeller::setPropPitch(float proppitch)
53 {
54     // makes only positive range of axis effective.
55     _proppitch = Math::clamp(proppitch, 0, 1);
56 }
57
58 void Propeller::calc(float density, float v, float omega,
59                      float* thrustOut, float* torqueOut)
60 {
61     // For manual pitch, exponentially modulate the J0 value between
62     // 0.25 and 4.  A prop pitch of 0.5 results in no change from the
63     // base value.
64     if (_manual) 
65         _j0 = _baseJ0 * Math::pow(2, 2 - 4*_proppitch);
66     
67     float tipspd = _r*omega;
68     float V2 = v*v + tipspd*tipspd;
69
70     // Sanify
71     if(v < 0) v = 0;
72     if(omega < 0.001) omega = 0.001;
73
74     float J = v/omega;    // Advance ratio
75     float lambda = J/_j0; // Unitless scalar advance ratio
76
77     // There's an undefined point at lambda == 1.
78     if(lambda == 1.0f) lambda = 0.9999f;
79
80     float l4 = lambda*lambda; l4 = l4*l4;   // lambda^4
81     float gamma = (_etaC*_beta/_j0)*(1-l4); // thrust/torque ratio
82
83     // Compute a thrust coefficient, with clamping at very low
84     // lambdas (fast propeller / slow aircraft).
85     float tc = (1 - lambda) / (1 - _lambdaPeak);
86     if(_matchTakeoff && tc > _tc0) tc = _tc0;
87
88     float thrust = 0.5f * density * V2 * _f0 * tc;
89     float torque = thrust/gamma;
90     if(lambda > 1) {
91         // This is the negative thrust / windmilling regime.  Throw
92         // out the efficiency graph approach and instead simply
93         // extrapolate the existing linear thrust coefficient and a
94         // torque coefficient that crosses the axis at a preset
95         // windmilling speed.  The tau0 value is an analytically
96         // calculated (i.e. don't mess with it) value for a torque
97         // coefficient at lamda==1.
98         float tau0 = (0.25f * _j0) / (_etaC * _beta * (1 - _lambdaPeak));
99         float lambdaWM = 1.2f; // lambda of zero torque (windmilling)
100         torque = tau0 - tau0 * (lambda - 1) / (lambdaWM - 1);
101         torque *= 0.5f * density * V2 * _f0;
102     }
103
104     *thrustOut = thrust;
105     *torqueOut = torque;
106 }
107
108 }; // namespace yasim