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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGPropeller.h"
41 #include "FGPropagate.h"
42 #include "FGAtmosphere.h"
43 #include "FGAuxiliary.h"
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_PROPELLER;
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 // This class currently makes certain assumptions when calculating torque and
55 // p-factor. That is, that the axis of rotation is the X axis of the aircraft -
56 // not just the X-axis of the engine/propeller. This may or may not work for a
59 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
64 MaxPitch = MinPitch = P_Factor = Sense = Pitch = Advance = 0.0;
67 Name = Prop_cfg->GetValue("NAME");
68 Prop_cfg->GetNextConfigLine();
69 while (Prop_cfg->GetValue() != string("/FG_PROPELLER")) {
73 } else if (token == "DIAMETER") {
74 *Prop_cfg >> Diameter;
76 } else if (token == "NUMBLADES") {
77 *Prop_cfg >> numBlades;
78 } else if (token == "GEARRATIO") {
79 *Prop_cfg >> GearRatio;
80 } else if (token == "MINPITCH") {
81 *Prop_cfg >> MinPitch;
82 } else if (token == "MAXPITCH") {
83 *Prop_cfg >> MaxPitch;
84 } else if (token == "MINRPM") {
86 } else if (token == "MAXRPM") {
88 } else if (token == "C_THRUST") {
89 *Prop_cfg >> rows >> cols;
90 if (cols == 1) cThrust = new FGTable(rows);
91 else cThrust = new FGTable(rows, cols);
92 *cThrust << *Prop_cfg;
93 } else if (token == "C_POWER") {
94 *Prop_cfg >> rows >> cols;
95 if (cols == 1) cPower = new FGTable(rows);
96 else cPower = new FGTable(rows, cols);
98 } else if (token == "EOF") {
99 cerr << " End of file reached" << endl;
102 cerr << "Unhandled token in Propeller config file: " << token << endl;
108 vTorque.InitMatrix();
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGPropeller::~FGPropeller()
117 if (cThrust) delete cThrust;
118 if (cPower) delete cPower;
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
125 // We need the velocity with respect to the wind.
127 // Note that PowerAvailable is the excess power available after the drag of the
128 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
129 // indicating that the propeller will not accelerate or decelerate.
130 // Remembering that Torque * omega = Power, we can derive the torque on the
131 // propeller and its acceleration to give a new RPM. The current RPM will be
132 // used to calculate thrust.
134 // Because RPM could be zero, we need to be creative about what RPM is stated as.
136 double FGPropeller::Calculate(double PowerAvailable)
138 double J, C_Thrust, omega;
139 double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
140 double rho = fdmex->GetAtmosphere()->GetDensity();
141 double RPS = RPM/60.0;
145 J = Vel / (Diameter * RPS);
150 if (MaxPitch == MinPitch) { // Fixed pitch prop
151 C_Thrust = cThrust->GetValue(J);
152 } else { // Variable pitch prop
153 C_Thrust = cThrust->GetValue(J, Pitch);
156 if (P_Factor > 0.0001) {
157 alpha = fdmex->GetAuxiliary()->Getalpha();
158 beta = fdmex->GetAuxiliary()->Getbeta();
159 SetActingLocationY( GetLocationY() + P_Factor*alpha*Sense);
160 SetActingLocationZ( GetLocationZ() + P_Factor*beta*Sense);
161 } else if (P_Factor < 0.000) {
162 cerr << "P-Factor value in config file must be greater than zero" << endl;
165 Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
166 omega = RPS*2.0*M_PI;
170 // The Ixx value and rotation speed given below are for rotation about the
171 // natural axis of the engine. The transform takes place in the base class
172 // FGForce::GetBodyForces() function.
174 vH(eX) = Ixx*omega*Sense;
178 if (omega <= 5) omega = 1.0;
180 ExcessTorque = PowerAvailable / omega * GearRatio;
181 RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
183 // The friction from the engine should
184 // stop it somewhere; I chose an
189 vMn = fdmex->GetPropagate()->GetPQR()*vH + vTorque*Sense;
191 return Thrust; // return thrust in pounds
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 double FGPropeller::GetPowerRequired(void)
198 if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
200 double cPReq, RPS = RPM / 60.0;
202 double J = fdmex->GetAuxiliary()->GetAeroUVW(eU) / (Diameter * RPS);
203 double rho = fdmex->GetAtmosphere()->GetDensity();
205 if (MaxPitch == MinPitch) { // Fixed pitch prop
207 cPReq = cPower->GetValue(J);
208 } else { // Variable pitch prop
210 if (MaxRPM != MinRPM) { // fixed-speed prop
211 double rpmReq = MinRPM + (MaxRPM - MinRPM) * Advance;
212 double dRPM = rpmReq - RPM;
216 if (Pitch < MinPitch) Pitch = MinPitch;
217 else if (Pitch > MaxPitch) Pitch = MaxPitch;
220 Pitch = MinPitch + (MaxPitch - MinPitch) * Advance;
222 cPReq = cPower->GetValue(J, Pitch);
225 PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
227 vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
229 return PowerRequired;
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 FGColumnVector3 FGPropeller::GetPFactor()
236 double px=0.0, py, pz;
238 py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
239 pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
241 return FGColumnVector3(px, py, pz);
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 string FGPropeller::GetThrusterLabels(int id)
248 std::ostringstream buf;
250 buf << Name << "_Torque[" << id << "], "
251 << Name << "_PFactor_Pitch[" << id << "], "
252 << Name << "_PFactor_Yaw[" << id << "], "
253 << Name << "_Thrust[" << id << "], ";
255 buf << Name << "_Pitch[" << id << "], ";
256 buf << Name << "_RPM[" << id << "]";
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 string FGPropeller::GetThrusterValues(int id)
265 std::ostringstream buf;
267 FGColumnVector3 vPFactor = GetPFactor();
268 buf << vTorque(eX) << ", "
269 << vPFactor(ePitch) << ", "
270 << vPFactor(eYaw) << ", "
273 buf << Pitch << ", ";
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 // The bitmasked value choices are as follows:
281 // unset: In this case (the default) JSBSim would only print
282 // out the normally expected messages, essentially echoing
283 // the config files as they are read. If the environment
284 // variable is not set, debug_lvl is set to 1 internally
285 // 0: This requests JSBSim not to output any messages
287 // 1: This value explicity requests the normal JSBSim
289 // 2: This value asks for a message to be printed out when
290 // a class is instantiated
291 // 4: When this value is set, a message is displayed when a
292 // FGModel object executes its Run() method
293 // 8: When this value is set, various runtime state variables
294 // are printed out periodically
295 // 16: When set various parameters are sanity checked and
296 // a message is printed out when they go out of bounds
298 void FGPropeller::Debug(int from)
300 if (debug_lvl <= 0) return;
302 if (debug_lvl & 1) { // Standard console startup message output
303 if (from == 0) { // Constructor
304 cout << "\n Propeller Name: " << Name << endl;
305 cout << " IXX = " << Ixx << endl;
306 cout << " Diameter = " << Diameter << " ft." << endl;
307 cout << " Number of Blades = " << numBlades << endl;
308 cout << " Minimum Pitch = " << MinPitch << endl;
309 cout << " Maximum Pitch = " << MaxPitch << endl;
310 cout << " Thrust Coefficient: " << endl;
312 cout << " Power Coefficient: " << endl;
316 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
317 if (from == 0) cout << "Instantiated: FGPropeller" << endl;
318 if (from == 1) cout << "Destroyed: FGPropeller" << endl;
320 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
322 if (debug_lvl & 8 ) { // Runtime state variables
324 if (debug_lvl & 16) { // Sanity checking
326 if (debug_lvl & 64) {
327 if (from == 0) { // Constructor
328 cout << IdSrc << endl;
329 cout << IdHdr << endl;