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 --------------------------------------------------------------------------------
35 ********************************************************************************
37 *******************************************************************************/
40 # include <Include/compiler.h>
41 # ifdef FG_HAVE_STD_INCLUDES
52 #include "FGFDMExec.h"
53 #include "FGAtmosphere.h"
55 #include "FGAircraft.h"
56 #include "FGTranslation.h"
57 #include "FGRotation.h"
58 #include "FGPosition.h"
59 #include "FGAuxiliary.h"
62 /*******************************************************************************
63 ************************************ CODE **************************************
64 *******************************************************************************/
67 FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName, int num)
74 State = FDMExec->GetState();
75 Atmosphere = FDMExec->GetAtmosphere();
76 FCS = FDMExec->GetFCS();
77 Aircraft = FDMExec->GetAircraft();
78 Translation = FDMExec->GetTranslation();
79 Rotation = FDMExec->GetRotation();
80 Position = FDMExec->GetPosition();
81 Auxiliary = FDMExec->GetAuxiliary();
82 Output = FDMExec->GetOutput();
85 fullpath = enginePath + "/" + engineName + ".dat";
86 ifstream enginefile(fullpath.c_str());
91 if (tag == "ROCKET") Type = etRocket;
92 else if (tag == "PISTON") Type = etPiston;
93 else if (tag == "TURBOPROP") Type = etTurboProp;
94 else if (tag == "TURBOJET") Type = etTurboJet;
95 else Type = etUnknown;
100 enginefile >> SLThrustMax;
101 enginefile >> VacThrustMax;
102 enginefile >> MaxThrottle;
103 enginefile >> MinThrottle;
104 enginefile >> SLFuelFlowMax;
106 enginefile >> SLOxiFlowMax;
109 cerr << "Unable to open engine definition file " << engineName << endl;
114 Starved = Flameout = false;
118 FGEngine::~FGEngine(void)
123 float FGEngine::CalcRocketThrust(void)
127 Throttle = FCS->GetThrottle(EngineNumber);
128 lastThrust = Thrust; // last actual thrust
130 if (Throttle < MinThrottle || Starved) {
131 PctPower = Thrust = 0.0; // desired thrust
134 PctPower = Throttle / MaxThrottle;
135 Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
136 SLThrustMax); // desired thrust
140 Thrust += 0.8*(Thrust - lastThrust); // actual thrust
146 float FGEngine::CalcPistonThrust(void)
152 float FGEngine::CalcThrust(void)
156 return CalcRocketThrust();
159 return CalcPistonThrust();
167 float FGEngine::CalcFuelNeed() {
168 FuelNeed = SLFuelFlowMax*PctPower;
173 float FGEngine::CalcOxidizerNeed() {
174 OxidizerNeed = SLOxiFlowMax*PctPower;