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 static const char *IdSrc = "$Header$";
66 static const char *IdHdr = "ID_ENGINE";
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, int num) {
79 State = FDMExec->GetState();
80 Atmosphere = FDMExec->GetAtmosphere();
81 FCS = FDMExec->GetFCS();
82 Aircraft = FDMExec->GetAircraft();
83 Translation = FDMExec->GetTranslation();
84 Rotation = FDMExec->GetRotation();
85 Position = FDMExec->GetPosition();
86 Auxiliary = FDMExec->GetAuxiliary();
87 Output = FDMExec->GetOutput();
92 fullpath = enginePath + "/" + engineName + ".xml";
94 fullpath = enginePath + ";" + engineName + ".xml";
97 cout << " Reading engine: " << engineName << " from file: " << fullpath << endl;
98 ifstream enginefile(fullpath.c_str());
103 if (tag == "ROCKET") Type = etRocket;
104 else if (tag == "PISTON") Type = etPiston;
105 else if (tag == "TURBOPROP") Type = etTurboProp;
106 else if (tag == "TURBOJET") Type = etTurboJet;
107 else Type = etUnknown;
112 cerr << "Unsupported Engine type" << tag << endl;
115 cerr << "Unknown engine type: " << tag << endl;
121 enginefile >> EnginePitch;
122 enginefile >> EngineYaw;
123 enginefile >> BrakeHorsePower;
124 enginefile >> MaxThrottle;
125 enginefile >> MinThrottle;
126 enginefile >> SLFuelFlowMax;
127 enginefile >> SpeedSlope;
128 enginefile >> SpeedIntercept;
129 enginefile >> AltitudeSlope;
136 enginefile >> EnginePitch;
137 enginefile >> EngineYaw;
138 enginefile >> SLThrustMax;
139 enginefile >> VacThrustMax;
140 enginefile >> MaxThrottle;
141 enginefile >> MinThrottle;
142 enginefile >> SLFuelFlowMax;
143 enginefile >> SLOxiFlowMax;
149 cerr << "Unable to open engine definition file " << fullpath.c_str() << endl;
153 Thrust = PctPower = 0.0;
154 Starved = Flameout = false;
159 FGEngine::~FGEngine(void) {}
162 float FGEngine::CalcRocketThrust(void) {
165 Throttle = FCS->GetThrottlePos(EngineNumber);
166 lastThrust = Thrust; // last actual thrust
168 if (Throttle < MinThrottle || Starved) {
169 PctPower = Thrust = 0.0; // desired thrust
172 PctPower = Throttle / MaxThrottle;
173 Thrust = PctPower*((1.0 - Atmosphere->GetDensityRatio())*(VacThrustMax - SLThrustMax) +
174 SLThrustMax); // desired thrust
179 if(State->Getdt() > 0.0) {
180 Thrust -= 0.8*(Thrust - lastThrust); // actual thrust
187 float FGEngine::CalcPistonThrust(void) {
190 Throttle = FCS->GetThrottlePos(EngineNumber);
193 v = Translation->GetVt();
194 h = Position->Geth();
201 pa=(SpeedSlope*v + SpeedIntercept)*(1 +AltitudeSlope*h)*BrakeHorsePower;
203 Thrust = Throttle*(pa*HPTOFTLBSSEC)/v;
209 float FGEngine::CalcThrust(void) {
213 return CalcRocketThrust();
216 return CalcPistonThrust();
227 float FGEngine::CalcFuelNeed() {
228 FuelNeed = SLFuelFlowMax*PctPower;
233 float FGEngine::CalcOxidizerNeed() {
234 OxidizerNeed = SLOxiFlowMax*PctPower;