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$"
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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 int GetIgnition(void) { return Ignition; }
139 virtual bool GetReversed(void) { return Reversed; }
140 virtual bool GetCutoff(void) { return Cutoff; }
141 virtual bool GetNitrous(void) { return Nitrous; }
143 virtual double getFuelFlow_gph () const {
147 virtual double getManifoldPressure_inHg () const {
148 return ManifoldPressure_inHg;
150 virtual double getExhaustGasTemp_degF () const {
151 return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
153 virtual double getCylinderHeadTemp_degF () const {
154 return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
156 virtual double getOilPressure_psi () const {
157 return OilPressure_psi;
159 virtual double getOilTemp_degF () const {
160 return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
163 virtual double getFuelFlow_pph () const {
167 virtual void SetStarved(bool tt) { Starved = tt; }
168 virtual void SetStarved(void) { Starved = true; }
170 virtual void SetRunning(bool bb) { Running=bb; }
171 virtual void SetName(string name) { Name = name; }
172 virtual void AddFeedTank(int tkID);
174 virtual void SetMagnetos(int m) { Magnetos = m; }
175 virtual void SetStarter(bool s) { Starter = s; }
176 virtual void SetAugmentation(bool a) { Augmentation = a; }
177 virtual void SetInjection(bool i) { Injection = i; }
178 virtual void SetIgnition(int ig) { Ignition = ig; }
179 virtual void SetReverse(bool r) { Reversed = r; }
180 virtual void SetCutoff(bool c) { Cutoff = c; }
181 virtual void SetNitrous(bool n) { Nitrous = n; }
183 /** Calculates the thrust of the engine, and other engine functions.
184 @param PowerRequired this is the power required to run the thrusting device
185 such as a propeller. This resisting effect must be provided to the
187 @return Thrust in pounds */
188 virtual double Calculate(double PowerRequired) {return 0.0;};
190 /** Reduces the fuel in the active tanks by the amount required.
191 This function should be called from within the
192 derived class' Calculate() function before any other calculations are
193 done. This base class method removes fuel from the fuel tanks as
194 appropriate, and sets the starved flag if necessary. */
195 virtual void ConsumeFuel(void);
197 /** The fuel need is calculated based on power levels and flow rate for that
198 power level. It is also turned from a rate into an actual amount (pounds)
199 by multiplying it by the delta T and the rate.
200 @return Total fuel requirement for this engine in pounds. */
201 virtual double CalcFuelNeed(void);
203 /** The oxidizer need is calculated based on power levels and flow rate for that
204 power level. It is also turned from a rate into an actual amount (pounds)
205 by multiplying it by the delta T and the rate.
206 @return Total oxidizer requirement for this engine in pounds. */
207 virtual double CalcOxidizerNeed(void);
209 /// Sets engine placement information
210 virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
212 /// Sets the engine number
213 virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
215 virtual double GetPowerAvailable(void) {return 0.0;};
217 virtual bool GetTrimMode(void) {return TrimMode;}
218 virtual void SetTrimMode(bool state) {TrimMode = state;}
226 double SLFuelFlowMax;
236 double FuelNeed, OxidizerNeed;
246 double ManifoldPressure_inHg;
247 double ExhaustGasTemp_degK;
248 double CylinderHeadTemp_degK;
249 double OilPressure_psi;
258 double InletPosition;
259 double NozzlePosition;
269 FGAtmosphere* Atmosphere;
271 FGPropulsion* Propulsion;
272 FGAircraft* Aircraft;
273 FGTranslation* Translation;
274 FGRotation* Rotation;
275 FGPosition* Position;
276 FGAuxiliary* Auxiliary;
279 vector <int> SourceTanks;
280 virtual void Debug(int from);
284 #include "FGFDMExec.h"
285 #include "FGAtmosphere.h"
287 #include "FGAircraft.h"
288 #include "FGTranslation.h"
289 #include "FGRotation.h"
290 #include "FGPropulsion.h"
291 #include "FGPosition.h"
292 #include "FGAuxiliary.h"
293 #include "FGOutput.h"
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%