]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Encapsulate the interpolstion version of FGEnvironment and fix some bugs
[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 "FGPropertyManager.h"
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 DEFINITIONS
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 #define ID_ENGINE "$Id$"
69
70 using std::string;
71 using std::vector;
72
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 FORWARD DECLARATIONS
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76
77 namespace JSBSim {
78
79 class FGFDMExec;
80 class FGState;
81 class FGAtmosphere;
82 class FGFCS;
83 class FGAircraft;
84 class FGTranslation;
85 class FGRotation;
86 class FGPropulsion;
87 class FGPosition;
88 class FGAuxiliary;
89 class FGOutput;
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 : public FGJSBBase
107 {
108 public:
109   FGEngine(FGFDMExec* exec);
110   virtual ~FGEngine();
111
112   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etSimTurbine};
113
114   EngineType      GetType(void) { return Type; }
115   virtual string  GetName(void) { return Name; }
116
117   // Engine controls
118   virtual double  GetThrottleMin(void) { return MinThrottle; }
119   virtual double  GetThrottleMax(void) { return MaxThrottle; }
120   virtual double  GetThrottle(void) { return Throttle; }
121   virtual double  GetMixture(void) { return Mixture; }
122   virtual bool    GetStarter(void) { return Starter; }
123
124   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
125   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
126   virtual double GetThrust(void) { return Thrust; }
127   virtual bool   GetStarved(void) { return Starved; }
128   virtual bool   GetRunning(void) { return Running; }
129   virtual bool   GetCranking(void) { return Cranking; }
130
131   virtual void SetStarved(bool tt) { Starved = tt; }
132   virtual void SetStarved(void)    { Starved = true; }
133
134   virtual void SetRunning(bool bb) { Running=bb; }
135   virtual void SetName(string name) { Name = name; }
136   virtual void AddFeedTank(int tkID);
137
138   virtual void SetStarter(bool s) { Starter = s; }
139
140   /** Calculates the thrust of the engine, and other engine functions.
141       @param PowerRequired this is the power required to run the thrusting device
142              such as a propeller. This resisting effect must be provided to the 
143              engine model.
144       @return Thrust in pounds */
145   virtual double Calculate(double PowerRequired) {return 0.0;};
146
147   /** Reduces the fuel in the active tanks by the amount required.
148       This function should be called from within the
149       derived class' Calculate() function before any other calculations are
150       done. This base class method removes fuel from the fuel tanks as
151       appropriate, and sets the starved flag if necessary. */
152   virtual void ConsumeFuel(void);
153
154   /** The fuel need is calculated based on power levels and flow rate for that
155       power level. It is also turned from a rate into an actual amount (pounds)
156       by multiplying it by the delta T and the rate.
157       @return Total fuel requirement for this engine in pounds. */
158   virtual double CalcFuelNeed(void);
159
160   /** The oxidizer need is calculated based on power levels and flow rate for that
161       power level. It is also turned from a rate into an actual amount (pounds)
162       by multiplying it by the delta T and the rate.
163       @return Total oxidizer requirement for this engine in pounds. */
164   virtual double CalcOxidizerNeed(void);
165
166   /// Sets engine placement information
167   virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
168
169   /// Sets the engine number
170   virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
171
172   virtual double GetPowerAvailable(void) {return 0.0;};
173
174   virtual bool GetTrimMode(void) {return TrimMode;}
175   virtual void SetTrimMode(bool state) {TrimMode = state;}
176
177 protected:
178   FGPropertyManager* PropertyManager;
179   string Name;
180   EngineType Type;
181   double X, Y, Z;
182   double EnginePitch;
183   double EngineYaw;
184   double SLFuelFlowMax;
185   double SLOxiFlowMax;
186   double MaxThrottle;
187   double MinThrottle;
188
189   double Thrust;
190   double Throttle;
191   double Mixture;
192   double FuelNeed;
193   double OxidizerNeed;
194   double PctPower;
195   int   EngineNumber;
196   bool  Starter;
197   bool  Starved;
198   bool  Running;
199   bool  Cranking;
200   bool  TrimMode;
201
202   double FuelFlow_gph;
203   double FuelFlow_pph;
204
205   FGFDMExec*      FDMExec;
206   FGState*        State;
207   FGAtmosphere*   Atmosphere;
208   FGFCS*          FCS;
209   FGPropulsion*   Propulsion;
210   FGAircraft*     Aircraft;
211   FGTranslation*  Translation;
212   FGRotation*     Rotation;
213   FGPosition*     Position;
214   FGAuxiliary*    Auxiliary;
215   FGOutput*       Output;
216
217   vector <int> SourceTanks;
218   void Debug(int from);
219 };
220 }
221 #include "FGState.h"
222 #include "FGFDMExec.h"
223 #include "FGAtmosphere.h"
224 #include "FGFCS.h"
225 #include "FGAircraft.h"
226 #include "FGTranslation.h"
227 #include "FGRotation.h"
228 #include "FGPropulsion.h"
229 #include "FGPosition.h"
230 #include "FGAuxiliary.h"
231 #include "FGOutput.h"
232
233 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 #endif
235