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"
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_PROPELLER;
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
53 MaxPitch = MinPitch = P_Factor = Sense = 0.0;
55 Name = Prop_cfg->GetValue("NAME");
56 Prop_cfg->GetNextConfigLine();
57 while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
61 } else if (token == "DIAMETER") {
62 *Prop_cfg >> Diameter;
64 } else if (token == "NUMBLADES") {
65 *Prop_cfg >> numBlades;
66 } else if (token == "MINPITCH") {
67 *Prop_cfg >> MinPitch;
68 } else if (token == "MAXPITCH") {
69 *Prop_cfg >> MaxPitch;
70 } else if (token == "EFFICIENCY") {
71 *Prop_cfg >> rows >> cols;
72 if (cols == 1) Efficiency = new FGTable(rows);
73 else Efficiency = new FGTable(rows, cols);
74 *Efficiency << *Prop_cfg;
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);
85 } else if (token == "EOF") {
86 cerr << " End of file reached" << endl;
89 cerr << "Unhandled token in Propeller config file: " << token << endl;
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 << " Efficiency: " << endl;
102 cout << " Thrust Coefficient: " << endl;
104 cout << " Power Coefficient: " << endl;
111 if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 FGPropeller::~FGPropeller()
118 if (Efficiency) delete Efficiency;
119 if (cThrust) delete cThrust;
120 if (cPower) delete cPower;
121 if (debug_lvl & 2) cout << "Destroyed: FGPropeller" << endl;
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
127 // We need the velocity with respect to the wind.
129 // Note that PowerAvailable is the excess power available after the drag of the
130 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
131 // indicating that the propeller will not accelerate or decelerate.
132 // Remembering that Torque * omega = Power, we can derive the torque on the
133 // propeller and its acceleration to give a new RPM. The current RPM will be
134 // used to calculate thrust.
136 // Because RPM could be zero, we need to be creative about what RPM is stated as.
138 double FGPropeller::Calculate(double PowerAvailable)
140 double J, C_Thrust, omega;
141 double Vel = (fdmex->GetTranslation()->GetvAero())(1);
142 double rho = fdmex->GetAtmosphere()->GetDensity();
143 double RPS = RPM/60.0;
147 J = Vel / (Diameter * RPM / 60.0);
152 if (MaxPitch == MinPitch) { // Fixed pitch prop
153 C_Thrust = cThrust->GetValue(J);
154 } else { // Variable pitch prop
155 C_Thrust = cThrust->GetValue(J, Pitch);
158 if (P_Factor > 0.0001) {
159 alpha = fdmex->GetTranslation()->Getalpha();
160 beta = fdmex->GetTranslation()->Getbeta();
161 SetLocationY(P_Factor*alpha*fabs(Sense)/Sense);
162 SetLocationZ(P_Factor*beta*fabs(Sense)/Sense);
163 } else if (P_Factor < 0.000) {
164 cerr << "P-Factor value in config file must be greater than zero" << endl;
167 Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
169 omega = RPS*2.0*M_PI;
171 // The Ixx value and rotation speed given below are for rotation about the
172 // natural axis of the engine. The transform takes place in the base class
173 // FGForce::GetBodyForces() function.
175 vH(eX) = Ixx*omega*fabs(Sense)/Sense;
179 if (omega <= 5) omega = 1.0;
181 Torque = PowerAvailable / omega;
182 RPM = (RPS + ((Torque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
184 vMn = fdmex->GetRotation()->GetPQR()*vH + Torque*Sense;
186 return Thrust; // return thrust in pounds
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 double FGPropeller::GetPowerRequired(void)
193 if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
195 double cPReq, RPS = RPM / 60.0;
197 double J = (fdmex->GetTranslation()->GetvAero())(1) / (Diameter * RPS);
198 double rho = fdmex->GetAtmosphere()->GetDensity();
200 if (MaxPitch == MinPitch) { // Fixed pitch prop
201 cPReq = cPower->GetValue(J);
202 } else { // Variable pitch prop
203 cPReq = cPower->GetValue(J, Pitch);
206 PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
208 return PowerRequired;
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 void FGPropeller::Debug(void)
215 //TODO: Add your source code here