]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropeller.cpp
Syncing with most recent JSBSim.
[flightgear.git] / src / FDM / JSBSim / FGPropeller.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGPropeller.cpp
4  Author:       Jon S. Berndt
5  Date started: 08/24/00
6  Purpose:      Encapsulates the propeller object
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 08/24/00  JSB  Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #include "FGPropeller.h"
39 #include "FGFCS.h"
40
41 static const char *IdSrc = "$Id$";
42 static const char *IdHdr = ID_PROPELLER;
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 CLASS IMPLEMENTATION
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48
49 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
50 {
51   string token;
52   int rows, cols;
53
54   MaxPitch = MinPitch = P_Factor = Sense = Pitch = 0.0;
55
56   Name = Prop_cfg->GetValue("NAME");
57   Prop_cfg->GetNextConfigLine();
58   while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
59     *Prop_cfg >> token;
60     if (token == "IXX") {
61       *Prop_cfg >> Ixx;
62     } else if (token == "DIAMETER") {
63       *Prop_cfg >> Diameter;
64       Diameter /= 12.0;
65     } else if (token == "NUMBLADES") {
66       *Prop_cfg >> numBlades;
67     } else if (token == "MINPITCH") {
68       *Prop_cfg >> MinPitch;
69     } else if (token == "MAXPITCH") {
70       *Prop_cfg >> MaxPitch;
71     } else if (token == "MINRPM") {
72       *Prop_cfg >> MinRPM;
73     } else if (token == "MAXRPM") {
74       *Prop_cfg >> MaxRPM;
75     } else if (token == "C_THRUST") {
76       *Prop_cfg >> rows >> cols;
77       if (cols == 1) cThrust = new FGTable(rows);
78       else           cThrust = new FGTable(rows, cols);
79       *cThrust << *Prop_cfg;
80     } else if (token == "C_POWER") {
81       *Prop_cfg >> rows >> cols;
82       if (cols == 1) cPower = new FGTable(rows);
83       else           cPower = new FGTable(rows, cols);
84       *cPower << *Prop_cfg;
85     } else if (token == "EOF") {
86       cerr << "      End of file reached" <<  endl;
87       break;
88     } else {
89       cerr << "Unhandled token in Propeller config file: " << token << endl;
90     }
91   }
92
93   if (debug_lvl > 0) {
94     cout << "\n    Propeller Name: " << Name << endl;
95     cout << "      IXX = " << Ixx << endl;
96     cout << "      Diameter = " << Diameter << " ft." << endl;
97     cout << "      Number of Blades  = " << numBlades << endl;
98     cout << "      Minimum Pitch  = " << MinPitch << endl;
99     cout << "      Maximum Pitch  = " << MaxPitch << endl;
100     cout << "      Thrust Coefficient: " <<  endl;
101     cThrust->Print();
102     cout << "      Power Coefficient: " <<  endl;
103     cPower->Print();
104   }
105
106   Type = ttPropeller;
107   RPM = 0;
108   vTorque.InitMatrix();
109
110   if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
111 }
112
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
115 FGPropeller::~FGPropeller()
116 {
117   if (cThrust)    delete cThrust;
118   if (cPower)     delete cPower;
119   if (debug_lvl & 2) cout << "Destroyed:    FGPropeller" << endl;
120 }
121
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 //
124 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
125 // We need the velocity with respect to the wind.
126 //
127 // Note that PowerAvailable is the excess power available after the drag of the
128 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
129 // indicating that the propeller will not accelerate or decelerate.
130 // Remembering that Torque * omega = Power, we can derive the torque on the
131 // propeller and its acceleration to give a new RPM. The current RPM will be
132 // used to calculate thrust.
133 //
134 // Because RPM could be zero, we need to be creative about what RPM is stated as.
135
136 double FGPropeller::Calculate(double PowerAvailable)
137 {
138   double J, C_Thrust, omega;
139   double Vel = fdmex->GetTranslation()->GetvAeroUVW(eU);
140   double rho = fdmex->GetAtmosphere()->GetDensity();
141   double RPS = RPM/60.0;
142   double alpha, beta;
143
144   if (RPM > 0.10) {
145     J = Vel / (Diameter * RPS);
146   } else {
147     J = 0.0;
148   }
149
150   if (MaxPitch == MinPitch) { // Fixed pitch prop
151     C_Thrust = cThrust->GetValue(J);
152   } else {                    // Variable pitch prop
153     C_Thrust = cThrust->GetValue(J, Pitch);
154   }
155
156   if (P_Factor > 0.0001) {
157     alpha = fdmex->GetTranslation()->Getalpha();
158     beta  = fdmex->GetTranslation()->Getbeta();
159     SetActingLocationY( GetLocationY() + P_Factor*alpha*fabs(Sense)/Sense);
160     SetActingLocationZ( GetLocationZ() + P_Factor*beta*fabs(Sense)/Sense);
161   } else if (P_Factor < 0.000) {
162     cerr << "P-Factor value in config file must be greater than zero" << endl;
163   }
164
165   Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
166   vFn(1) = Thrust;
167   omega = RPS*2.0*M_PI;
168
169   // The Ixx value and rotation speed given below are for rotation about the
170   // natural axis of the engine. The transform takes place in the base class
171   // FGForce::GetBodyForces() function.
172
173   vH(eX) = Ixx*omega*fabs(Sense)/Sense;
174   vH(eY) = 0.0;
175   vH(eZ) = 0.0;
176
177   if (omega <= 5) omega = 1.0;
178
179   ExcessTorque = PowerAvailable / omega;
180   RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
181
182   vMn = fdmex->GetRotation()->GetPQR()*vH + vTorque*Sense;
183
184   return Thrust; // return thrust in pounds
185 }
186
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188
189 double FGPropeller::GetPowerRequired(void)
190 {
191   if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
192
193   double cPReq, RPS = RPM / 60.0;
194
195   double J = fdmex->GetTranslation()->GetvAeroUVW(eU) / (Diameter * RPS);
196   double rho = fdmex->GetAtmosphere()->GetDensity();
197
198   if (MaxPitch == MinPitch) { // Fixed pitch prop
199     cPReq = cPower->GetValue(J);
200   } else {                    // Variable pitch prop
201     double advance = fdmex->GetFCS()->GetPropAdvance(ThrusterNumber);
202
203     if (MaxRPM != MinRPM) {   // fixed-speed prop
204       double rpmReq = MinRPM + (MaxRPM - MinRPM) * advance;
205       double dRPM = rpmReq - RPM;
206
207       Pitch -= dRPM / 10;
208
209       if (Pitch < MinPitch)       Pitch = MinPitch;
210       else if (Pitch > MaxPitch)  Pitch = MaxPitch;
211
212     } else {
213       Pitch = MaxPitch - (MaxPitch - MinPitch) * advance;
214     }
215     cPReq = cPower->GetValue(J, Pitch);
216   }
217
218   PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
219                                                        *Diameter*rho;
220   vTorque(eX) = PowerRequired / ((RPM/60)*2.0*M_PI);
221
222   return PowerRequired;
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 void FGPropeller::Debug(void)
228 {
229     //TODO: Add your source code here
230 }
231