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 --------------------------------------------------------------------------------
36 ********************************************************************************
38 *******************************************************************************/
47 #include "FGFDMExec.h"
48 #include "FGAtmosphere.h"
50 #include "FGAircraft.h"
51 #include "FGTranslation.h"
52 #include "FGRotation.h"
53 #include "FGPosition.h"
54 #include "FGAuxiliary.h"
57 /*******************************************************************************
58 ************************************ CODE **************************************
59 *******************************************************************************/
62 FGEngine::FGEngine(FGFDMExec* fdex, char *engineName, int num)
69 State = FDMExec->GetState();
70 Atmosphere = FDMExec->GetAtmosphere();
71 FCS = FDMExec->GetFCS();
72 Aircraft = FDMExec->GetAircraft();
73 Translation = FDMExec->GetTranslation();
74 Rotation = FDMExec->GetRotation();
75 Position = FDMExec->GetPosition();
76 Auxiliary = FDMExec->GetAuxiliary();
77 Output = FDMExec->GetOutput();
79 strcpy(Name, engineName);
80 sprintf(fullpath,"/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/engine/%s.dat", engineName);
81 ifstream enginefile(fullpath);
85 if (strstr(tag,"ROCKET")) Type = 0;
86 else if (strstr(tag,"PISTON")) Type = 1;
87 else if (strstr(tag,"TURBOPROP")) Type = 2;
88 else if (strstr(tag,"TURBOJET")) Type = 3;
93 enginefile >> SLThrustMax;
94 enginefile >> VacThrustMax;
95 enginefile >> MaxThrottle;
96 enginefile >> MinThrottle;
97 enginefile >> SLFuelFlowMax;
99 enginefile >> SLOxiFlowMax;
102 cerr << "Unable to open engine definition file " << engineName << endl;
107 Starved = Flameout = false;
111 FGEngine::~FGEngine(void)
116 float FGEngine::CalcRocketThrust(void)
120 Throttle = FCS->GetThrottle(EngineNumber);
121 lastThrust = Thrust; // last actual thrust
123 if (Throttle < MinThrottle || Starved) {
124 PctPower = Thrust = 0.0; // desired thrust
127 PctPower = Throttle / MaxThrottle;
128 Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
129 SLThrustMax); // desired thrust
133 Thrust += 0.8*(Thrust - lastThrust); // actual thrust
139 float FGEngine::CalcPistonThrust(void)
145 float FGEngine::CalcThrust(void)
149 return CalcRocketThrust();
152 return CalcPistonThrust();
160 float FGEngine::CalcFuelNeed() {
161 FuelNeed = SLFuelFlowMax*PctPower;
166 float FGEngine::CalcOxidizerNeed() {
167 OxidizerNeed = SLOxiFlowMax*PctPower;