1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 09/12/2000
6 Purpose: This module models a Piston engine
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 --------------------------------------------------------------------------------
30 This class descends from the FGEngine class and models a Piston engine based on
31 parameters given in the engine config file for this class
34 --------------------------------------------------------------------------------
35 09/12/2000 JSB Created
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_PISTON;
47 extern short debug_lvl;
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec)
57 Name = Eng_cfg->GetValue("NAME");
58 Eng_cfg->GetNextConfigLine();
59 while (Eng_cfg->GetValue() != "/FG_PISTON") {
61 if (token == "BRAKEHORSEPOWER") *Eng_cfg >> BrakeHorsePower;
62 else if (token == "MAXTHROTTLE") *Eng_cfg >> MaxThrottle;
63 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
64 else if (token == "SLFUELFLOWMAX") *Eng_cfg >> SLFuelFlowMax;
65 else if (token == "SPEEDSLOPE") *Eng_cfg >> SpeedSlope;
66 else if (token == "SPEEDINTERCEPT") *Eng_cfg >> SpeedIntercept;
67 else if (token == "ALTITUDESLOPE") *Eng_cfg >> AltitudeSlope;
68 else cerr << "Unhandled token in Engine config file: " << token << endl;
72 cout << "\n Engine Name: " << Name << endl;
73 cout << " BrakeHorsePower = " << BrakeHorsePower << endl;
74 cout << " MaxThrottle = " << MaxThrottle << endl;
75 cout << " MinThrottle = " << MinThrottle << endl;
76 cout << " SLFuelFlowMax = " << SLFuelFlowMax << endl;
77 cout << " SpeedSlope = " << SpeedSlope << endl;
78 cout << " SpeedIntercept = " << SpeedIntercept << endl;
79 cout << " AltitudeSlope = " << AltitudeSlope << endl;
85 if (debug_lvl & 2) cout << "Instantiated: FGPiston" << endl;
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 if (debug_lvl & 2) cout << "Destroyed: FGPiston" << endl;
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 float FGPiston::Calculate(float PowerRequired)
99 float h,EngineMaxPower;
103 Throttle = FCS->GetThrottlePos(EngineNumber);
105 h = Position->Geth();
109 EngineMaxPower = (1 + AltitudeSlope*h)*BrakeHorsePower;
110 PowerAvailable = Throttle*EngineMaxPower*HPTOFTLBSSEC - PowerRequired;
112 return PowerAvailable;
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 void FGPiston::Debug(void)
119 //TODO: Add your source code here