]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropeller.cpp
Removed FGMatrix.* because it is no longer used by 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 // This class currently makes certain assumptions when calculating torque and 
49 // p-factor. That is, that the axis of rotation is the X axis of the aircraft -
50 // not just the X-axis of the engine/propeller. This may or may not work for a 
51 // helicopter.
52
53 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
54 {
55   string token;
56   int rows, cols;
57
58   MaxPitch = MinPitch = P_Factor = Sense = Pitch = 0.0;
59
60   Name = Prop_cfg->GetValue("NAME");
61   Prop_cfg->GetNextConfigLine();
62   while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
63     *Prop_cfg >> token;
64     if (token == "IXX") {
65       *Prop_cfg >> Ixx;
66     } else if (token == "DIAMETER") {
67       *Prop_cfg >> Diameter;
68       Diameter /= 12.0;
69     } else if (token == "NUMBLADES") {
70       *Prop_cfg >> numBlades;
71     } else if (token == "MINPITCH") {
72       *Prop_cfg >> MinPitch;
73     } else if (token == "MAXPITCH") {
74       *Prop_cfg >> MaxPitch;
75     } else if (token == "MINRPM") {
76       *Prop_cfg >> MinRPM;
77     } else if (token == "MAXRPM") {
78       *Prop_cfg >> MaxRPM;
79     } else if (token == "C_THRUST") {
80       *Prop_cfg >> rows >> cols;
81       if (cols == 1) cThrust = new FGTable(rows);
82       else           cThrust = new FGTable(rows, cols);
83       *cThrust << *Prop_cfg;
84     } else if (token == "C_POWER") {
85       *Prop_cfg >> rows >> cols;
86       if (cols == 1) cPower = new FGTable(rows);
87       else           cPower = new FGTable(rows, cols);
88       *cPower << *Prop_cfg;
89     } else if (token == "EOF") {
90       cerr << "      End of file reached" <<  endl;
91       break;
92     } else {
93       cerr << "Unhandled token in Propeller config file: " << token << endl;
94     }
95   }
96
97   Type = ttPropeller;
98   RPM = 0;
99   vTorque.InitMatrix();
100
101   Debug(0);
102 }
103
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106 FGPropeller::~FGPropeller()
107 {
108   if (cThrust)    delete cThrust;
109   if (cPower)     delete cPower;
110   Debug(1);
111 }
112
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 //
115 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
116 // We need the velocity with respect to the wind.
117 //
118 // Note that PowerAvailable is the excess power available after the drag of the
119 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
120 // indicating that the propeller will not accelerate or decelerate.
121 // Remembering that Torque * omega = Power, we can derive the torque on the
122 // propeller and its acceleration to give a new RPM. The current RPM will be
123 // used to calculate thrust.
124 //
125 // Because RPM could be zero, we need to be creative about what RPM is stated as.
126
127 double FGPropeller::Calculate(double PowerAvailable)
128 {
129   double J, C_Thrust, omega;
130   double Vel = fdmex->GetTranslation()->GetvAeroUVW(eU);
131   double rho = fdmex->GetAtmosphere()->GetDensity();
132   double RPS = RPM/60.0;
133   double alpha, beta;
134
135   if (RPM > 0.10) {
136     J = Vel / (Diameter * RPS);
137   } else {
138     J = 0.0;
139   }
140
141   if (MaxPitch == MinPitch) { // Fixed pitch prop
142     C_Thrust = cThrust->GetValue(J);
143   } else {                    // Variable pitch prop
144     C_Thrust = cThrust->GetValue(J, Pitch);
145   }
146
147   if (P_Factor > 0.0001) {
148     alpha = fdmex->GetTranslation()->Getalpha();
149     beta  = fdmex->GetTranslation()->Getbeta();
150     SetActingLocationY( GetLocationY() + P_Factor*alpha*Sense);
151     SetActingLocationZ( GetLocationZ() + P_Factor*beta*Sense);
152   } else if (P_Factor < 0.000) {
153     cerr << "P-Factor value in config file must be greater than zero" << endl;
154   }
155
156   Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
157   omega = RPS*2.0*M_PI;
158
159   // Check for windmilling.
160   double radius = Diameter * 0.375; // 75% of radius
161   double windmill_cutoff = tan(Pitch * 1.745329E-2) * omega * radius;
162   if (Vel > windmill_cutoff)
163     Thrust = -Thrust;
164
165   vFn(1) = Thrust;
166
167   // The Ixx value and rotation speed given below are for rotation about the
168   // natural axis of the engine. The transform takes place in the base class
169   // FGForce::GetBodyForces() function.
170
171   vH(eX) = Ixx*omega*Sense;
172   vH(eY) = 0.0;
173   vH(eZ) = 0.0;
174
175   if (omega <= 5) omega = 1.0;
176
177   ExcessTorque = PowerAvailable / omega;
178   RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
179
180   vMn = fdmex->GetRotation()->GetPQR()*vH + vTorque*Sense;
181
182   return Thrust; // return thrust in pounds
183 }
184
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186
187 double FGPropeller::GetPowerRequired(void)
188 {
189   if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
190
191   double cPReq, RPS = RPM / 60.0;
192
193   double J = fdmex->GetTranslation()->GetvAeroUVW(eU) / (Diameter * RPS);
194   double rho = fdmex->GetAtmosphere()->GetDensity();
195
196   if (MaxPitch == MinPitch) { // Fixed pitch prop
197     Pitch = MinPitch;
198     cPReq = cPower->GetValue(J);
199   } else {                    // Variable pitch prop
200     double advance = fdmex->GetFCS()->GetPropAdvance(ThrusterNumber);
201
202     if (MaxRPM != MinRPM) {   // fixed-speed prop
203       double rpmReq = MinRPM + (MaxRPM - MinRPM) * advance;
204       double dRPM = rpmReq - RPM;
205
206       Pitch -= dRPM / 10;
207
208       if (Pitch < MinPitch)       Pitch = MinPitch;
209       else if (Pitch > MaxPitch)  Pitch = MaxPitch;
210
211     } else {
212       Pitch = MaxPitch - (MaxPitch - MinPitch) * advance;
213     }
214     cPReq = cPower->GetValue(J, Pitch);
215   }
216
217   PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
218                                                        *Diameter*rho;
219   vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
220
221   return PowerRequired;
222 }
223
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225
226 FGColumnVector3 FGPropeller::GetPFactor()
227 {
228   double px=0.0, py, pz;
229
230   py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
231   pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
232
233   return FGColumnVector3(px, py, pz);
234 }
235
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 //    The bitmasked value choices are as follows:
238 //    unset: In this case (the default) JSBSim would only print
239 //       out the normally expected messages, essentially echoing
240 //       the config files as they are read. If the environment
241 //       variable is not set, debug_lvl is set to 1 internally
242 //    0: This requests JSBSim not to output any messages
243 //       whatsoever.
244 //    1: This value explicity requests the normal JSBSim
245 //       startup messages
246 //    2: This value asks for a message to be printed out when
247 //       a class is instantiated
248 //    4: When this value is set, a message is displayed when a
249 //       FGModel object executes its Run() method
250 //    8: When this value is set, various runtime state variables
251 //       are printed out periodically
252 //    16: When set various parameters are sanity checked and
253 //       a message is printed out when they go out of bounds
254
255 void FGPropeller::Debug(int from)
256 {
257   if (debug_lvl <= 0) return;
258
259   if (debug_lvl & 1) { // Standard console startup message output
260     if (from == 0) { // Constructor
261       cout << "\n    Propeller Name: " << Name << endl;
262       cout << "      IXX = " << Ixx << endl;
263       cout << "      Diameter = " << Diameter << " ft." << endl;
264       cout << "      Number of Blades  = " << numBlades << endl;
265       cout << "      Minimum Pitch  = " << MinPitch << endl;
266       cout << "      Maximum Pitch  = " << MaxPitch << endl;
267       cout << "      Thrust Coefficient: " <<  endl;
268       cThrust->Print();
269       cout << "      Power Coefficient: " <<  endl;
270       cPower->Print();
271     }
272   }
273   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
274     if (from == 0) cout << "Instantiated: FGPropeller" << endl;
275     if (from == 1) cout << "Destroyed:    FGPropeller" << endl;
276   }
277   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
278   }
279   if (debug_lvl & 8 ) { // Runtime state variables
280   }
281   if (debug_lvl & 16) { // Sanity checking
282   }
283   if (debug_lvl & 64) {
284     if (from == 0) { // Constructor
285       cout << IdSrc << endl;
286       cout << IdHdr << endl;
287     }
288   }
289 }
290