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 extern short debug_lvl;
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
55 MaxPitch = MinPitch = 0.0;
57 Name = Prop_cfg->GetValue("NAME");
58 Prop_cfg->GetNextConfigLine();
59 while (Prop_cfg->GetValue() != "/FG_PROPELLER") {
63 } else if (token == "DIAMETER") {
64 *Prop_cfg >> Diameter;
66 } else if (token == "NUMBLADES") {
67 *Prop_cfg >> numBlades;
68 } else if (token == "MINPITCH") {
69 *Prop_cfg >> MinPitch;
70 } else if (token == "MAXPITCH") {
71 *Prop_cfg >> MaxPitch;
72 } else if (token == "EFFICIENCY") {
73 *Prop_cfg >> rows >> cols;
74 if (cols == 1) Efficiency = new FGTable(rows);
75 else Efficiency = new FGTable(rows, cols);
76 *Efficiency << *Prop_cfg;
77 } else if (token == "C_THRUST") {
78 *Prop_cfg >> rows >> cols;
79 if (cols == 1) cThrust = new FGTable(rows);
80 else cThrust = new FGTable(rows, cols);
81 *cThrust << *Prop_cfg;
82 } else if (token == "C_POWER") {
83 *Prop_cfg >> rows >> cols;
84 if (cols == 1) cPower = new FGTable(rows);
85 else cPower = new FGTable(rows, cols);
87 } else if (token == "EOF") {
88 cerr << " End of file reached" << endl;
91 cerr << "Unhandled token in Propeller config file: " << token << endl;
96 cout << "\n Propeller Name: " << Name << endl;
97 cout << " IXX = " << Ixx << endl;
98 cout << " Diameter = " << Diameter << " ft." << endl;
99 cout << " Number of Blades = " << numBlades << endl;
100 cout << " Minimum Pitch = " << MinPitch << endl;
101 cout << " Maximum Pitch = " << MaxPitch << endl;
102 cout << " Efficiency: " << endl;
104 cout << " Thrust Coefficient: " << endl;
106 cout << " Power Coefficient: " << endl;
113 if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 FGPropeller::~FGPropeller()
120 if (Efficiency) delete Efficiency;
121 if (cThrust) delete cThrust;
122 if (cPower) delete cPower;
123 if (debug_lvl & 2) cout << "Destroyed: FGPropeller" << endl;
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
129 // We need the velocity with respect to the wind.
131 // Note that PowerAvailable is the excess power available after the drag of the
132 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
133 // indicating that the propeller will not accelerate or decelerate.
134 // Remembering that Torque * omega = Power, we can derive the torque on the
135 // propeller and its acceleration to give a new RPM. The current RPM will be
136 // used to calculate thrust.
138 // Because RPM could be zero, we need to be creative about what RPM is stated as.
140 float FGPropeller::Calculate(float PowerAvailable)
142 float J, C_Thrust, omega;
143 float Vel = (fdmex->GetTranslation()->GetUVW())(1);
144 float rho = fdmex->GetAtmosphere()->GetDensity();
145 float RPS = RPM/60.0;
148 J = Vel / (Diameter * RPM / 60.0);
153 if (MaxPitch == MinPitch) { // Fixed pitch prop
154 C_Thrust = cThrust->GetValue(J);
155 } else { // Variable pitch prop
156 C_Thrust = cThrust->GetValue(J, Pitch);
159 Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
161 omega = RPS*2.0*M_PI;
163 if (omega <= 5) omega = 1.0;
165 Torque = PowerAvailable / omega;
166 RPM = (RPS + ((Torque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
167 return Thrust; // return thrust in pounds
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 float FGPropeller::GetPowerRequired(void)
174 if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
176 float cPReq, RPS = RPM / 60.0;
178 float J = (fdmex->GetTranslation()->GetUVW())(1) / (Diameter * RPS);
179 float rho = fdmex->GetAtmosphere()->GetDensity();
181 if (MaxPitch == MinPitch) { // Fixed pitch prop
182 cPReq = cPower->GetValue(J);
183 } else { // Variable pitch prop
184 cPReq = cPower->GetValue(J, Pitch);
187 PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
189 return PowerRequired;
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 void FGPropeller::Debug(void)
196 //TODO: Add your source code here