1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGPropeller.cpp
6 Purpose: Encapsulates the propeller object
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser 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 Lesser General Public License for more
20 You should have received a copy of the GNU Lesser 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 Lesser 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "FGPropeller.h"
42 #include "input_output/FGXMLElement.h"
48 static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.36 2011/08/03 03:21:06 jberndt Exp $";
49 static const char *IdHdr = ID_PROPELLER;
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 // This class currently makes certain assumptions when calculating torque and
56 // p-factor. That is, that the axis of rotation is the X axis of the aircraft -
57 // not just the X-axis of the engine/propeller. This may or may not work for a
60 FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
61 : FGThruster(exec, prop_element, num)
64 Element *table_element, *local_element;
66 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
68 MaxPitch = MinPitch = P_Factor = Pitch = Advance = MinRPM = MaxRPM = 0.0;
69 Sense = 1; // default clockwise rotation
75 CtFactor = CpFactor = 1.0;
77 cThrust = cPower = CtMach = CpMach = 0;
80 if (prop_element->FindElement("ixx"))
81 Ixx = prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2");
82 if (prop_element->FindElement("diameter"))
83 Diameter = prop_element->FindElementValueAsNumberConvertTo("diameter", "FT");
84 if (prop_element->FindElement("numblades"))
85 numBlades = (int)prop_element->FindElementValueAsNumber("numblades");
86 if (prop_element->FindElement("gearratio"))
87 GearRatio = prop_element->FindElementValueAsNumber("gearratio");
88 if (prop_element->FindElement("minpitch"))
89 MinPitch = prop_element->FindElementValueAsNumber("minpitch");
90 if (prop_element->FindElement("maxpitch"))
91 MaxPitch = prop_element->FindElementValueAsNumber("maxpitch");
92 if (prop_element->FindElement("minrpm"))
93 MinRPM = prop_element->FindElementValueAsNumber("minrpm");
94 if (prop_element->FindElement("maxrpm")) {
95 MaxRPM = prop_element->FindElementValueAsNumber("maxrpm");
98 if (prop_element->FindElement("constspeed"))
99 ConstantSpeed = (int)prop_element->FindElementValueAsNumber("constspeed");
100 if (prop_element->FindElement("reversepitch"))
101 ReversePitch = prop_element->FindElementValueAsNumber("reversepitch");
102 while(table_element = prop_element->FindNextElement("table")) {
103 name = table_element->GetAttributeValue("name");
105 if (name == "C_THRUST") {
106 cThrust = new FGTable(PropertyManager, table_element);
107 } else if (name == "C_POWER") {
108 cPower = new FGTable(PropertyManager, table_element);
109 } else if (name == "CT_MACH") {
110 CtMach = new FGTable(PropertyManager, table_element);
111 } else if (name == "CP_MACH") {
112 CpMach = new FGTable(PropertyManager, table_element);
114 cerr << "Unknown table type: " << name << " in propeller definition." << endl;
116 } catch (std::string str) {
117 throw("Error loading propeller table:" + name + ". " + str);
120 if( (cPower == 0) || (cThrust == 0)){
121 cerr << "Propeller configuration must contain C_THRUST and C_POWER tables!" << endl;
124 local_element = prop_element->GetParent()->FindElement("sense");
126 double Sense = local_element->GetDataAsNumber();
127 SetSense(fabs(Sense)/Sense);
129 local_element = prop_element->GetParent()->FindElement("p_factor");
131 P_Factor = local_element->GetDataAsNumber();
134 cerr << "P-Factor value in propeller configuration file must be greater than zero" << endl;
136 if (prop_element->FindElement("ct_factor"))
137 SetCtFactor( prop_element->FindElementValueAsNumber("ct_factor") );
138 if (prop_element->FindElement("cp_factor"))
139 SetCpFactor( prop_element->FindElementValueAsNumber("cp_factor") );
143 vTorque.InitMatrix();
144 D4 = Diameter*Diameter*Diameter*Diameter;
148 string property_name, base_property_name;
149 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
150 property_name = base_property_name + "/advance-ratio";
151 PropertyManager->Tie( property_name.c_str(), &J );
152 property_name = base_property_name + "/blade-angle";
153 PropertyManager->Tie( property_name.c_str(), &Pitch );
154 property_name = base_property_name + "/thrust-coefficient";
155 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetThrustCoefficient );
156 property_name = base_property_name + "/propeller-rpm";
157 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetRPM );
158 property_name = base_property_name + "/helical-tip-Mach";
159 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetHelicalTipMach );
160 property_name = base_property_name + "/constant-speed-mode";
161 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetConstantSpeed,
162 &FGPropeller::SetConstantSpeed );
163 property_name = base_property_name + "/prop-induced-velocity_fps";
164 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetInducedVelocity,
165 &FGPropeller::SetInducedVelocity );
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 FGPropeller::~FGPropeller()
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
185 // We need the velocity with respect to the wind.
187 // Remembering that Torque * omega = Power, we can derive the torque on the
188 // propeller and its acceleration to give a new RPM. The current RPM will be
189 // used to calculate thrust.
191 // Because RPM could be zero, we need to be creative about what RPM is stated as.
193 double FGPropeller::Calculate(double EnginePower)
195 double omega, PowerAvailable;
197 double Vel = in.AeroUVW(eU);
198 double rho = in.Density;
199 double RPS = RPM/60.0;
201 // Calculate helical tip Mach
202 double Area = 0.25*Diameter*Diameter*M_PI;
203 double Vtip = RPS * Diameter * M_PI;
204 HelicalTipMach = sqrt(Vtip*Vtip + Vel*Vel) / in.Soundspeed;
206 PowerAvailable = EnginePower - GetPowerRequired();
208 if (RPS > 0.0) J = Vel / (Diameter * RPS); // Calculate J normally
209 else J = Vel / Diameter;
211 if (MaxPitch == MinPitch) { // Fixed pitch prop
212 ThrustCoeff = cThrust->GetValue(J);
213 } else { // Variable pitch prop
214 ThrustCoeff = cThrust->GetValue(J, Pitch);
217 // Apply optional scaling factor to Ct (default value = 1)
218 ThrustCoeff *= CtFactor;
220 // Apply optional Mach effects from CT_MACH table
221 if (CtMach) ThrustCoeff *= CtMach->GetValue(HelicalTipMach);
223 if (P_Factor > 0.0001) {
224 SetActingLocationY( GetLocationY() + P_Factor*in.Alpha*Sense);
225 SetActingLocationZ( GetLocationZ() + P_Factor*in.Beta*Sense);
228 Thrust = ThrustCoeff*RPS*RPS*D4*rho;
230 // From B. W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics"
231 // first edition, eqn. 6.15 (propeller analysis chapter).
232 Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area)));
234 omega = RPS*2.0*M_PI;
238 // The Ixx value and rotation speed given below are for rotation about the
239 // natural axis of the engine. The transform takes place in the base class
240 // FGForce::GetBodyForces() function.
242 vH(eX) = Ixx*omega*Sense;
246 if (omega > 0.0) ExcessTorque = PowerAvailable / omega;
247 else ExcessTorque = PowerAvailable / 1.0;
249 RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
251 if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
253 // Transform Torque and momentum first, as PQR is used in this
254 // equation and cannot be transformed itself.
255 vMn = in.PQR*(Transform()*vH) + Transform()*vTorque;
257 return Thrust; // return thrust in pounds
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 double FGPropeller::GetPowerRequired(void)
265 double rho = in.Density;
266 double Vel = in.AeroUVW(eU);
267 double RPS = RPM / 60.0;
269 if (RPS != 0.0) J = Vel / (Diameter * RPS);
270 else J = Vel / Diameter;
272 if (MaxPitch == MinPitch) { // Fixed pitch prop
273 cPReq = cPower->GetValue(J);
275 } else { // Variable pitch prop
277 if (ConstantSpeed != 0) { // Constant Speed Mode
279 // do normal calculation when propeller is neither feathered nor reversed
280 // Note: This method of feathering and reversing was added to support the
281 // turboprop model. It's left here for backward compatablity, but
282 // now feathering and reversing should be done in Manual Pitch Mode.
286 double rpmReq = MinRPM + (MaxRPM - MinRPM) * Advance;
287 double dRPM = rpmReq - RPM;
288 // The pitch of a variable propeller cannot be changed when the RPMs are
289 // too low - the oil pump does not work.
290 if (RPM > 200) Pitch -= dRPM * deltaT;
291 if (Pitch < MinPitch) Pitch = MinPitch;
292 else if (Pitch > MaxPitch) Pitch = MaxPitch;
294 } else { // Reversed propeller
296 // when reversed calculate propeller pitch depending on throttle lever position
297 // (beta range for taxing full reverse for braking)
298 double PitchReq = MinPitch - ( MinPitch - ReversePitch ) * Reverse_coef;
299 // The pitch of a variable propeller cannot be changed when the RPMs are
300 // too low - the oil pump does not work.
301 if (RPM > 200) Pitch += (PitchReq - Pitch) / 200;
303 Pitch += (MaxRPM - RPM) / 50;
304 if (Pitch < ReversePitch) Pitch = ReversePitch;
305 else if (Pitch > MaxPitch) Pitch = MaxPitch;
309 } else { // Feathered propeller
310 // ToDo: Make feathered and reverse settings done via FGKinemat
311 Pitch += (MaxPitch - Pitch) / 300; // just a guess (about 5 sec to fully feathered)
314 } else { // Manual Pitch Mode, pitch is controlled externally
318 cPReq = cPower->GetValue(J, Pitch);
321 // Apply optional scaling factor to Cp (default value = 1)
324 // Apply optional Mach effects from CP_MACH table
325 if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);
328 PowerRequired = cPReq*RPS*RPS*RPS*D5*rho;
329 vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
331 // For a stationary prop we have to estimate torque first.
332 double CL = (90.0 - Pitch) / 20.0;
333 if (CL > 1.5) CL = 1.5;
334 double BladeArea = Diameter * Diameter / 32.0 * numBlades;
335 vTorque(eX) = -Sense*BladeArea*Diameter*Vel*Vel*rho*0.19*CL;
336 PowerRequired = fabs(vTorque(eX))*0.2*M_PI;
339 return PowerRequired;
342 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 FGColumnVector3 FGPropeller::GetPFactor()
346 double px=0.0, py, pz;
348 py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
349 pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
351 return FGColumnVector3(px, py, pz);
354 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
356 string FGPropeller::GetThrusterLabels(int id, string delimeter)
358 std::ostringstream buf;
360 buf << Name << " Torque (engine " << id << ")" << delimeter
361 << Name << " PFactor Pitch (engine " << id << ")" << delimeter
362 << Name << " PFactor Yaw (engine " << id << ")" << delimeter
363 << Name << " Thrust (engine " << id << " in lbs)" << delimeter;
365 buf << Name << " Pitch (engine " << id << ")" << delimeter;
366 buf << Name << " RPM (engine " << id << ")";
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 string FGPropeller::GetThrusterValues(int id, string delimeter)
375 std::ostringstream buf;
377 FGColumnVector3 vPFactor = GetPFactor();
378 buf << vTorque(eX) << delimeter
379 << vPFactor(ePitch) << delimeter
380 << vPFactor(eYaw) << delimeter
381 << Thrust << delimeter;
383 buf << Pitch << delimeter;
389 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 // The bitmasked value choices are as follows:
391 // unset: In this case (the default) JSBSim would only print
392 // out the normally expected messages, essentially echoing
393 // the config files as they are read. If the environment
394 // variable is not set, debug_lvl is set to 1 internally
395 // 0: This requests JSBSim not to output any messages
397 // 1: This value explicity requests the normal JSBSim
399 // 2: This value asks for a message to be printed out when
400 // a class is instantiated
401 // 4: When this value is set, a message is displayed when a
402 // FGModel object executes its Run() method
403 // 8: When this value is set, various runtime state variables
404 // are printed out periodically
405 // 16: When set various parameters are sanity checked and
406 // a message is printed out when they go out of bounds
408 void FGPropeller::Debug(int from)
410 if (debug_lvl <= 0) return;
412 if (debug_lvl & 1) { // Standard console startup message output
413 if (from == 0) { // Constructor
414 cout << "\n Propeller Name: " << Name << endl;
415 cout << " IXX = " << Ixx << endl;
416 cout << " Diameter = " << Diameter << " ft." << endl;
417 cout << " Number of Blades = " << numBlades << endl;
418 cout << " Gear Ratio = " << GearRatio << endl;
419 cout << " Minimum Pitch = " << MinPitch << endl;
420 cout << " Maximum Pitch = " << MaxPitch << endl;
421 cout << " Minimum RPM = " << MinRPM << endl;
422 cout << " Maximum RPM = " << MaxRPM << endl;
423 // Tables are being printed elsewhere...
424 // cout << " Thrust Coefficient: " << endl;
426 // cout << " Power Coefficient: " << endl;
428 // cout << " Mach Thrust Coefficient: " << endl;
433 // cout << " NONE" << endl;
435 // cout << " Mach Power Coefficient: " << endl;
440 // cout << " NONE" << endl;
444 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
445 if (from == 0) cout << "Instantiated: FGPropeller" << endl;
446 if (from == 1) cout << "Destroyed: FGPropeller" << endl;
448 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
450 if (debug_lvl & 8 ) { // Runtime state variables
452 if (debug_lvl & 16) { // Sanity checking
454 if (debug_lvl & 64) {
455 if (from == 0) { // Constructor
456 cout << IdSrc << endl;
457 cout << IdHdr << endl;