1 /*******************************************************************************
8 ------------- Copyright (C) 1999 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 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
34 09/03/99 JSB Changed Rocket thrust equation to correct -= Thrust instead of
35 += Thrust (thanks to Tony Peden)
37 ********************************************************************************
39 *******************************************************************************/
42 # include <simgear/compiler.h>
43 # ifdef FG_HAVE_STD_INCLUDES
54 #include "FGFDMExec.h"
55 #include "FGAtmosphere.h"
57 #include "FGAircraft.h"
58 #include "FGTranslation.h"
59 #include "FGRotation.h"
60 #include "FGPosition.h"
61 #include "FGAuxiliary.h"
65 /*******************************************************************************
66 ************************************ CODE **************************************
67 *******************************************************************************/
70 FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, int num)
77 State = FDMExec->GetState();
78 Atmosphere = FDMExec->GetAtmosphere();
79 FCS = FDMExec->GetFCS();
80 Aircraft = FDMExec->GetAircraft();
81 Translation = FDMExec->GetTranslation();
82 Rotation = FDMExec->GetRotation();
83 Position = FDMExec->GetPosition();
84 Auxiliary = FDMExec->GetAuxiliary();
85 Output = FDMExec->GetOutput();
88 fullpath = enginePath + "/" + engineName + ".dat";
89 ifstream enginefile(fullpath.c_str());
94 if (tag == "ROCKET") Type = etRocket;
95 else if (tag == "PISTON") Type = etPiston;
96 else if (tag == "TURBOPROP") Type = etTurboProp;
97 else if (tag == "TURBOJET") Type = etTurboJet;
98 else Type = etUnknown;
103 cerr << "Unknown engine type: " << tag << endl;
109 enginefile >> BrakeHorsePower;
110 enginefile >> MaxThrottle;
111 enginefile >> MinThrottle;
112 enginefile >> SLFuelFlowMax;
113 enginefile >> SpeedSlope;
114 enginefile >> SpeedIntercept;
115 enginefile >> AltitudeSlope;
122 enginefile >> SLThrustMax;
123 enginefile >> VacThrustMax;
124 enginefile >> MaxThrottle;
125 enginefile >> MinThrottle;
126 enginefile >> SLFuelFlowMax;
127 enginefile >> SLOxiFlowMax;
133 cerr << "Unable to open engine definition file " << fullpath << endl;
137 Thrust = PctPower = 0.0;
138 Starved = Flameout = false;
142 FGEngine::~FGEngine(void)
147 float FGEngine::CalcRocketThrust(void)
151 Throttle = FCS->GetThrottlePos(EngineNumber);
152 lastThrust = Thrust; // last actual thrust
154 if (Throttle < MinThrottle || Starved) {
155 PctPower = Thrust = 0.0; // desired thrust
158 PctPower = Throttle / MaxThrottle;
159 Thrust = PctPower*((1.0 - Atmosphere->GetDensityRatio())*(VacThrustMax - SLThrustMax) +
160 SLThrustMax); // desired thrust
164 Thrust -= 0.8*(Thrust - lastThrust); // actual thrust
170 float FGEngine::CalcPistonThrust(void)
174 Throttle = FCS->GetThrottlePos(EngineNumber);
177 v=Translation->GetVt();
183 pa=(SpeedSlope*v + SpeedIntercept)*(1 +AltitudeSlope*h)*BrakeHorsePower;
184 Thrust= Throttle*(pa*HPTOFTLBSSEC)/v;
190 float FGEngine::CalcThrust(void)
194 return CalcRocketThrust();
197 return CalcPistonThrust();
205 float FGEngine::CalcFuelNeed() {
206 FuelNeed = SLFuelFlowMax*PctPower;
211 float FGEngine::CalcOxidizerNeed() {
212 OxidizerNeed = SLOxiFlowMax*PctPower;