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, etTurboProp, etTurboJet, etTurboShaft};
116 virtual float GetThrottleMin(void) { return MinThrottle; }
117 virtual float GetThrottleMax(void) { return MaxThrottle; }
118 float GetThrottle(void) { return Throttle; }
119 float GetMixture(void) { return Mixture; }
120 int GetMagnetos(void) { return Magnetos; }
121 bool GetStarter(void) { return Starter; }
122 float GetThrust(void) { return Thrust; }
123 bool GetStarved(void) { return Starved; }
124 bool GetFlameout(void) { return Flameout; }
125 bool GetRunning(void) { return Running; }
126 bool GetCranking(void) { return Cranking; }
127 int GetType(void) { return Type; }
128 string GetName(void) { return Name; }
130 virtual float getManifoldPressure_inHg () const {
131 return ManifoldPressure_inHg;
133 virtual float getExhaustGasTemp_degF () const {
134 return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
136 virtual float getCylinderHeadTemp_degF () const {
137 return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
139 virtual float getOilPressure_psi () const {
140 return OilPressure_psi;
142 virtual float getOilTemp_degF () const {
143 return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
146 void SetStarved(bool tt) {Starved = tt;}
147 void SetStarved(void) {Starved = true;}
149 void SetRunning(bool bb) { Running=bb; }
150 void SetName(string name) {Name = name;}
151 void AddFeedTank(int tkID);
153 void SetMagnetos(int m) { Magnetos = m; }
154 void SetStarter(bool s) { Starter = s;}
156 /** Calculates the thrust of the engine, and other engine functions.
157 @param PowerRequired this is the power required to run the thrusting device
158 such as a propeller. This resisting effect must be provided to the
160 @return Thrust in pounds */
161 virtual float Calculate(float PowerRequired) {return 0.0;};
163 /** Reduces the fuel in the active tanks by the amount required.
164 This function should be called from within the
165 derived class' Calculate() function before any other calculations are
166 done. This base class method removes fuel from the fuel tanks as
167 appropriate, and sets the starved flag if necessary. */
168 void ConsumeFuel(void);
170 /** The fuel need is calculated based on power levels and flow rate for that
171 power level. It is also turned from a rate into an actual amount (pounds)
172 by multiplying it by the delta T and the rate.
173 @return Total fuel requirement for this engine in pounds. */
174 float CalcFuelNeed(void);
176 /** The oxidizer need is calculated based on power levels and flow rate for that
177 power level. It is also turned from a rate into an actual amount (pounds)
178 by multiplying it by the delta T and the rate.
179 @return Total oxidizer requirement for this engine in pounds. */
180 float CalcOxidizerNeed(void);
182 /// Sets engine placement information
183 void SetPlacement(float x, float y, float z, float pitch, float yaw);
185 virtual float GetPowerAvailable(void) {return 0.0;};
187 bool GetTrimMode(void) {return TrimMode;}
188 void SetTrimMode(bool state) {TrimMode = state;}
206 float FuelNeed, OxidizerNeed;
215 float ManifoldPressure_inHg;
216 float ExhaustGasTemp_degK;
217 float CylinderHeadTemp_degK;
218 float OilPressure_psi;
223 FGAtmosphere* Atmosphere;
225 FGPropulsion* Propulsion;
226 FGAircraft* Aircraft;
227 FGTranslation* Translation;
228 FGRotation* Rotation;
229 FGPosition* Position;
230 FGAuxiliary* Auxiliary;
233 vector <int> SourceTanks;
238 #include "FGFDMExec.h"
239 #include "FGAtmosphere.h"
241 #include "FGAircraft.h"
242 #include "FGTranslation.h"
243 #include "FGRotation.h"
244 #include "FGPropulsion.h"
245 #include "FGPosition.h"
246 #include "FGAuxiliary.h"
247 #include "FGOutput.h"
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%