1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGTurboProp.cpp
4 Author: Jiri "Javky" Javurek
5 based on SimTurbine and Turbine engine from David Culp
6 Date started: 05/14/2004
7 Purpose: This module models a turbo propeller engine.
9 ------------- Copyright (C) 2004 (javky@email.cz) ---------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class descends from the FGEngine class and models a Turbo propeller engine
32 based on parameters given in the engine config file for this class
35 --------------------------------------------------------------------------------
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include "FGTurboProp.h"
48 #include "FGPropeller.h"
52 static const char *IdSrc = "$Id$";
53 static const char *IdHdr = ID_TURBOPROP;
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 FGTurboProp::FGTurboProp(FGFDMExec* exec, Element *el, int engine_number)
60 : FGEngine(exec, el, engine_number)
68 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FGTurboProp::~FGTurboProp()
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 bool FGTurboProp::Load(FGFDMExec* exec, Element *el)
80 MaxStartingTime = 999999; //very big timeout -> infinite
83 // ToDo: Need to make sure units are properly accounted for below.
85 if (el->FindElement("milthrust"))
86 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
87 if (el->FindElement("idlen1"))
88 IdleN1 = el->FindElementValueAsNumber("idlen1");
89 if (el->FindElement("idlen2"))
90 IdleN2 = el->FindElementValueAsNumber("idlen1");
91 if (el->FindElement("maxn1"))
92 MaxN1 = el->FindElementValueAsNumber("maxn1");
93 if (el->FindElement("maxn2"))
94 MaxN2 = el->FindElementValueAsNumber("maxn2");
95 if (el->FindElement("betarangeend"))
96 BetaRangeThrottleEnd = el->FindElementValueAsNumber("betarangeend")/100.0;
97 if (el->FindElement("reversemaxpower"))
98 ReverseMaxPower = el->FindElementValueAsNumber("reversemaxpower")/100.0;
100 if (el->FindElement("maxpower"))
101 MaxPower = el->FindElementValueAsNumber("maxpower");
102 if (el->FindElement("idlefuelflow"))
103 IdleFF = el->FindElementValueAsNumber("idlefuelflow");
104 if (el->FindElement("psfc"))
105 PSFC = el->FindElementValueAsNumber("psfc");
106 if (el->FindElement("n1idle_max_delay"))
107 Idle_Max_Delay = el->FindElementValueAsNumber("n1idle_max_delay");
108 if (el->FindElement("maxstartingtime"))
109 MaxStartingTime = el->FindElementValueAsNumber("maxstartingtime");
110 if (el->FindElement("startern1"))
111 StarterN1 = el->FindElementValueAsNumber("startern1");
112 if (el->FindElement("ielumaxtorque"))
113 Ielu_max_torque = el->FindElementValueAsNumber("ielumaxtorque");
114 if (el->FindElement("itt_delay"))
115 ITT_Delay = el->FindElementValueAsNumber("itt_delay");
117 Element *table_element;
119 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
122 table_element = el->FindNextElement("table");
123 if (!table_element) break;
124 name = table_element->GetAttributeValue("name");
125 if (name == "EnginePowerVC") {
126 EnginePowerVC = new FGTable(PropertyManager, table_element);
127 } else if (name == "EnginePowerRPM_N1") {
128 EnginePowerRPM_N1 = new FGTable(PropertyManager, table_element);
129 } else if (name == "ITT_N1") {
130 ITT_N1 = new FGTable(PropertyManager, table_element);
132 cerr << "Unknown table type: " << name << " in turbine definition." <<
137 // Pre-calculations and initializations
140 N1_factor = MaxN1 - IdleN1;
141 N2_factor = MaxN2 - IdleN2;
142 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
143 if (IdleFF==-1) IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
145 cout << "ENG POWER:" << EnginePowerRPM_N1->GetValue(1200,90) << "\n";
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 // The main purpose of Calculate() is to determine what phase the engine should
152 // be in, then call the corresponding function.
154 double FGTurboProp::Calculate(void)
156 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
157 dt = State->Getdt() * Propulsion->GetRate();
159 ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
161 Prop_RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
162 if (Thruster->GetType() == FGThruster::ttPropeller) {
163 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
164 ((FGPropeller*)Thruster)->SetFeather(FCS->GetPropFeather(EngineNumber));
165 ((FGPropeller*)Thruster)->SetReverse(Reversed);
167 ((FGPropeller*)Thruster)->SetReverseCoef(ThrottleCmd);
169 ((FGPropeller*)Thruster)->SetReverseCoef(0.0);
174 if (ThrottleCmd < BetaRangeThrottleEnd) {
175 ThrottleCmd = 0.0; // idle when in Beta-range
178 ThrottleCmd = (ThrottleCmd-BetaRangeThrottleEnd)/(1-BetaRangeThrottleEnd) * ReverseMaxPower;
182 // When trimming is finished check if user wants engine OFF or RUNNING
183 if ((phase == tpTrim) && (dt > 0)) {
184 if (Running && !Starved) {
188 OilTemp_degK = 366.0;
194 Eng_Temperature = TAT;
195 OilTemp_degK = TAT+273.15;
199 if (!Running && Starter) {
200 if (phase == tpOff) {
202 if (StartTime < 0) StartTime=0;
205 if (!Running && !Cutoff && (N1 > 15.0)) {
209 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
210 if (dt == 0) phase = tpTrim;
211 if (Starved) phase = tpOff;
212 if (Condition >= 10) {
218 if (Ielu_max_torque > 0
219 && -Ielu_max_torque > ((FGPropeller*)(Thruster))->GetTorque()
220 && ThrottleCmd >= OldThrottle ) {
221 ThrottleCmd = OldThrottle - 0.1 * dt; //IELU down
222 Ielu_intervent = true;
223 } else if (Ielu_max_torque > 0 && Ielu_intervent && ThrottleCmd >= OldThrottle) {
224 ThrottleCmd = OldThrottle;
225 ThrottleCmd = OldThrottle + 0.05 * dt; //IELU up
226 Ielu_intervent = true;
228 Ielu_intervent = false;
231 Ielu_intervent = false;
233 OldThrottle = ThrottleCmd;
236 case tpOff: Eng_HP = Off(); break;
237 case tpRun: Eng_HP = Run(); break;
238 case tpSpinUp: Eng_HP = SpinUp(); break;
239 case tpStart: Eng_HP = Start(); break;
243 //printf ("EngHP: %lf / Requi: %lf\n",Eng_HP,Prop_Required_Power);
244 return Thruster->Calculate((Eng_HP * hptoftlbssec)-Thruster->GetPowerRequired());
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 double FGTurboProp::Off(void)
251 double qbar = Auxiliary->Getqbar();
252 Running = false; EngStarting = false;
254 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 800.0, 800.0);
256 //allow the air turn with generator
257 N1 = ExpSeek(&N1, qbar/15.0, Idle_Max_Delay*2.5, Idle_Max_Delay * 5);
259 OilTemp_degK = ExpSeek(&OilTemp_degK,273.15 + TAT, 400 , 400);
261 Eng_Temperature = ExpSeek(&Eng_Temperature,TAT,300,400);
262 double ITT_goal = ITT_N1->GetValue(N1,0.1) + ((N1>20) ? 0.0 : (20-N1)/20.0 * Eng_Temperature);
263 Eng_ITT_degC = ExpSeek(&Eng_ITT_degC,ITT_goal,ITT_Delay,ITT_Delay*1.2);
265 OilPressure_psi = (N1/100.0*0.25+(0.1-(OilTemp_degK-273.15)*0.1/80.0)*N1/100.0) / 7692.0e-6; //from MPa to psi
267 ConsumeFuel(); // for possible setting Starved = false when fuel tank
268 // is refilled (fuel crossfeed etc.)
270 if (Prop_RPM>5) return -0.012; // friction in engine when propeller spining (estimate)
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 double FGTurboProp::Run(void)
278 double thrust = 0.0, EngPower_HP, eff_coef;
279 Running = true; Starter = false; EngStarting = false;
283 N1 = ExpSeek(&N1, IdleN1 + ThrottleCmd * N1_factor, Idle_Max_Delay, Idle_Max_Delay * 2.4);
285 EngPower_HP = EnginePowerRPM_N1->GetValue(Prop_RPM,N1);
286 EngPower_HP *= EnginePowerVC->GetValue();
287 if (EngPower_HP > MaxPower) EngPower_HP = MaxPower;
289 eff_coef = 9.333 - (N1)/12; // 430%Fuel at 60%N1
290 FuelFlow_pph = PSFC * EngPower_HP * eff_coef;
292 Eng_Temperature = ExpSeek(&Eng_Temperature,Eng_ITT_degC,300,400);
293 double ITT_goal = ITT_N1->GetValue((N1-old_N1)*300+N1,1);
294 Eng_ITT_degC = ExpSeek(&Eng_ITT_degC,ITT_goal,ITT_Delay,ITT_Delay*1.2);
296 OilPressure_psi = (N1/100.0*0.25+(0.1-(OilTemp_degK-273.15)*0.1/80.0)*N1/100.0) / 7692.0e-6; //from MPa to psi
298 EPR = 1.0 + thrust/MilThrust;
300 OilTemp_degK = Seek(&OilTemp_degK, 353.15, 0.4-N1*0.001, 0.04);
304 if (Cutoff) phase = tpOff;
305 if (Starved) phase = tpOff;
310 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 double FGTurboProp::SpinUp(void)
315 Running = false; EngStarting = true;
318 if (!GeneratorPower) {
325 N1 = ExpSeek(&N1, StarterN1, Idle_Max_Delay * 6, Idle_Max_Delay * 2.4);
327 Eng_Temperature = ExpSeek(&Eng_Temperature,TAT,300,400);
328 double ITT_goal = ITT_N1->GetValue(N1,0.1) + ((N1>20) ? 0.0 : (20-N1)/20.0 * Eng_Temperature);
329 Eng_ITT_degC = ExpSeek(&Eng_ITT_degC,ITT_goal,ITT_Delay,ITT_Delay*1.2);
331 OilTemp_degK = ExpSeek(&OilTemp_degK,273.15 + TAT, 400 , 400);
333 OilPressure_psi = (N1/100.0*0.25+(0.1-(OilTemp_degK-273.15)*0.1/80.0)*N1/100.0) / 7692.0e-6; //from MPa to psi
334 NozzlePosition = 1.0;
336 EngPower_HP = EnginePowerRPM_N1->GetValue(Prop_RPM,N1);
337 EngPower_HP *= EnginePowerVC->GetValue();
338 if (EngPower_HP > MaxPower) EngPower_HP = MaxPower;
340 if (StartTime>=0) StartTime+=dt;
341 if (StartTime > MaxStartingTime && MaxStartingTime > 0) { //start failed due timeout
346 ConsumeFuel(); // for possible setting Starved = false when fuel tank
347 // is refilled (fuel crossfeed etc.)
352 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 double FGTurboProp::Start(void)
356 double EngPower_HP,eff_coef;
358 if ((N1 > 15.0) && !Starved) { // minimum 15% N2 needed for start
360 Cranking = true; // provided for sound effects signal
362 EngPower_HP = EnginePowerRPM_N1->GetValue(Prop_RPM,N1);
363 EngPower_HP *= EnginePowerVC->GetValue();
364 if (EngPower_HP > MaxPower) EngPower_HP = MaxPower;
365 N1 = ExpSeek(&N1, IdleN1*1.1, Idle_Max_Delay*4, Idle_Max_Delay * 2.4);
366 eff_coef = 9.333 - (N1)/12; // 430%Fuel at 60%N1
367 FuelFlow_pph = PSFC * EngPower_HP * eff_coef;
368 Eng_Temperature = ExpSeek(&Eng_Temperature,Eng_ITT_degC,300,400);
369 double ITT_goal = ITT_N1->GetValue((N1-old_N1)*300+N1,1);
370 Eng_ITT_degC = ExpSeek(&Eng_ITT_degC,ITT_goal,ITT_Delay,ITT_Delay*1.2);
372 OilPressure_psi = (N1/100.0*0.25+(0.1-(OilTemp_degK-273.15)*0.1/80.0)*N1/100.0) / 7692.0e-6; //from MPa to psi
373 OilTemp_degK = Seek(&OilTemp_degK, 353.15, 0.4-N1*0.001, 0.04);
383 } else { // no start if N2 < 15% or Starved
394 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 double FGTurboProp::CalcFuelNeed(void)
398 double dT = State->Getdt() * Propulsion->GetRate();
399 FuelFlowRate = FuelFlow_pph / 3600.0;
400 FuelExpended = FuelFlowRate * dT;
404 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 double FGTurboProp::Seek(double *var, double target, double accel, double decel)
411 if (v < target) v = target;
412 } else if (v < target) {
414 if (v > target) v = target;
419 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 double FGTurboProp::ExpSeek(double *var, double target, double accel_tau, double decel_tau)
423 // exponential delay instead of the linear delay used in Seek
426 v = (v - target) * exp ( -dt / decel_tau) + target;
427 } else if (v < target) {
428 v = (target - v) * (1 - exp ( -dt / accel_tau)) + v;
433 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 void FGTurboProp::SetDefaults(void)
437 Name = "Not defined";
447 NozzlePosition = 1.0;
459 Ielu_intervent=false;
461 Idle_Max_Delay = 1.0;
464 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
467 string FGTurboProp::GetEngineLabels(string delimeter)
469 std::ostringstream buf;
471 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
472 << Name << "_N2[" << EngineNumber << "]" << delimeter
473 << Name << "__PwrAvailJVK[" << EngineNumber << "]" << delimeter
474 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
479 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
481 string FGTurboProp::GetEngineValues(string delimeter)
483 std::ostringstream buf;
485 buf << N1 << delimeter
487 << Thruster->GetThrusterValues(EngineNumber,delimeter);
492 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494 int FGTurboProp::InitRunning(void)
496 State->SuspendIntegration();
501 State->ResumeIntegration();
505 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
507 void FGTurboProp::bindmodel()
509 string property_name, base_property_name;
510 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
511 property_name = base_property_name + "/n1";
512 PropertyManager->Tie( property_name.c_str(), &N1);
513 property_name = base_property_name + "/n2";
514 PropertyManager->Tie( property_name.c_str(), &N2);
515 property_name = base_property_name + "/reverser";
516 PropertyManager->Tie( property_name.c_str(), &Reversed);
519 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520 // The bitmasked value choices are as follows:
521 // unset: In this case (the default) JSBSim would only print
522 // out the normally expected messages, essentially echoing
523 // the config files as they are read. If the environment
524 // variable is not set, debug_lvl is set to 1 internally
525 // 0: This requests JSBSim not to output any messages
527 // 1: This value explicity requests the normal JSBSim
529 // 2: This value asks for a message to be printed out when
530 // a class is instantiated
531 // 4: When this value is set, a message is displayed when a
532 // FGModel object executes its Run() method
533 // 8: When this value is set, various runtime state variables
534 // are printed out periodically
535 // 16: When set various parameters are sanity checked and
536 // a message is printed out when they go out of bounds
538 void FGTurboProp::Debug(int from)
540 if (debug_lvl <= 0) return;
542 if (debug_lvl & 1) { // Standard console startup message output
543 if (from == 0) { // Constructor
546 if (from == 2) { // called from Load()
547 cout << "\n ****MUJ MOTOR TURBOPROP****\n";
548 cout << "\n Engine Name: " << Name << endl;
549 cout << " MilThrust: " << MilThrust << endl;
550 cout << " IdleN1: " << IdleN1 << endl;
551 cout << " MaxN1: " << MaxN1 << endl;
556 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
557 if (from == 0) cout << "Instantiated: FGTurboProp" << endl;
558 if (from == 1) cout << "Destroyed: FGTurboProp" << endl;
560 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
562 if (debug_lvl & 8 ) { // Runtime state variables
564 if (debug_lvl & 16) { // Sanity checking
566 if (debug_lvl & 64) {
567 if (from == 0) { // Constructor
568 cout << IdSrc << endl;
569 cout << IdHdr << endl;