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