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 "models/FGPropagate.h"
43 #include "models/FGAtmosphere.h"
44 #include "models/FGAuxiliary.h"
45 #include "input_output/FGXMLElement.h"
51 static const char *IdSrc = "$Id: FGPropeller.cpp,v 1.33 2011/03/10 01:35:25 dpculp Exp $";
52 static const char *IdHdr = ID_PROPELLER;
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 // This class currently makes certain assumptions when calculating torque and
59 // p-factor. That is, that the axis of rotation is the X axis of the aircraft -
60 // not just the X-axis of the engine/propeller. This may or may not work for a
63 FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
64 : FGThruster(exec, prop_element, num)
67 Element *table_element, *local_element;
69 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
71 MaxPitch = MinPitch = P_Factor = Pitch = Advance = MinRPM = MaxRPM = 0.0;
72 Sense = 1; // default clockwise rotation
78 CtFactor = CpFactor = 1.0;
80 cThrust = cPower = CtMach = CpMach = 0;
83 if (prop_element->FindElement("ixx"))
84 Ixx = prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2");
85 if (prop_element->FindElement("diameter"))
86 Diameter = prop_element->FindElementValueAsNumberConvertTo("diameter", "FT");
87 if (prop_element->FindElement("numblades"))
88 numBlades = (int)prop_element->FindElementValueAsNumber("numblades");
89 if (prop_element->FindElement("gearratio"))
90 GearRatio = prop_element->FindElementValueAsNumber("gearratio");
91 if (prop_element->FindElement("minpitch"))
92 MinPitch = prop_element->FindElementValueAsNumber("minpitch");
93 if (prop_element->FindElement("maxpitch"))
94 MaxPitch = prop_element->FindElementValueAsNumber("maxpitch");
95 if (prop_element->FindElement("minrpm"))
96 MinRPM = prop_element->FindElementValueAsNumber("minrpm");
97 if (prop_element->FindElement("maxrpm")) {
98 MaxRPM = prop_element->FindElementValueAsNumber("maxrpm");
101 if (prop_element->FindElement("constspeed"))
102 ConstantSpeed = (int)prop_element->FindElementValueAsNumber("constspeed");
103 if (prop_element->FindElement("reversepitch"))
104 ReversePitch = prop_element->FindElementValueAsNumber("reversepitch");
105 for (int i=0; i<2; i++) {
106 table_element = prop_element->FindNextElement("table");
107 name = table_element->GetAttributeValue("name");
109 if (name == "C_THRUST") {
110 cThrust = new FGTable(PropertyManager, table_element);
111 } else if (name == "C_POWER") {
112 cPower = new FGTable(PropertyManager, table_element);
113 } else if (name == "CT_MACH") {
114 CtMach = new FGTable(PropertyManager, table_element);
115 } else if (name == "CP_MACH") {
116 CpMach = new FGTable(PropertyManager, table_element);
118 cerr << "Unknown table type: " << name << " in propeller definition." << endl;
120 } catch (std::string str) {
121 throw("Error loading propeller table:" + name + ". " + str);
125 local_element = prop_element->GetParent()->FindElement("sense");
127 double Sense = local_element->GetDataAsNumber();
128 SetSense(fabs(Sense)/Sense);
130 local_element = prop_element->GetParent()->FindElement("p_factor");
132 P_Factor = local_element->GetDataAsNumber();
135 cerr << "P-Factor value in config file must be greater than zero" << endl;
137 if (prop_element->FindElement("ct_factor"))
138 SetCtFactor( prop_element->FindElementValueAsNumber("ct_factor") );
139 if (prop_element->FindElement("cp_factor"))
140 SetCpFactor( prop_element->FindElementValueAsNumber("cp_factor") );
144 vTorque.InitMatrix();
145 D4 = Diameter*Diameter*Diameter*Diameter;
149 string property_name, base_property_name;
150 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
151 property_name = base_property_name + "/advance-ratio";
152 PropertyManager->Tie( property_name.c_str(), &J );
153 property_name = base_property_name + "/blade-angle";
154 PropertyManager->Tie( property_name.c_str(), &Pitch );
155 property_name = base_property_name + "/thrust-coefficient";
156 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetThrustCoefficient );
157 property_name = base_property_name + "/propeller-rpm";
158 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetRPM );
159 property_name = base_property_name + "/helical-tip-Mach";
160 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetHelicalTipMach );
161 property_name = base_property_name + "/constant-speed-mode";
162 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetConstantSpeed,
163 &FGPropeller::SetConstantSpeed );
164 property_name = base_property_name + "/prop-induced-velocity_fps";
165 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetInducedVelocity,
166 &FGPropeller::SetInducedVelocity );
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 FGPropeller::~FGPropeller()
183 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
186 // We need the velocity with respect to the wind.
188 // Remembering that Torque * omega = Power, we can derive the torque on the
189 // propeller and its acceleration to give a new RPM. The current RPM will be
190 // used to calculate thrust.
192 // Because RPM could be zero, we need to be creative about what RPM is stated as.
194 double FGPropeller::Calculate(double EnginePower)
196 double omega, alpha, beta, PowerAvailable;
198 double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
199 double rho = fdmex->GetAtmosphere()->GetDensity();
200 double RPS = RPM/60.0;
202 PowerAvailable = EnginePower - GetPowerRequired();
204 // Calculate helical tip Mach
205 double Area = 0.25*Diameter*Diameter*M_PI;
206 double Vtip = RPS * Diameter * M_PI;
207 HelicalTipMach = sqrt(Vtip*Vtip + Vel*Vel) /
208 fdmex->GetAtmosphere()->GetSoundSpeed();
210 if (RPS > 0.0) J = Vel / (Diameter * RPS); // Calculate J normally
211 else J = Vel / Diameter;
213 if (MaxPitch == MinPitch) { // Fixed pitch prop
214 ThrustCoeff = cThrust->GetValue(J);
215 } else { // Variable pitch prop
216 ThrustCoeff = cThrust->GetValue(J, Pitch);
219 // Apply optional scaling factor to Ct (default value = 1)
220 ThrustCoeff *= CtFactor;
222 // Apply optional Mach effects from CT_MACH table
223 if (CtMach) ThrustCoeff *= CtMach->GetValue(HelicalTipMach);
225 if (P_Factor > 0.0001) {
226 alpha = fdmex->GetAuxiliary()->Getalpha();
227 beta = fdmex->GetAuxiliary()->Getbeta();
228 SetActingLocationY( GetLocationY() + P_Factor*alpha*Sense);
229 SetActingLocationZ( GetLocationZ() + P_Factor*beta*Sense);
232 Thrust = ThrustCoeff*RPS*RPS*D4*rho;
234 // From B. W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics"
235 // first edition, eqn. 6.15 (propeller analysis chapter).
236 Vinduced = 0.5 * (-Vel + sqrt(Vel*Vel + 2.0*Thrust/(rho*Area)));
238 omega = RPS*2.0*M_PI;
242 // The Ixx value and rotation speed given below are for rotation about the
243 // natural axis of the engine. The transform takes place in the base class
244 // FGForce::GetBodyForces() function.
246 vH(eX) = Ixx*omega*Sense;
250 if (omega > 0.0) ExcessTorque = PowerAvailable / omega;
251 else ExcessTorque = PowerAvailable / 1.0;
253 RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
255 if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
257 // Transform Torque and momentum first, as PQR is used in this
258 // equation and cannot be transformed itself.
259 vMn = fdmex->GetPropagate()->GetPQR()*(Transform()*vH) + Transform()*vTorque;
261 return Thrust; // return thrust in pounds
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 double FGPropeller::GetPowerRequired(void)
269 double rho = fdmex->GetAtmosphere()->GetDensity();
270 double Vel = fdmex->GetAuxiliary()->GetAeroUVW(eU);
271 double RPS = RPM / 60.0;
273 if (RPS != 0.0) J = Vel / (Diameter * RPS);
274 else J = Vel / Diameter;
276 if (MaxPitch == MinPitch) { // Fixed pitch prop
277 cPReq = cPower->GetValue(J);
279 } else { // Variable pitch prop
281 if (ConstantSpeed != 0) { // Constant Speed Mode
283 // do normal calculation when propeller is neither feathered nor reversed
284 // Note: This method of feathering and reversing was added to support the
285 // turboprop model. It's left here for backward compatablity, but
286 // now feathering and reversing should be done in Manual Pitch Mode.
290 double rpmReq = MinRPM + (MaxRPM - MinRPM) * Advance;
291 double dRPM = rpmReq - RPM;
292 // The pitch of a variable propeller cannot be changed when the RPMs are
293 // too low - the oil pump does not work.
294 if (RPM > 200) Pitch -= dRPM * deltaT;
295 if (Pitch < MinPitch) Pitch = MinPitch;
296 else if (Pitch > MaxPitch) Pitch = MaxPitch;
298 } else { // Reversed propeller
300 // when reversed calculate propeller pitch depending on throttle lever position
301 // (beta range for taxing full reverse for braking)
302 double PitchReq = MinPitch - ( MinPitch - ReversePitch ) * Reverse_coef;
303 // The pitch of a variable propeller cannot be changed when the RPMs are
304 // too low - the oil pump does not work.
305 if (RPM > 200) Pitch += (PitchReq - Pitch) / 200;
307 Pitch += (MaxRPM - RPM) / 50;
308 if (Pitch < ReversePitch) Pitch = ReversePitch;
309 else if (Pitch > MaxPitch) Pitch = MaxPitch;
313 } else { // Feathered propeller
314 // ToDo: Make feathered and reverse settings done via FGKinemat
315 Pitch += (MaxPitch - Pitch) / 300; // just a guess (about 5 sec to fully feathered)
318 } else { // Manual Pitch Mode, pitch is controlled externally
322 cPReq = cPower->GetValue(J, Pitch);
325 // Apply optional scaling factor to Cp (default value = 1)
328 // Apply optional Mach effects from CP_MACH table
329 if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);
332 PowerRequired = cPReq*RPS*RPS*RPS*D5*rho;
333 vTorque(eX) = -Sense*PowerRequired / (RPS*2.0*M_PI);
335 // For a stationary prop we have to estimate torque first.
336 double CL = (90.0 - Pitch) / 20.0;
337 if (CL > 1.5) CL = 1.5;
338 double BladeArea = Diameter * Diameter / 32.0 * numBlades;
339 vTorque(eX) = -Sense*BladeArea*Diameter*Vel*Vel*rho*0.19*CL;
340 PowerRequired = fabs(vTorque(eX))*0.2*M_PI;
343 return PowerRequired;
346 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348 FGColumnVector3 FGPropeller::GetPFactor()
350 double px=0.0, py, pz;
352 py = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
353 pz = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
355 return FGColumnVector3(px, py, pz);
358 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 string FGPropeller::GetThrusterLabels(int id, string delimeter)
362 std::ostringstream buf;
364 buf << Name << " Torque (engine " << id << ")" << delimeter
365 << Name << " PFactor Pitch (engine " << id << ")" << delimeter
366 << Name << " PFactor Yaw (engine " << id << ")" << delimeter
367 << Name << " Thrust (engine " << id << " in lbs)" << delimeter;
369 buf << Name << " Pitch (engine " << id << ")" << delimeter;
370 buf << Name << " RPM (engine " << id << ")";
375 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 string FGPropeller::GetThrusterValues(int id, string delimeter)
379 std::ostringstream buf;
381 FGColumnVector3 vPFactor = GetPFactor();
382 buf << vTorque(eX) << delimeter
383 << vPFactor(ePitch) << delimeter
384 << vPFactor(eYaw) << delimeter
385 << Thrust << delimeter;
387 buf << Pitch << delimeter;
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 // The bitmasked value choices are as follows:
395 // unset: In this case (the default) JSBSim would only print
396 // out the normally expected messages, essentially echoing
397 // the config files as they are read. If the environment
398 // variable is not set, debug_lvl is set to 1 internally
399 // 0: This requests JSBSim not to output any messages
401 // 1: This value explicity requests the normal JSBSim
403 // 2: This value asks for a message to be printed out when
404 // a class is instantiated
405 // 4: When this value is set, a message is displayed when a
406 // FGModel object executes its Run() method
407 // 8: When this value is set, various runtime state variables
408 // are printed out periodically
409 // 16: When set various parameters are sanity checked and
410 // a message is printed out when they go out of bounds
412 void FGPropeller::Debug(int from)
414 if (debug_lvl <= 0) return;
416 if (debug_lvl & 1) { // Standard console startup message output
417 if (from == 0) { // Constructor
418 cout << "\n Propeller Name: " << Name << endl;
419 cout << " IXX = " << Ixx << endl;
420 cout << " Diameter = " << Diameter << " ft." << endl;
421 cout << " Number of Blades = " << numBlades << endl;
422 cout << " Gear Ratio = " << GearRatio << endl;
423 cout << " Minimum Pitch = " << MinPitch << endl;
424 cout << " Maximum Pitch = " << MaxPitch << endl;
425 cout << " Minimum RPM = " << MinRPM << endl;
426 cout << " Maximum RPM = " << MaxRPM << endl;
427 // cout << " Thrust Coefficient: " << endl;
429 // cout << " Power Coefficient: " << endl;
433 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
434 if (from == 0) cout << "Instantiated: FGPropeller" << endl;
435 if (from == 1) cout << "Destroyed: FGPropeller" << endl;
437 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
439 if (debug_lvl & 8 ) { // Runtime state variables
441 if (debug_lvl & 16) { // Sanity checking
443 if (debug_lvl & 64) {
444 if (from == 0) { // Constructor
445 cout << IdSrc << endl;
446 cout << IdHdr << endl;