1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
29 Based on Flightgear code, which is based on LaRCSim. This class simulates
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 # include <simgear/compiler.h>
51 # ifdef SG_HAVE_STD_INCLUDES
61 #include "FGJSBBase.h"
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67 #define ID_ENGINE "$Id$"
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98 /** Base class for all engines.
99 This base class contains methods and members common to all engines, such as
100 logic to drain fuel from the appropriate tank, etc.
101 @author Jon S. Berndt
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109 class FGEngine : public FGJSBBase
112 FGEngine(FGFDMExec* exec);
115 enum EngineType {etUnknown, etRocket, etPiston, etTurbine};
117 virtual double GetThrottleMin(void) { return MinThrottle; }
118 virtual double GetThrottleMax(void) { return MaxThrottle; }
119 virtual double GetThrottle(void) { return Throttle; }
120 virtual double GetMixture(void) { return Mixture; }
121 virtual int GetMagnetos(void) { return Magnetos; }
122 virtual bool GetStarter(void) { return Starter; }
123 virtual double GetThrust(void) { return Thrust; }
124 virtual bool GetStarved(void) { return Starved; }
125 virtual bool GetFlameout(void) { return Flameout; }
126 virtual bool GetRunning(void) { return Running; }
127 virtual bool GetCranking(void) { return Cranking; }
128 virtual int GetType(void) { return Type; }
129 virtual string GetName(void) { return Name; }
131 virtual double getFuelFlow_gph () const {
135 virtual double getManifoldPressure_inHg () const {
136 return ManifoldPressure_inHg;
138 virtual double getExhaustGasTemp_degF () const {
139 return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
141 virtual double getCylinderHeadTemp_degF () const {
142 return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
144 virtual double getOilPressure_psi () const {
145 return OilPressure_psi;
147 virtual double getOilTemp_degF () const {
148 return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
151 virtual void SetStarved(bool tt) {Starved = tt;}
152 virtual void SetStarved(void) {Starved = true;}
154 virtual void SetRunning(bool bb) { Running=bb; }
155 virtual void SetName(string name) {Name = name;}
156 virtual void AddFeedTank(int tkID);
158 virtual void SetMagnetos(int m) { Magnetos = m; }
159 virtual void SetStarter(bool s) { Starter = s;}
161 /** Calculates the thrust of the engine, and other engine functions.
162 @param PowerRequired this is the power required to run the thrusting device
163 such as a propeller. This resisting effect must be provided to the
165 @return Thrust in pounds */
166 virtual double Calculate(double PowerRequired) {return 0.0;};
168 /** Reduces the fuel in the active tanks by the amount required.
169 This function should be called from within the
170 derived class' Calculate() function before any other calculations are
171 done. This base class method removes fuel from the fuel tanks as
172 appropriate, and sets the starved flag if necessary. */
173 virtual void ConsumeFuel(void);
175 /** The fuel need is calculated based on power levels and flow rate for that
176 power level. It is also turned from a rate into an actual amount (pounds)
177 by multiplying it by the delta T and the rate.
178 @return Total fuel requirement for this engine in pounds. */
179 virtual double CalcFuelNeed(void);
181 /** The oxidizer need is calculated based on power levels and flow rate for that
182 power level. It is also turned from a rate into an actual amount (pounds)
183 by multiplying it by the delta T and the rate.
184 @return Total oxidizer requirement for this engine in pounds. */
185 virtual double CalcOxidizerNeed(void);
187 /// Sets engine placement information
188 virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
190 /// Sets the engine number
191 virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
193 virtual double GetPowerAvailable(void) {return 0.0;};
195 virtual bool GetTrimMode(void) {return TrimMode;}
196 virtual void SetTrimMode(bool state) {TrimMode = state;}
204 double SLFuelFlowMax;
214 double FuelNeed, OxidizerNeed;
224 double ManifoldPressure_inHg;
225 double ExhaustGasTemp_degK;
226 double CylinderHeadTemp_degK;
227 double OilPressure_psi;
232 FGAtmosphere* Atmosphere;
234 FGPropulsion* Propulsion;
235 FGAircraft* Aircraft;
236 FGTranslation* Translation;
237 FGRotation* Rotation;
238 FGPosition* Position;
239 FGAuxiliary* Auxiliary;
242 vector <int> SourceTanks;
243 virtual void Debug(int from);
247 #include "FGFDMExec.h"
248 #include "FGAtmosphere.h"
250 #include "FGAircraft.h"
251 #include "FGTranslation.h"
252 #include "FGRotation.h"
253 #include "FGPropulsion.h"
254 #include "FGPosition.h"
255 #include "FGAuxiliary.h"
256 #include "FGOutput.h"
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%