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 *******************************************************************************/
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
46 #include "FGAircraft.h"
47 #include "FGTranslation.h"
48 #include "FGRotation.h"
49 #include "FGPosition.h"
50 #include "FGAuxiliary.h"
53 /*******************************************************************************
54 ************************************ CODE **************************************
55 *******************************************************************************/
58 FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName,
66 State = FDMExec->GetState();
67 Atmosphere = FDMExec->GetAtmosphere();
68 FCS = FDMExec->GetFCS();
69 Aircraft = FDMExec->GetAircraft();
70 Translation = FDMExec->GetTranslation();
71 Rotation = FDMExec->GetRotation();
72 Position = FDMExec->GetPosition();
73 Auxiliary = FDMExec->GetAuxiliary();
74 Output = FDMExec->GetOutput();
77 fullpath = enginePath + "/" + engineName + ".dat";
78 ifstream enginefile(fullpath.c_str());
83 if (tag == "ROCKET") Type = etRocket;
84 else if (tag == "PISTON") Type = etPiston;
85 else if (tag == "TURBOPROP") Type = etTurboProp;
86 else if (tag == "TURBOJET") Type = etTurboJet;
87 else Type = etUnknown;
92 enginefile >> SLThrustMax;
93 enginefile >> VacThrustMax;
94 enginefile >> MaxThrottle;
95 enginefile >> MinThrottle;
96 enginefile >> SLFuelFlowMax;
98 enginefile >> SLOxiFlowMax;
101 cerr << "Unable to open engine definition file " << engineName << endl;
106 Starved = Flameout = false;
110 FGEngine::~FGEngine(void)
115 float FGEngine::CalcRocketThrust(void)
119 Throttle = FCS->GetThrottle(EngineNumber);
120 lastThrust = Thrust; // last actual thrust
122 if (Throttle < MinThrottle || Starved) {
123 PctPower = Thrust = 0.0; // desired thrust
126 PctPower = Throttle / MaxThrottle;
127 Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
128 SLThrustMax); // desired thrust
132 Thrust += 0.8*(Thrust - lastThrust); // actual thrust
138 float FGEngine::CalcPistonThrust(void)
144 float FGEngine::CalcThrust(void)
148 return CalcRocketThrust();
151 return CalcPistonThrust();
159 float FGEngine::CalcFuelNeed() {
160 FuelNeed = SLFuelFlowMax*PctPower;
165 float FGEngine::CalcOxidizerNeed() {
166 OxidizerNeed = SLOxiFlowMax*PctPower;