]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Mathias Fröhlich:
[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 #include "FGThruster.h"
63 #include "FGPropertyManager.h"
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 DEFINITIONS
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 #define ID_ENGINE "$Id$"
70
71 using std::string;
72 using std::vector;
73
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 FORWARD DECLARATIONS
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77
78 namespace JSBSim {
79
80 class FGFDMExec;
81 class FGState;
82 class FGAtmosphere;
83 class FGFCS;
84 class FGAircraft;
85 class FGPropagate;
86 class FGPropulsion;
87 class FGAuxiliary;
88 class FGOutput;
89 class FGThruster;
90 class FGConfigFile;
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 CLASS DOCUMENTATION
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 /** Base class for all engines.
97     This base class contains methods and members common to all engines, such as
98     logic to drain fuel from the appropriate tank, etc.
99     @author Jon S. Berndt
100     @version $Id$
101 */
102
103 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 CLASS DECLARATION
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
106
107 class FGEngine : public FGJSBBase
108 {
109 public:
110   FGEngine(FGFDMExec* exec, int engine_number);
111   virtual ~FGEngine();
112
113   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etElectric};
114
115   EngineType      GetType(void) { return Type; }
116   virtual string  GetName(void) { return Name; }
117   string GetThrusterFileName(void) {return thrusterFileName;}
118   void SetEngineFileName(string eng) {engineFileName = eng;}
119   string GetEngineFileName(void) {return engineFileName;}
120
121   // Engine controls
122   virtual double  GetThrottleMin(void) { return MinThrottle; }
123   virtual double  GetThrottleMax(void) { return MaxThrottle; }
124   virtual double  GetThrottle(void) { return Throttle; }
125   virtual double  GetMixture(void) { return Mixture; }
126   virtual bool    GetStarter(void) { return Starter; }
127
128   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
129   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
130   virtual double GetThrust(void) { return Thrust; }
131   virtual bool   GetStarved(void) { return Starved; }
132   virtual bool   GetRunning(void) { return Running; }
133   virtual bool   GetCranking(void) { return Cranking; }
134
135   virtual void SetStarved(bool tt) { Starved = tt; }
136   virtual void SetStarved(void)    { Starved = true; }
137
138   virtual void SetRunning(bool bb) { Running=bb; }
139   virtual void SetName(string name) { Name = name; }
140   virtual void AddFeedTank(int tkID);
141   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
142
143   virtual void SetStarter(bool s) { Starter = s; }
144
145   /** Calculates the thrust of the engine, and other engine functions.
146       @return Thrust in pounds */
147   virtual double Calculate(void) {return 0.0;}
148
149   /** Reduces the fuel in the active tanks by the amount required.
150       This function should be called from within the
151       derived class' Calculate() function before any other calculations are
152       done. This base class method removes fuel from the fuel tanks as
153       appropriate, and sets the starved flag if necessary. */
154   virtual void ConsumeFuel(void);
155
156   /** The fuel need is calculated based on power levels and flow rate for that
157       power level. It is also turned from a rate into an actual amount (pounds)
158       by multiplying it by the delta T and the rate.
159       @return Total fuel requirement for this engine in pounds. */
160   virtual double CalcFuelNeed(void);
161
162   /** The oxidizer need is calculated based on power levels and flow rate for that
163       power level. It is also turned from a rate into an actual amount (pounds)
164       by multiplying it by the delta T and the rate.
165       @return Total oxidizer requirement for this engine in pounds. */
166   virtual double CalcOxidizerNeed(void);
167
168   /// Sets engine placement information
169   virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
170   double GetPlacementX(void) const {return X;}
171   double GetPlacementY(void) const {return Y;}
172   double GetPlacementZ(void) const {return Z;}
173   double GetPitch(void) const {return EnginePitch;}
174   double GetYaw(void) const {return EngineYaw;}
175
176   virtual double GetPowerAvailable(void) {return 0.0;};
177
178   virtual bool GetTrimMode(void) {return TrimMode;}
179   virtual void SetTrimMode(bool state) {TrimMode = state;}
180
181   virtual FGColumnVector3& GetBodyForces(void);
182   virtual FGColumnVector3& GetMoments(void);
183
184   bool LoadThruster(FGConfigFile* AC_cfg);
185   FGThruster* GetThruster(void) {return Thruster;}
186
187   virtual string GetEngineLabels(string delimeter) = 0;
188   virtual string GetEngineValues(string delimeter) = 0;
189   int GetNumSourceTanks(void) {return SourceTanks.size();}
190   int GetSourceTank(int t) {return SourceTanks[t];}
191
192 protected:
193   FGPropertyManager* PropertyManager;
194   string Name;
195   string thrusterFileName;
196   string engineFileName;
197   const int   EngineNumber;
198   EngineType Type;
199   double X, Y, Z;
200   double EnginePitch;
201   double EngineYaw;
202   double SLFuelFlowMax;
203   double SLOxiFlowMax;
204   double MaxThrottle;
205   double MinThrottle;
206
207   double Thrust;
208   double Throttle;
209   double Mixture;
210   double FuelNeed;
211   double OxidizerNeed;
212   double PctPower;
213   bool  Starter;
214   bool  Starved;
215   bool  Running;
216   bool  Cranking;
217   bool  TrimMode;
218   bool  FuelFreeze;
219
220   double FuelFlow_gph;
221   double FuelFlow_pph;
222
223   FGFDMExec*      FDMExec;
224   FGState*        State;
225   FGAtmosphere*   Atmosphere;
226   FGFCS*          FCS;
227   FGPropulsion*   Propulsion;
228   FGAircraft*     Aircraft;
229   FGPropagate*    Propagate;
230   FGAuxiliary*    Auxiliary;
231   FGOutput*       Output;
232   FGThruster*     Thruster;
233
234   vector <int> SourceTanks;
235   void Debug(int from);
236 };
237 }
238 #include "FGState.h"
239 #include "FGFDMExec.h"
240 #include "FGAtmosphere.h"
241 #include "FGFCS.h"
242 #include "FGAircraft.h"
243 #include "FGPropagate.h"
244 #include "FGPropulsion.h"
245 #include "FGAuxiliary.h"
246 #include "FGOutput.h"
247 #include "FGThruster.h"
248 #include "FGConfigFile.h"
249
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 #endif
252