]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
JSBSim tweaks.
[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 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 DEFINITIONS
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 #define ID_ENGINE "$Id$"
66
67 using std::string;
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 FORWARD DECLARATIONS
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 class FGFDMExec;
74 class FGState;
75 class FGAtmosphere;
76 class FGFCS;
77 class FGAircraft;
78 class FGTranslation;
79 class FGRotation;
80 class FGPropulsion;
81 class FGPosition;
82 class FGAuxiliary;
83 class FGOutput;
84
85 using std::vector;
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 CLASS DOCUMENTATION
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 /** Base class for all engines.
96     This base class contains methods and members common to all engines, such as
97     logic to drain fuel from the appropriate tank, etc.
98     @author Jon S. Berndt
99     @version $Id$ 
100 */
101
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 CLASS DECLARATION
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
105
106 class FGEngine {
107 public:
108   FGEngine(FGFDMExec* exec);
109   virtual ~FGEngine();
110
111   enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet, etTurboShaft};
112
113   virtual float  GetThrottleMin(void) { return MinThrottle; }
114   virtual float  GetThrottleMax(void) { return MaxThrottle; }
115   float  GetThrottle(void) { return Throttle; }
116   float  GetThrust(void) { return Thrust; }
117   bool   GetStarved(void) { return Starved; }
118   bool   GetFlameout(void) { return Flameout; }
119   bool   GetRunning(void) { return Running; }
120   int    GetType(void) { return Type; }
121   string GetName(void) { return Name; }
122
123   void SetStarved(bool tt) {Starved = tt;}
124   void SetStarved(void)    {Starved = true;}
125
126   void SetRunning(bool bb) { Running=bb; }
127   void SetName(string name) {Name = name;}
128   void AddFeedTank(int tkID);
129
130   /** Calculates the thrust of the engine, and other engine functions.
131       @param PowerRequired this is the power required to run the thrusting device
132              such as a propeller. This resisting effect must be provided to the 
133              engine model.
134       @return Thrust in pounds */
135   virtual float Calculate(float PowerRequired) {return 0.0;};
136
137   /** Reduces the fuel in the active tanks by the amount required.
138       This function should be called from within the
139       derived class' Calculate() function before any other calculations are
140       done. This base class method removes fuel from the fuel tanks as
141       appropriate, and sets the starved flag if necessary. */
142   void ConsumeFuel(void);
143
144   /** The fuel need is calculated based on power levels and flow rate for that
145       power level. It is also turned from a rate into an actual amount (pounds)
146       by multiplying it by the delta T and the rate.
147       @return Total fuel requirement for this engine in pounds. */
148   float CalcFuelNeed(void);
149
150   /** The oxidizer need is calculated based on power levels and flow rate for that
151       power level. It is also turned from a rate into an actual amount (pounds)
152       by multiplying it by the delta T and the rate.
153       @return Total oxidizer requirement for this engine in pounds. */
154   float CalcOxidizerNeed(void);
155
156   /// Sets engine placement information
157   void SetPlacement(float x, float y, float z, float pitch, float yaw);
158
159   virtual float GetPowerAvailable(void) {return 0.0;};
160
161   bool GetTrimMode(void) {return TrimMode;}
162   void SetTrimMode(bool state) {TrimMode = state;}
163
164 protected:
165   string Name;
166   EngineType Type;
167   float X, Y, Z;
168   float EnginePitch;
169   float EngineYaw;
170   float SLFuelFlowMax;
171   float SLOxiFlowMax;
172   float MaxThrottle;
173   float MinThrottle;
174
175   float Thrust;
176   float Throttle;
177   float FuelNeed, OxidizerNeed;
178   bool  Starved;
179   bool  Flameout;
180   bool  Running;
181   float PctPower;
182   int   EngineNumber;
183   bool  TrimMode;
184
185   FGFDMExec*      FDMExec;
186   FGState*        State;
187   FGAtmosphere*   Atmosphere;
188   FGFCS*          FCS;
189   FGPropulsion*   Propulsion;
190   FGAircraft*     Aircraft;
191   FGTranslation*  Translation;
192   FGRotation*     Rotation;
193   FGPosition*     Position;
194   FGAuxiliary*    Auxiliary;
195   FGOutput*       Output;
196
197   vector <int> SourceTanks;
198   void Debug(void);
199 };
200
201 #include "FGState.h"
202 #include "FGFDMExec.h"
203 #include "FGAtmosphere.h"
204 #include "FGFCS.h"
205 #include "FGAircraft.h"
206 #include "FGTranslation.h"
207 #include "FGRotation.h"
208 #include "FGPropulsion.h"
209 #include "FGPosition.h"
210 #include "FGAuxiliary.h"
211 #include "FGOutput.h"
212 #include "FGDefs.h"
213
214 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 #endif
216