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