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, etSimTurbine};
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; }
130 virtual double GetN1(void) { return N1; }
131 virtual double GetN2(void) { return N2; }
132 virtual double GetEGT(void) { return EGT_degC; }
133 virtual double GetEPR(void) { return EPR; }
134 virtual double GetInlet(void) { return InletPosition; }
135 virtual double GetNozzle(void) { return NozzlePosition; }
136 virtual bool GetAugmentation(void) { return Augmentation; }
137 virtual bool GetInjection(void) { return Injection; }
138 virtual bool GetIgnition(void) { return Ignition; }
139 virtual bool GetReversed(void) { return Reversed; }
141 virtual double getFuelFlow_gph () const {
145 virtual double getManifoldPressure_inHg () const {
146 return ManifoldPressure_inHg;
148 virtual double getExhaustGasTemp_degF () const {
149 return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
151 virtual double getCylinderHeadTemp_degF () const {
152 return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
154 virtual double getOilPressure_psi () const {
155 return OilPressure_psi;
157 virtual double getOilTemp_degF () const {
158 return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
161 virtual double getFuelFlow_pph () const {
165 virtual void SetStarved(bool tt) {Starved = tt;}
166 virtual void SetStarved(void) {Starved = true;}
168 virtual void SetRunning(bool bb) { Running=bb; }
169 virtual void SetName(string name) {Name = name;}
170 virtual void AddFeedTank(int tkID);
172 virtual void SetMagnetos(int m) { Magnetos = m; }
173 virtual void SetStarter(bool s) { Starter = s;}
175 /** Calculates the thrust of the engine, and other engine functions.
176 @param PowerRequired this is the power required to run the thrusting device
177 such as a propeller. This resisting effect must be provided to the
179 @return Thrust in pounds */
180 virtual double Calculate(double PowerRequired) {return 0.0;};
182 /** Reduces the fuel in the active tanks by the amount required.
183 This function should be called from within the
184 derived class' Calculate() function before any other calculations are
185 done. This base class method removes fuel from the fuel tanks as
186 appropriate, and sets the starved flag if necessary. */
187 virtual void ConsumeFuel(void);
189 /** The fuel need is calculated based on power levels and flow rate for that
190 power level. It is also turned from a rate into an actual amount (pounds)
191 by multiplying it by the delta T and the rate.
192 @return Total fuel requirement for this engine in pounds. */
193 virtual double CalcFuelNeed(void);
195 /** The oxidizer need is calculated based on power levels and flow rate for that
196 power level. It is also turned from a rate into an actual amount (pounds)
197 by multiplying it by the delta T and the rate.
198 @return Total oxidizer requirement for this engine in pounds. */
199 virtual double CalcOxidizerNeed(void);
201 /// Sets engine placement information
202 virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
204 /// Sets the engine number
205 virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
207 virtual double GetPowerAvailable(void) {return 0.0;};
209 virtual bool GetTrimMode(void) {return TrimMode;}
210 virtual void SetTrimMode(bool state) {TrimMode = state;}
218 double SLFuelFlowMax;
228 double FuelNeed, OxidizerNeed;
238 double ManifoldPressure_inHg;
239 double ExhaustGasTemp_degK;
240 double CylinderHeadTemp_degK;
241 double OilPressure_psi;
250 double InletPosition;
251 double NozzlePosition;
259 FGAtmosphere* Atmosphere;
261 FGPropulsion* Propulsion;
262 FGAircraft* Aircraft;
263 FGTranslation* Translation;
264 FGRotation* Rotation;
265 FGPosition* Position;
266 FGAuxiliary* Auxiliary;
269 vector <int> SourceTanks;
270 virtual void Debug(int from);
274 #include "FGFDMExec.h"
275 #include "FGAtmosphere.h"
277 #include "FGAircraft.h"
278 #include "FGTranslation.h"
279 #include "FGRotation.h"
280 #include "FGPropulsion.h"
281 #include "FGPosition.h"
282 #include "FGAuxiliary.h"
283 #include "FGOutput.h"
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%