1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGPropeller.cpp
6 Purpose: Encapsulates the propeller object
8 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 #include "FGPropeller.h"
39 #include "FGTranslation.h"
40 #include "FGRotation.h"
42 #include "FGAtmosphere.h"
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_PROPELLER;
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 // This class currently makes certain assumptions when calculating torque and
54 // p-factor. That is, that the axis of rotation is the X axis of the aircraft -
55 // not just the X-axis of the engine/propeller. This may or may not work for a
58 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
63 MaxPitch = MinPitch = P_Factor = Sense = Pitch = 0.0;
66 Name = Prop_cfg->GetValue("NAME");
67 Prop_cfg->GetNextConfigLine();
68 while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
72 } else if (token == "DIAMETER") {
73 *Prop_cfg >> Diameter;
75 } else if (token == "NUMBLADES") {
76 *Prop_cfg >> numBlades;
77 } else if (token == "GEARRATIO") {
78 *Prop_cfg >> GearRatio;
79 } else if (token == "MINPITCH") {
80 *Prop_cfg >> MinPitch;
81 } else if (token == "MAXPITCH") {
82 *Prop_cfg >> MaxPitch;
83 } else if (token == "MINRPM") {
85 } else if (token == "MAXRPM") {
87 } else if (token == "C_THRUST") {
88 *Prop_cfg >> rows >> cols;
89 if (cols == 1) cThrust = new FGTable(rows);
90 else cThrust = new FGTable(rows, cols);
91 *cThrust << *Prop_cfg;
92 } else if (token == "C_POWER") {
93 *Prop_cfg >> rows >> cols;
94 if (cols == 1) cPower = new FGTable(rows);
95 else cPower = new FGTable(rows, cols);
97 } else if (token == "EOF") {
98 cerr << " End of file reached" << endl;
101 cerr << "Unhandled token in Propeller config file: " << token << endl;
107 vTorque.InitMatrix();
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 FGPropeller::~FGPropeller()
116 if (cThrust) delete cThrust;
117 if (cPower) delete cPower;
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
124 // We need the velocity with respect to the wind.
126 // Note that PowerAvailable is the excess power available after the drag of the
127 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
128 // indicating that the propeller will not accelerate or decelerate.
129 // Remembering that Torque * omega = Power, we can derive the torque on the
130 // propeller and its acceleration to give a new RPM. The current RPM will be
131 // used to calculate thrust.
133 // Because RPM could be zero, we need to be creative about what RPM is stated as.
135 double FGPropeller::Calculate(double PowerAvailable)
137 double J, C_Thrust, omega;
138 double Vel = fdmex->GetTranslation()->GetAeroUVW(eU);
139 double rho = fdmex->GetAtmosphere()->GetDensity();
140 double RPS = RPM/60.0;
144 J = Vel / (Diameter * RPS);
149 if (MaxPitch == MinPitch) { // Fixed pitch prop
150 C_Thrust = cThrust->GetValue(J);
151 } else { // Variable pitch prop
152 C_Thrust = cThrust->GetValue(J, Pitch);
155 if (P_Factor > 0.0001) {
156 alpha = fdmex->GetTranslation()->Getalpha();
157 beta = fdmex->GetTranslation()->Getbeta();
158 SetActingLocationY( GetLocationY() + P_Factor*alpha*Sense);
159 SetActingLocationZ( GetLocationZ() + P_Factor*beta*Sense);
160 } else if (P_Factor < 0.000) {
161 cerr << "P-Factor value in config file must be greater than zero" << endl;
164 Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
165 omega = RPS*2.0*M_PI;
167 // Check for windmilling.
168 double radius = Diameter * 0.375; // 75% of radius
169 double windmill_cutoff = tan(Pitch * 1.745329E-2) * omega * radius;
170 if (Vel > windmill_cutoff)
175 // The Ixx value and rotation speed given below are for rotation about the
176 // natural axis of the engine. The transform takes place in the base class
177 // FGForce::GetBodyForces() function.
179 vH(eX) = Ixx*omega*Sense;
183 if (omega <= 5) omega = 1.0;
185 ExcessTorque = PowerAvailable / omega * GearRatio;
186 RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
188 // The friction from the engine should
189 // stop it somewhere; I chose an
194 vMn = fdmex->GetRotation()->GetPQR()*vH + vTorque*Sense;
196 return Thrust; // return thrust in pounds
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 double FGPropeller::GetPowerRequired(void)
203 if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
205 double cPReq, RPS = RPM / 60.0;
207 double J = fdmex->GetTranslation()->GetAeroUVW(eU) / (Diameter * RPS);
208 double rho = fdmex->GetAtmosphere()->GetDensity();
210 if (MaxPitch == MinPitch) { // Fixed pitch prop
212 cPReq = cPower->GetValue(J);
213 } else { // Variable pitch prop
214 double advance = fdmex->GetFCS()->GetPropAdvance(ThrusterNumber);
216 if (MaxRPM != MinRPM) { // fixed-speed prop
217 double rpmReq = MinRPM + (MaxRPM - MinRPM) * advance;
218 double dRPM = rpmReq - RPM;
222 if (Pitch < MinPitch) Pitch = MinPitch;
223 else if (Pitch > MaxPitch) Pitch = MaxPitch;
226 Pitch = MinPitch + (MaxPitch - MinPitch) * advance;
228 cPReq = cPower->GetValue(J, Pitch);
231 PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
233 vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
235 return PowerRequired;
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 FGColumnVector3 FGPropeller::GetPFactor()
242 double px=0.0, py, pz;
244 py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
245 pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
247 return FGColumnVector3(px, py, pz);
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 // The bitmasked value choices are as follows:
252 // unset: In this case (the default) JSBSim would only print
253 // out the normally expected messages, essentially echoing
254 // the config files as they are read. If the environment
255 // variable is not set, debug_lvl is set to 1 internally
256 // 0: This requests JSBSim not to output any messages
258 // 1: This value explicity requests the normal JSBSim
260 // 2: This value asks for a message to be printed out when
261 // a class is instantiated
262 // 4: When this value is set, a message is displayed when a
263 // FGModel object executes its Run() method
264 // 8: When this value is set, various runtime state variables
265 // are printed out periodically
266 // 16: When set various parameters are sanity checked and
267 // a message is printed out when they go out of bounds
269 void FGPropeller::Debug(int from)
271 if (debug_lvl <= 0) return;
273 if (debug_lvl & 1) { // Standard console startup message output
274 if (from == 0) { // Constructor
275 cout << "\n Propeller Name: " << Name << endl;
276 cout << " IXX = " << Ixx << endl;
277 cout << " Diameter = " << Diameter << " ft." << endl;
278 cout << " Number of Blades = " << numBlades << endl;
279 cout << " Minimum Pitch = " << MinPitch << endl;
280 cout << " Maximum Pitch = " << MaxPitch << endl;
281 cout << " Thrust Coefficient: " << endl;
283 cout << " Power Coefficient: " << endl;
287 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
288 if (from == 0) cout << "Instantiated: FGPropeller" << endl;
289 if (from == 1) cout << "Destroyed: FGPropeller" << endl;
291 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
293 if (debug_lvl & 8 ) { // Runtime state variables
295 if (debug_lvl & 16) { // Sanity checking
297 if (debug_lvl & 64) {
298 if (from == 0) { // Constructor
299 cout << IdSrc << endl;
300 cout << IdHdr << endl;