]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Sync with latest JSBSim CVS
[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
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FORWARD DECLARATIONS
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 class FGFDMExec;
76 class FGState;
77 class FGAtmosphere;
78 class FGFCS;
79 class FGAircraft;
80 class FGTranslation;
81 class FGRotation;
82 class FGPropulsion;
83 class FGPosition;
84 class FGAuxiliary;
85 class FGOutput;
86
87 using std::vector;
88
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92
93 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 CLASS DOCUMENTATION
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96
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
101     @version $Id$ 
102 */
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DECLARATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 class FGEngine : public FGJSBBase
109 {
110 public:
111   FGEngine(FGFDMExec* exec);
112   virtual ~FGEngine();
113
114   enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet, etTurboShaft};
115
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; }
129
130   virtual float getManifoldPressure_inHg () const {
131     return ManifoldPressure_inHg;
132   }
133   virtual float getExhaustGasTemp_degF () const {
134     return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
135   }
136   virtual float getCylinderHeadTemp_degF () const {
137     return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
138   }
139   virtual float getOilPressure_psi () const {
140     return OilPressure_psi;
141   }
142   virtual float getOilTemp_degF () const {
143     return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
144   }
145
146   void SetStarved(bool tt) {Starved = tt;}
147   void SetStarved(void)    {Starved = true;}
148
149   void SetRunning(bool bb) { Running=bb; }
150   void SetName(string name) {Name = name;}
151   void AddFeedTank(int tkID);
152
153   void SetMagnetos(int m) { Magnetos = m; }
154   void SetStarter(bool s) { Starter = s;}
155
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 
159              engine model.
160       @return Thrust in pounds */
161   virtual float Calculate(float PowerRequired) {return 0.0;};
162
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);
169
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);
175
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);
181
182   /// Sets engine placement information
183   void SetPlacement(float x, float y, float z, float pitch, float yaw);
184
185   virtual float GetPowerAvailable(void) {return 0.0;};
186
187   bool GetTrimMode(void) {return TrimMode;}
188   void SetTrimMode(bool state) {TrimMode = state;}
189
190 protected:
191   string Name;
192   EngineType Type;
193   float X, Y, Z;
194   float EnginePitch;
195   float EngineYaw;
196   float SLFuelFlowMax;
197   float SLOxiFlowMax;
198   float MaxThrottle;
199   float MinThrottle;
200
201   float Thrust;
202   float Throttle;
203   float Mixture;
204   int   Magnetos;
205   bool  Starter;
206   float FuelNeed, OxidizerNeed;
207   bool  Starved;
208   bool  Flameout;
209   bool  Running;
210   bool  Cranking;
211   float PctPower;
212   int   EngineNumber;
213   bool  TrimMode;
214
215   float ManifoldPressure_inHg;
216   float ExhaustGasTemp_degK;
217   float CylinderHeadTemp_degK;
218   float OilPressure_psi;
219   float OilTemp_degK;
220
221   FGFDMExec*      FDMExec;
222   FGState*        State;
223   FGAtmosphere*   Atmosphere;
224   FGFCS*          FCS;
225   FGPropulsion*   Propulsion;
226   FGAircraft*     Aircraft;
227   FGTranslation*  Translation;
228   FGRotation*     Rotation;
229   FGPosition*     Position;
230   FGAuxiliary*    Auxiliary;
231   FGOutput*       Output;
232
233   vector <int> SourceTanks;
234   void Debug(void);
235 };
236
237 #include "FGState.h"
238 #include "FGFDMExec.h"
239 #include "FGAtmosphere.h"
240 #include "FGFCS.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"
248
249 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250 #endif
251