Debian Codegraph @

src/FDM/JSBSim/models/propulsion/FGPropeller.cpp

raw symbols SCIP
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGPropeller.cpp
4 Author: Jon S. Berndt
5 Date started: 08/24/00
6 Purpose: Encapsulates the propeller object
7
8 ------------- Copyright (C) 2000 Jon S. Berndt ([email protected]) -------------
9
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
13 version.
14
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
18 details.
19
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.
23
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.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 08/24/00 JSB Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #include <iostream>
39 #include <sstream>
40
41 #include "FGFDMExec.h"
42 #include "FGPropeller.h"
43 #include "input_output/FGXMLElement.h"
44 #include "models/FGMassBalance.h"
45
46 using namespace std;
47
48 namespace JSBSim {
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS IMPLEMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
55 : FGThruster(exec, prop_element, num)
56 {
57 Element *table_element, *local_element;
58 string name="";
59 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
60
61 MaxPitch = MinPitch = P_Factor = Pitch = Advance = MinRPM = MaxRPM = 0.0;
62 Sense = 1; // default clockwise rotation
63 ReversePitch = 0.0;
64 Reversed = false;
65 Feathered = false;
66 Reverse_coef = 0.0;
67 GearRatio = 1.0;
68 CtFactor = CpFactor = 1.0;
69 ConstantSpeed = 0;
70 cThrust = cPower = CtMach = CpMach = 0;
71 Vinduced = 0.0;
72 in.Soundspeed = 1.0;
73
74 if (prop_element->FindElement("ixx"))
75 Ixx = max(prop_element->FindElementValueAsNumberConvertTo("ixx", "SLUG*FT2"), 1e-06);
76
77 Sense_multiplier = 1.0;
78 if (prop_element->HasAttribute("version")
79 && prop_element->GetAttributeValueAsNumber("version") > 1.0)
80 Sense_multiplier = -1.0;
81
82 if (prop_element->FindElement("diameter"))
83 Diameter = max(prop_element->FindElementValueAsNumberConvertTo("diameter", "FT"), 0.001);
84 if (prop_element->FindElement("numblades"))
85 numBlades = (int)prop_element->FindElementValueAsNumber("numblades");
86 if (prop_element->FindElement("gearratio"))
87 GearRatio = max(prop_element->FindElementValueAsNumber("gearratio"), 0.001);
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");
96 ConstantSpeed = 1;
97 }
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")) != 0) {
103 name = table_element->GetAttributeValue("name");
104 try {
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);
113 } else {
114 cerr << "Unknown table type: " << name << " in propeller definition." << endl;
115 }
116 } catch (std::string& str) {
117 throw("Error loading propeller table:" + name + ". " + str);
118 }
119 }
120 if( (cPower == 0) || (cThrust == 0)){
121 cerr << "Propeller configuration must contain C_THRUST and C_POWER tables!" << endl;
122 }
123
124 local_element = prop_element->GetParent()->FindElement("sense");
125 if (local_element) {
126 double Sense = local_element->GetDataAsNumber();
127 SetSense(Sense >= 0.0 ? 1.0 : -1.0);
128 }
129 local_element = prop_element->GetParent()->FindElement("p_factor");
130 if (local_element) {
131 P_Factor = local_element->GetDataAsNumber();
132 }
133 if (P_Factor < 0) {
134 cerr << "P-Factor value in propeller configuration file must be greater than zero" << endl;
135 }
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") );
140
141 Type = ttPropeller;
142 RPM = 0;
143 vTorque.InitMatrix();
144 D4 = Diameter*Diameter*Diameter*Diameter;
145 D5 = D4*Diameter;
146 Pitch = MinPitch;
147
148 string property_name, base_property_name;
149 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNum);
150 property_name = base_property_name + "/engine-rpm";
151 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetEngineRPM );
152 property_name = base_property_name + "/advance-ratio";
153 PropertyManager->Tie( property_name.c_str(), &J );
154 property_name = base_property_name + "/blade-angle";
155 PropertyManager->Tie( property_name.c_str(), &Pitch );
156 property_name = base_property_name + "/thrust-coefficient";
157 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetThrustCoefficient );
158 property_name = base_property_name + "/propeller-rpm";
159 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetRPM );
160 property_name = base_property_name + "/helical-tip-Mach";
161 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetHelicalTipMach );
162 property_name = base_property_name + "/constant-speed-mode";
163 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetConstantSpeed,
164 &FGPropeller::SetConstantSpeed );
165 property_name = base_property_name + "/prop-induced-velocity_fps"; // [ft/sec]
166 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetInducedVelocity,
167 &FGPropeller::SetInducedVelocity );
168 property_name = base_property_name + "/propeller-power-ftlbps"; // [ft-lbs/sec]
169 PropertyManager->Tie( property_name.c_str(), &PowerRequired );
170 property_name = base_property_name + "/propeller-torque-ftlb"; // [ft-lbs]
171 PropertyManager->Tie( property_name.c_str(), this, &FGPropeller::GetTorque);
172 property_name = base_property_name + "/propeller-sense";
173 PropertyManager->Tie( property_name.c_str(), &Sense );
174
175 Debug(0);
176 }
177
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
180 FGPropeller::~FGPropeller()
181 {
182 delete cThrust;
183 delete cPower;
184 delete CtMach;
185 delete CpMach;
186
187 Debug(1);
188 }
189
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191
192 void FGPropeller::ResetToIC(void)
193 {
194 FGThruster::ResetToIC();
195 Vinduced = 0.0;
196 }
197
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 //
200 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
201 // We need the velocity with respect to the wind.
202 //
203 // Remembering that Torque * omega = Power, we can derive the torque on the
204 // propeller and its acceleration to give a new RPM. The current RPM will be
205 // used to calculate thrust.
206 //
207 // Because RPM could be zero, we need to be creative about what RPM is stated as.
208
209 double FGPropeller::Calculate(double EnginePower)
210 {
211 FGColumnVector3 vDXYZ = MassBalance->StructuralToBody(vXYZn);
212 const FGMatrix33& mT = Transform();
213 // Local air velocity is obtained from Stevens & Lewis' "Aircraft Control and
214 // Simualtion (3rd edition)" eqn 8.2-1
215 // Variables in.AeroUVW and in.AeroPQR include the wind and turbulence effects
216 // as computed by FGAuxiliary.
217 FGColumnVector3 localAeroVel = mT.Transposed() * (in.AeroUVW + in.AeroPQR*vDXYZ);
218 double omega, PowerAvailable;
219
220 double Vel = localAeroVel(eU);
221 double rho = in.Density;
222 double RPS = RPM/60.0;
223
224 // Calculate helical tip Mach
225 double Area = 0.25*Diameter*Diameter*M_PI;
226 double Vtip = RPS * Diameter * M_PI;
227 HelicalTipMach = sqrt(Vtip*Vtip + Vel*Vel) / in.Soundspeed;
228
229 if (RPS > 0.01) J = Vel / (Diameter * RPS); // Calculate J normally
230 else J = Vel / Diameter;
231
232 PowerAvailable = EnginePower - GetPowerRequired();
233
234 if (MaxPitch == MinPitch) { // Fixed pitch prop
235 ThrustCoeff = cThrust->GetValue(J);
236 } else { // Variable pitch prop
237 ThrustCoeff = cThrust->GetValue(J, Pitch);
238 }
239
240 // Apply optional scaling factor to Ct (default value = 1)
241 ThrustCoeff *= CtFactor;
242
243 // Apply optional Mach effects from CT_MACH table
244 if (CtMach) ThrustCoeff *= CtMach->GetValue(HelicalTipMach);
245
246 Thrust = ThrustCoeff*RPS*RPS*D4*rho;
247
248 // Induced velocity in the propeller disk area. This formula is obtained
249 // from momentum theory - see B. W. McCormick, "Aerodynamics, Aeronautics,
250 // and Flight Mechanics" 1st edition, eqn. 6.15 (propeller analysis chapter).
251 // Since Thrust and Vel can both be negative we need to adjust this formula
252 // To handle sign (direction) separately from magnitude.
253 double Vel2sum = Vel*abs(Vel) + 2.0*Thrust/(rho*Area);
254
255 if( Vel2sum > 0.0)
256 Vinduced = 0.5 * (-Vel + sqrt(Vel2sum));
257 else
258 Vinduced = 0.5 * (-Vel - sqrt(-Vel2sum));
259
260 // P-factor is simulated by a shift of the acting location of the thrust.
261 // The shift is a multiple of the angle between the propeller shaft axis
262 // and the relative wind that goes through the propeller disk.
263 if (P_Factor > 0.0001) {
264 double tangentialVel = localAeroVel.Magnitude(eV, eW);
265
266 if (tangentialVel > 0.0001) {
267 // The angle made locally by the air flow with respect to the propeller
268 // axis is influenced by the induced velocity. This attenuates the
269 // influence of a string cross wind and gives a more realistic behavior.
270 double angle = atan2(tangentialVel, Vel+Vinduced);
271 double factor = Sense * P_Factor * angle / tangentialVel;
272 SetActingLocationY( GetLocationY() + factor * localAeroVel(eW));
273 SetActingLocationZ( GetLocationZ() + factor * localAeroVel(eV));
274 }
275 }
276
277 omega = RPS*2.0*M_PI;
278
279 vFn(eX) = Thrust;
280 vTorque(eX) = -Sense*EnginePower / max(0.01, omega);
281
282 // The Ixx value and rotation speed given below are for rotation about the
283 // natural axis of the engine. The transform takes place in the base class
284 // FGForce::GetBodyForces() function.
285
286 FGColumnVector3 vH(Ixx*omega*Sense*Sense_multiplier, 0.0, 0.0);
287
288 if (omega > 0.01) ExcessTorque = PowerAvailable / omega;
289 else ExcessTorque = PowerAvailable / 1.0;
290
291 RPM = (RPS + ((ExcessTorque / Ixx) / (2.0 * M_PI)) * in.TotalDeltaT) * 60.0;
292
293 if (RPM < 0.0) RPM = 0.0; // Engine won't turn backwards
294
295 // Transform Torque and momentum first, as PQR is used in this
296 // equation and cannot be transformed itself.
297 vMn = in.PQRi*(mT*vH) + mT*vTorque;
298
299 return Thrust; // return thrust in pounds
300 }
301
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303
304 double FGPropeller::GetPowerRequired(void)
305 {
306 double cPReq;
307
308 if (MaxPitch == MinPitch) { // Fixed pitch prop
309 cPReq = cPower->GetValue(J);
310
311 } else { // Variable pitch prop
312
313 if (ConstantSpeed != 0) { // Constant Speed Mode
314
315 // do normal calculation when propeller is neither feathered nor reversed
316 // Note: This method of feathering and reversing was added to support the
317 // turboprop model. It's left here for backward compatiblity, but
318 // now feathering and reversing should be done in Manual Pitch Mode.
319 if (!Feathered) {
320 if (!Reversed) {
321
322 double rpmReq = MinRPM + (MaxRPM - MinRPM) * Advance;
323 double dRPM = rpmReq - RPM;
324 // The pitch of a variable propeller cannot be changed when the RPMs are
325 // too low - the oil pump does not work.
326 if (RPM > 200) Pitch -= dRPM * in.TotalDeltaT;
327 if (Pitch < MinPitch) Pitch = MinPitch;
328 else if (Pitch > MaxPitch) Pitch = MaxPitch;
329
330 } else { // Reversed propeller
331
332 // when reversed calculate propeller pitch depending on throttle lever position
333 // (beta range for taxing full reverse for braking)
334 double PitchReq = MinPitch - ( MinPitch - ReversePitch ) * Reverse_coef;
335 // The pitch of a variable propeller cannot be changed when the RPMs are
336 // too low - the oil pump does not work.
337 if (RPM > 200) Pitch += (PitchReq - Pitch) / 200;
338 if (RPM > MaxRPM) {
339 Pitch += (MaxRPM - RPM) / 50;
340 if (Pitch < ReversePitch) Pitch = ReversePitch;
341 else if (Pitch > MaxPitch) Pitch = MaxPitch;
342 }
343 }
344
345 } else { // Feathered propeller
346 // ToDo: Make feathered and reverse settings done via FGKinemat
347 Pitch += (MaxPitch - Pitch) / 300; // just a guess (about 5 sec to fully feathered)
348 }
349
350 } else { // Manual Pitch Mode, pitch is controlled externally
351
352 }
353
354 cPReq = cPower->GetValue(J, Pitch);
355 }
356
357 // Apply optional scaling factor to Cp (default value = 1)
358 cPReq *= CpFactor;
359
360 // Apply optional Mach effects from CP_MACH table
361 if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);
362
363 double RPS = RPM / 60.0;
364 double local_RPS = RPS < 0.01 ? 0.01 : RPS;
365
366 PowerRequired = cPReq*local_RPS*local_RPS*local_RPS*D5*in.Density;
367
368 return PowerRequired;
369 }
370
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372
373 FGColumnVector3 FGPropeller::GetPFactor() const
374 {
375 // These are moments in lbf per ft : the lever arm along Z generates a moment
376 // along the pitch direction.
377 double p_pitch = Thrust * Sense * (GetActingLocationZ() - GetLocationZ()) / 12.0;
378 // The lever arm along Y generates a moment along the yaw direction.
379 double p_yaw = Thrust * Sense * (GetActingLocationY() - GetLocationY()) / 12.0;
380
381 return FGColumnVector3(0.0, p_pitch, p_yaw);
382 }
383
384 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385
386 string FGPropeller::GetThrusterLabels(int id, const string& delimeter)
387 {
388 std::ostringstream buf;
389
390 buf << Name << " Torque (engine " << id << ")" << delimeter
391 << Name << " PFactor Pitch (engine " << id << ")" << delimeter
392 << Name << " PFactor Yaw (engine " << id << ")" << delimeter
393 << Name << " Thrust (engine " << id << " in lbs)" << delimeter;
394 if (IsVPitch())
395 buf << Name << " Pitch (engine " << id << ")" << delimeter;
396 buf << Name << " RPM (engine " << id << ")";
397
398 return buf.str();
399 }
400
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402
403 string FGPropeller::GetThrusterValues(int id, const string& delimeter)
404 {
405 std::ostringstream buf;
406
407 FGColumnVector3 vPFactor = GetPFactor();
408 buf << vTorque(eX) << delimeter
409 << vPFactor(ePitch) << delimeter
410 << vPFactor(eYaw) << delimeter
411 << Thrust << delimeter;
412 if (IsVPitch())
413 buf << Pitch << delimeter;
414 buf << RPM;
415
416 return buf.str();
417 }
418
419 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
420 // The bitmasked value choices are as follows:
421 // unset: In this case (the default) JSBSim would only print
422 // out the normally expected messages, essentially echoing
423 // the config files as they are read. If the environment
424 // variable is not set, debug_lvl is set to 1 internally
425 // 0: This requests JSBSim not to output any messages
426 // whatsoever.
427 // 1: This value explicity requests the normal JSBSim
428 // startup messages
429 // 2: This value asks for a message to be printed out when
430 // a class is instantiated
431 // 4: When this value is set, a message is displayed when a
432 // FGModel object executes its Run() method
433 // 8: When this value is set, various runtime state variables
434 // are printed out periodically
435 // 16: When set various parameters are sanity checked and
436 // a message is printed out when they go out of bounds
437
438 void FGPropeller::Debug(int from)
439 {
440 if (debug_lvl <= 0) return;
441
442 if (debug_lvl & 1) { // Standard console startup message output
443 if (from == 0) { // Constructor
444 cout << "\n Propeller Name: " << Name << endl;
445 cout << " IXX = " << Ixx << endl;
446 cout << " Diameter = " << Diameter << " ft." << endl;
447 cout << " Number of Blades = " << numBlades << endl;
448 cout << " Gear Ratio = " << GearRatio << endl;
449 cout << " Minimum Pitch = " << MinPitch << endl;
450 cout << " Maximum Pitch = " << MaxPitch << endl;
451 cout << " Minimum RPM = " << MinRPM << endl;
452 cout << " Maximum RPM = " << MaxRPM << endl;
453 // Tables are being printed elsewhere...
454 // cout << " Thrust Coefficient: " << endl;
455 // cThrust->Print();
456 // cout << " Power Coefficient: " << endl;
457 // cPower->Print();
458 // cout << " Mach Thrust Coefficient: " << endl;
459 // if(CtMach)
460 // {
461 // CtMach->Print();
462 // } else {
463 // cout << " NONE" << endl;
464 // }
465 // cout << " Mach Power Coefficient: " << endl;
466 // if(CpMach)
467 // {
468 // CpMach->Print();
469 // } else {
470 // cout << " NONE" << endl;
471 // }
472 }
473 }
474 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
475 if (from == 0) cout << "Instantiated: FGPropeller" << endl;
476 if (from == 1) cout << "Destroyed: FGPropeller" << endl;
477 }
478 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
479 }
480 if (debug_lvl & 8 ) { // Runtime state variables
481 }
482 if (debug_lvl & 16) { // Sanity checking
483 }
484 if (debug_lvl & 64) {
485 if (from == 0) { // Constructor
486 }
487 }
488 }
489 }