]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGEngine.h
Sync. w. JSB CVS as of 15/01/2007
[flightgear.git] / src / FDM / JSBSim / models / propulsion / 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 Lesser 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 Lesser General Public License for more details.
17
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA  02111-1307, USA.
21
22  Further information about the GNU Lesser General Public License can also be found on
23  the world wide web at http://www.gnu.org.
24
25 FUNCTIONAL DESCRIPTION
26 --------------------------------------------------------------------------------
27
28 Based on Flightgear code, which is based on LaRCSim. This class simulates
29 a generic engine.
30
31 HISTORY
32 --------------------------------------------------------------------------------
33 01/21/99   JSB   Created
34
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 SENTRY
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #ifndef FGENGINE_H
40 #define FGENGINE_H
41
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 INCLUDES
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45
46 #ifdef FGFS
47 #  include <simgear/compiler.h>
48 #  include STL_STRING
49    SG_USING_STD(string);
50 #  ifdef SG_HAVE_STD_INCLUDES
51 #    include <vector>
52 #  else
53 #    include <vector.h>
54 #  endif
55 #else
56 #  include <vector>
57 #  include <string>
58 #endif
59
60 #include <FGJSBBase.h>
61 #include "FGThruster.h"
62 #include <input_output/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 FGPropagate;
85 class FGPropulsion;
86 class FGAuxiliary;
87 class FGThruster;
88 class Element;
89
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 CLASS DOCUMENTATION
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93
94 /** Base class for all engines.
95     This base class contains methods and members common to all engines, such as
96     logic to drain fuel from the appropriate tank, etc.
97     @author Jon S. Berndt
98     @version $Id$
99 */
100
101 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 CLASS DECLARATION
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104
105 class FGEngine : public FGJSBBase
106 {
107 public:
108   FGEngine(FGFDMExec* exec, Element* el, int engine_number);
109   virtual ~FGEngine();
110
111   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
112
113   EngineType      GetType(void) { return Type; }
114   virtual string  GetName(void) { return Name; }
115
116   // Engine controls
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 bool    GetStarter(void) { return Starter; }
122
123   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
124   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
125   virtual double GetThrust(void) { return Thrust; }
126   virtual bool   GetStarved(void) { return Starved; }
127   virtual bool   GetRunning(void) { return Running; }
128   virtual bool   GetCranking(void) { return Cranking; }
129
130   virtual void SetStarved(bool tt) { Starved = tt; }
131   virtual void SetStarved(void)    { Starved = true; }
132
133   virtual void SetRunning(bool bb) { Running=bb; }
134   virtual void SetName(string name) { Name = name; }
135   virtual void AddFeedTank(int tkID);
136   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
137
138   virtual void SetStarter(bool s) { Starter = s; }
139
140   /** Calculates the thrust of the engine, and other engine functions.
141       @return Thrust in pounds */
142   virtual double Calculate(void) {return 0.0;}
143
144   /** Reduces the fuel in the active tanks by the amount required.
145       This function should be called from within the
146       derived class' Calculate() function before any other calculations are
147       done. This base class method removes fuel from the fuel tanks as
148       appropriate, and sets the starved flag if necessary. */
149   virtual void ConsumeFuel(void);
150
151   /** The fuel need is calculated based on power levels and flow rate for that
152       power level. It is also turned from a rate into an actual amount (pounds)
153       by multiplying it by the delta T and the rate.
154       @return Total fuel requirement for this engine in pounds. */
155   virtual double CalcFuelNeed(void);
156
157   /** The oxidizer need is calculated based on power levels and flow rate for that
158       power level. It is also turned from a rate into an actual amount (pounds)
159       by multiplying it by the delta T and the rate.
160       @return Total oxidizer requirement for this engine in pounds. */
161   virtual double CalcOxidizerNeed(void);
162
163   /// Sets engine placement information
164   virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
165
166   virtual double GetPowerAvailable(void) {return 0.0;};
167
168   virtual bool GetTrimMode(void) {return TrimMode;}
169   virtual void SetTrimMode(bool state) {TrimMode = state;}
170
171   virtual FGColumnVector3& GetBodyForces(void);
172   virtual FGColumnVector3& GetMoments(void);
173
174   bool LoadThruster(Element *el);
175   FGThruster* GetThruster(void) {return Thruster;}
176
177   virtual string GetEngineLabels(string delimeter) = 0;
178   virtual string GetEngineValues(string delimeter) = 0;
179
180 protected:
181   FGPropertyManager* PropertyManager;
182   string Name;
183   const int   EngineNumber;
184   EngineType Type;
185   double X, Y, Z;
186   double EnginePitch;
187   double EngineYaw;
188   double SLFuelFlowMax;
189   double SLOxiFlowMax;
190   double MaxThrottle;
191   double MinThrottle;
192
193   double Thrust;
194   double Throttle;
195   double Mixture;
196   double FuelNeed;
197   double OxidizerNeed;
198   double PctPower;
199   bool  Starter;
200   bool  Starved;
201   bool  Running;
202   bool  Cranking;
203   bool  TrimMode;
204   bool  FuelFreeze;
205
206   double FuelFlow_gph;
207   double FuelFlow_pph;
208
209   FGFDMExec*      FDMExec;
210   FGState*        State;
211   FGAtmosphere*   Atmosphere;
212   FGFCS*          FCS;
213   FGPropulsion*   Propulsion;
214   FGAircraft*     Aircraft;
215   FGPropagate*    Propagate;
216   FGAuxiliary*    Auxiliary;
217   FGThruster*     Thruster;
218
219   vector <int> SourceTanks;
220   void Debug(int from);
221 };
222 }
223 #include <FGState.h>
224 #include <FGFDMExec.h>
225 #include <models/FGAtmosphere.h>
226 #include <models/FGFCS.h>
227 #include <models/FGAircraft.h>
228 #include <models/FGPropagate.h>
229 #include <models/FGPropulsion.h>
230 #include <models/FGAuxiliary.h>
231 #include <models/propulsion/FGThruster.h>
232 #include <input_output/FGXMLElement.h>
233
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235 #endif
236