]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Add speed-brake and spoilers controlls
[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 bool    GetIgnition(void) { return Ignition; }
139   virtual bool    GetReversed(void) { return Reversed; }
140
141   virtual double getFuelFlow_gph () const {
142     return FuelFlow_gph;
143   }
144
145   virtual double getManifoldPressure_inHg () const {
146     return ManifoldPressure_inHg;
147   }
148   virtual double getExhaustGasTemp_degF () const {
149     return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
150   }
151   virtual double getCylinderHeadTemp_degF () const {
152     return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
153   }
154   virtual double getOilPressure_psi () const {
155     return OilPressure_psi;
156   }
157   virtual double getOilTemp_degF () const {
158     return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
159   }
160
161   virtual double getFuelFlow_pph () const {
162     return FuelFlow_pph;
163   }
164
165   virtual void SetStarved(bool tt) {Starved = tt;}
166   virtual void SetStarved(void)    {Starved = true;}
167
168   virtual void SetRunning(bool bb) { Running=bb; }
169   virtual void SetName(string name) {Name = name;}
170   virtual void AddFeedTank(int tkID);
171
172   virtual void SetMagnetos(int m) { Magnetos = m; }
173   virtual void SetStarter(bool s) { Starter = s;}
174
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 
178              engine model.
179       @return Thrust in pounds */
180   virtual double Calculate(double PowerRequired) {return 0.0;};
181
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);
188
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);
194
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);
200
201   /// Sets engine placement information
202   virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
203
204   /// Sets the engine number
205   virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
206
207   virtual double GetPowerAvailable(void) {return 0.0;};
208
209   virtual bool GetTrimMode(void) {return TrimMode;}
210   virtual void SetTrimMode(bool state) {TrimMode = state;}
211
212 protected:
213   string Name;
214   EngineType Type;
215   double X, Y, Z;
216   double EnginePitch;
217   double EngineYaw;
218   double SLFuelFlowMax;
219   double SLOxiFlowMax;
220   double MaxThrottle;
221   double MinThrottle;
222
223   double Thrust;
224   double Throttle;
225   double Mixture;
226   int   Magnetos;
227   bool  Starter;
228   double FuelNeed, OxidizerNeed;
229   bool  Starved;
230   bool  Flameout;
231   bool  Running;
232   bool  Cranking;
233   double PctPower;
234   int   EngineNumber;
235   bool  TrimMode;
236
237   double FuelFlow_gph;
238   double ManifoldPressure_inHg;
239   double ExhaustGasTemp_degK;
240   double CylinderHeadTemp_degK;
241   double OilPressure_psi;
242   double OilTemp_degK;
243
244   double FuelFlow_pph;
245   double N1;
246   double N2;
247   double EGT_degC;
248   double EPR;
249   double BleedDemand;
250   double InletPosition;
251   double NozzlePosition;
252   bool Augmentation;
253   bool Injection;
254   bool Ignition;
255   bool Reversed;
256
257   FGFDMExec*      FDMExec;
258   FGState*        State;
259   FGAtmosphere*   Atmosphere;
260   FGFCS*          FCS;
261   FGPropulsion*   Propulsion;
262   FGAircraft*     Aircraft;
263   FGTranslation*  Translation;
264   FGRotation*     Rotation;
265   FGPosition*     Position;
266   FGAuxiliary*    Auxiliary;
267   FGOutput*       Output;
268
269   vector <int> SourceTanks;
270   virtual void Debug(int from);
271 };
272 }
273 #include "FGState.h"
274 #include "FGFDMExec.h"
275 #include "FGAtmosphere.h"
276 #include "FGFCS.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"
284
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 #endif
287