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$"
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
97 /** Base class for all engines.
98 This base class contains methods and members common to all engines, such as
99 logic to drain fuel from the appropriate tank, etc.
100 @author Jon S. Berndt
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108 class FGEngine : public FGJSBBase
111 FGEngine(FGFDMExec* exec);
114 enum EngineType {etUnknown, etRocket, etPiston, etTurbine};
116 virtual double GetThrottleMin(void) { return MinThrottle; }
117 virtual double GetThrottleMax(void) { return MaxThrottle; }
118 virtual double GetThrottle(void) { return Throttle; }
119 virtual double GetMixture(void) { return Mixture; }
120 virtual int GetMagnetos(void) { return Magnetos; }
121 virtual bool GetStarter(void) { return Starter; }
122 virtual double GetThrust(void) { return Thrust; }
123 virtual bool GetStarved(void) { return Starved; }
124 virtual bool GetFlameout(void) { return Flameout; }
125 virtual bool GetRunning(void) { return Running; }
126 virtual bool GetCranking(void) { return Cranking; }
127 virtual int GetType(void) { return Type; }
128 virtual string GetName(void) { return Name; }
130 virtual double getFuelFlow_gph () const {
134 virtual double getManifoldPressure_inHg () const {
135 return ManifoldPressure_inHg;
137 virtual double getExhaustGasTemp_degF () const {
138 return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
140 virtual double getCylinderHeadTemp_degF () const {
141 return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
143 virtual double getOilPressure_psi () const {
144 return OilPressure_psi;
146 virtual double getOilTemp_degF () const {
147 return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
150 virtual void SetStarved(bool tt) {Starved = tt;}
151 virtual void SetStarved(void) {Starved = true;}
153 virtual void SetRunning(bool bb) { Running=bb; }
154 virtual void SetName(string name) {Name = name;}
155 virtual void AddFeedTank(int tkID);
157 virtual void SetMagnetos(int m) { Magnetos = m; }
158 virtual void SetStarter(bool s) { Starter = s;}
160 /** Calculates the thrust of the engine, and other engine functions.
161 @param PowerRequired this is the power required to run the thrusting device
162 such as a propeller. This resisting effect must be provided to the
164 @return Thrust in pounds */
165 virtual double Calculate(double PowerRequired) {return 0.0;};
167 /** Reduces the fuel in the active tanks by the amount required.
168 This function should be called from within the
169 derived class' Calculate() function before any other calculations are
170 done. This base class method removes fuel from the fuel tanks as
171 appropriate, and sets the starved flag if necessary. */
172 virtual void ConsumeFuel(void);
174 /** The fuel need is calculated based on power levels and flow rate for that
175 power level. It is also turned from a rate into an actual amount (pounds)
176 by multiplying it by the delta T and the rate.
177 @return Total fuel requirement for this engine in pounds. */
178 virtual double CalcFuelNeed(void);
180 /** The oxidizer need is calculated based on power levels and flow rate for that
181 power level. It is also turned from a rate into an actual amount (pounds)
182 by multiplying it by the delta T and the rate.
183 @return Total oxidizer requirement for this engine in pounds. */
184 virtual double CalcOxidizerNeed(void);
186 /// Sets engine placement information
187 virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
189 /// Sets the engine number
190 virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
192 virtual double GetPowerAvailable(void) {return 0.0;};
194 virtual bool GetTrimMode(void) {return TrimMode;}
195 virtual void SetTrimMode(bool state) {TrimMode = state;}
203 double SLFuelFlowMax;
213 double FuelNeed, OxidizerNeed;
223 double ManifoldPressure_inHg;
224 double ExhaustGasTemp_degK;
225 double CylinderHeadTemp_degK;
226 double OilPressure_psi;
231 FGAtmosphere* Atmosphere;
233 FGPropulsion* Propulsion;
234 FGAircraft* Aircraft;
235 FGTranslation* Translation;
236 FGRotation* Rotation;
237 FGPosition* Position;
238 FGAuxiliary* Auxiliary;
241 vector <int> SourceTanks;
242 virtual void Debug(int from);
246 #include "FGFDMExec.h"
247 #include "FGAtmosphere.h"
249 #include "FGAircraft.h"
250 #include "FGTranslation.h"
251 #include "FGRotation.h"
252 #include "FGPropulsion.h"
253 #include "FGPosition.h"
254 #include "FGAuxiliary.h"
255 #include "FGOutput.h"
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%