]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Provide a fix for the MSVC/Cygwin GDI build problem
[flightgear.git] / src / FDM / JSBSim / FGEngine.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGEngine.h
4  Author:       Jon S. Berndt
5  Date started: 01/21/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
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
12  version.
13
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
17  details.
18
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28
29 Based on Flightgear code, which is based on LaRCSim. This class simulates
30 a generic engine.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 01/21/99   JSB   Created
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 SENTRY
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #ifndef FGENGINE_H
41 #define FGENGINE_H
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 INCLUDES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #ifdef FGFS
48 #  include <simgear/compiler.h>
49 #  include STL_STRING
50    SG_USING_STD(string);
51 #  ifdef SG_HAVE_STD_INCLUDES
52 #    include <vector>
53 #  else
54 #    include <vector.h>
55 #  endif
56 #else
57 #  include <vector>
58 #  include <string>
59 #endif
60
61 #include "FGJSBBase.h"
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 DEFINITIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 #define ID_ENGINE "$Id$"
68
69 using std::string;
70 using std::vector;
71
72 namespace JSBSim {
73
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 FORWARD DECLARATIONS
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77
78 class FGFDMExec;
79 class FGState;
80 class FGAtmosphere;
81 class FGFCS;
82 class FGAircraft;
83 class FGTranslation;
84 class FGRotation;
85 class FGPropulsion;
86 class FGPosition;
87 class FGAuxiliary;
88 class FGOutput;
89
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 CLASS DOCUMENTATION
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
97
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
102     @version $Id$ 
103 */
104
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 CLASS DECLARATION
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108
109 class FGEngine : public FGJSBBase
110 {
111 public:
112   FGEngine(FGFDMExec* exec);
113   virtual ~FGEngine();
114
115   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etSimTurbine};
116
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; }
142
143   virtual double getFuelFlow_gph () const {
144     return FuelFlow_gph;
145   }
146
147   virtual double getManifoldPressure_inHg () const {
148     return ManifoldPressure_inHg;
149   }
150   virtual double getExhaustGasTemp_degF () const {
151     return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
152   }
153   virtual double getCylinderHeadTemp_degF () const {
154     return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
155   }
156   virtual double getOilPressure_psi () const {
157     return OilPressure_psi;
158   }
159   virtual double getOilTemp_degF () const {
160     return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
161   }
162
163   virtual double getFuelFlow_pph () const {
164     return FuelFlow_pph;
165   }
166
167   virtual void SetStarved(bool tt) { Starved = tt; }
168   virtual void SetStarved(void)    { Starved = true; }
169
170   virtual void SetRunning(bool bb) { Running=bb; }
171   virtual void SetName(string name) { Name = name; }
172   virtual void AddFeedTank(int tkID);
173
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; }
182
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 
186              engine model.
187       @return Thrust in pounds */
188   virtual double Calculate(double PowerRequired) {return 0.0;};
189
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);
196
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);
202
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);
208
209   /// Sets engine placement information
210   virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
211
212   /// Sets the engine number
213   virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
214
215   virtual double GetPowerAvailable(void) {return 0.0;};
216
217   virtual bool GetTrimMode(void) {return TrimMode;}
218   virtual void SetTrimMode(bool state) {TrimMode = state;}
219
220 protected:
221   string Name;
222   EngineType Type;
223   double X, Y, Z;
224   double EnginePitch;
225   double EngineYaw;
226   double SLFuelFlowMax;
227   double SLOxiFlowMax;
228   double MaxThrottle;
229   double MinThrottle;
230
231   double Thrust;
232   double Throttle;
233   double Mixture;
234   int   Magnetos;
235   bool  Starter;
236   double FuelNeed, OxidizerNeed;
237   bool  Starved;
238   bool  Flameout;
239   bool  Running;
240   bool  Cranking;
241   double PctPower;
242   int   EngineNumber;
243   bool  TrimMode;
244
245   double FuelFlow_gph;
246   double ManifoldPressure_inHg;
247   double ExhaustGasTemp_degK;
248   double CylinderHeadTemp_degK;
249   double OilPressure_psi;
250   double OilTemp_degK;
251
252   double FuelFlow_pph;
253   double N1;
254   double N2;
255   double EGT_degC;
256   double EPR;
257   double BleedDemand;
258   double InletPosition;
259   double NozzlePosition;
260   bool Augmentation;
261   bool Injection;
262   int Ignition;
263   bool Reversed;
264   bool Cutoff;
265   bool Nitrous;
266
267   FGFDMExec*      FDMExec;
268   FGState*        State;
269   FGAtmosphere*   Atmosphere;
270   FGFCS*          FCS;
271   FGPropulsion*   Propulsion;
272   FGAircraft*     Aircraft;
273   FGTranslation*  Translation;
274   FGRotation*     Rotation;
275   FGPosition*     Position;
276   FGAuxiliary*    Auxiliary;
277   FGOutput*       Output;
278
279   vector <int> SourceTanks;
280   virtual void Debug(int from);
281 };
282 }
283 #include "FGState.h"
284 #include "FGFDMExec.h"
285 #include "FGAtmosphere.h"
286 #include "FGFCS.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"
294
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 #endif
297