]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGEngine.h
Sync. with JSBSim CVS
[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 #include <FGJSBBase.h>
47 #include "FGThruster.h"
48 #include <input_output/FGPropertyManager.h>
49 #include <input_output/FGXMLFileRead.h>
50 #include <vector>
51 #include <string>
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 DEFINITIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 #define ID_ENGINE "$Id$"
58
59 using std::string;
60 using std::vector;
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 FORWARD DECLARATIONS
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
66 namespace JSBSim {
67
68 class FGFDMExec;
69 class FGState;
70 class FGAtmosphere;
71 class FGFCS;
72 class FGAircraft;
73 class FGPropagate;
74 class FGPropulsion;
75 class FGAuxiliary;
76 class FGThruster;
77 class Element;
78
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 CLASS DOCUMENTATION
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82
83 /** Base class for all engines.
84     This base class contains methods and members common to all engines, such as
85     logic to drain fuel from the appropriate tank, etc. 
86     <br>
87     <h3>Configuration File Format:</h3>
88 @code
89         <engine file="{string}">
90             <location unit="{IN | M}">
91                 <x> {number} </x>
92                 <y> {number} </y>
93                 <z> {number} </z>
94             </location>
95             <!-- optional orientation definition -->
96             <orient unit="{RAD | DEG}">
97                 <roll>  {number} </roll>
98                 <pitch> {number} </pitch>
99                 <yaw> {number} </yaw>
100             </orient>
101             <feed> {integer} </feed>
102             ... optional more feed tank index numbers ... 
103             <thruster file="{string}">
104                 <location unit="{IN | M}">
105                     <x> {number} </x>
106                     <y> {number} </y>
107                     <z> {number} </z>
108                 </location>
109                 <orient unit="{RAD | DEG}">
110                     <roll> {number} </roll>
111                     <pitch> {number} </pitch>
112                     <yaw> {number} </yaw>
113                 </orient>
114             </thruster>
115         </engine>
116 @endcode
117 <pre>
118     NOTES:
119         Engines feed from all tanks equally.
120
121         Not all thruster types can be matched with a given engine type.  See the class
122         documentation for engine and thruster classes.
123 </pre>     
124     @author Jon S. Berndt
125     @version $Id$
126 */
127
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 CLASS DECLARATION
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
131
132 class FGEngine : public FGJSBBase, public FGXMLFileRead
133 {
134 public:
135   FGEngine(FGFDMExec* exec, Element* el, int engine_number);
136   virtual ~FGEngine();
137
138   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
139
140   EngineType      GetType(void) { return Type; }
141   virtual string  GetName(void) { return Name; }
142
143   // Engine controls
144   virtual double  GetThrottleMin(void) { return MinThrottle; }
145   virtual double  GetThrottleMax(void) { return MaxThrottle; }
146   virtual double  GetThrottle(void) { return Throttle; }
147   virtual double  GetMixture(void) { return Mixture; }
148   virtual bool    GetStarter(void) { return Starter; }
149
150   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
151   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
152   virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
153   virtual double GetThrust(void) const { return Thrust; }
154   virtual bool   GetStarved(void) { return Starved; }
155   virtual bool   GetRunning(void) const { return Running; }
156   virtual bool   GetCranking(void) { return Cranking; }
157
158   virtual void SetStarved(bool tt) { Starved = tt; }
159   virtual void SetStarved(void)    { Starved = true; }
160
161   virtual void SetRunning(bool bb) { Running=bb; }
162   virtual void SetName(string name) { Name = name; }
163   virtual void AddFeedTank(int tkID);
164   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
165
166   virtual void SetStarter(bool s) { Starter = s; }
167
168   virtual int InitRunning(void){ return 1; }
169
170   /** Resets the Engine parameters to the initial conditions */
171   void ResetToIC(void);
172
173   /** Calculates the thrust of the engine, and other engine functions.
174       @return Thrust in pounds */
175   virtual double Calculate(void) {return 0.0;}
176
177   /// Sets engine placement information
178   virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
179
180   virtual double GetPowerAvailable(void) {return 0.0;};
181
182   virtual bool GetTrimMode(void) {return TrimMode;}
183   virtual void SetTrimMode(bool state) {TrimMode = state;}
184
185   virtual FGColumnVector3& GetBodyForces(void);
186   virtual FGColumnVector3& GetMoments(void);
187
188   bool LoadThruster(Element *el);
189   FGThruster* GetThruster(void) {return Thruster;}
190
191   virtual string GetEngineLabels(string delimeter) = 0;
192   virtual string GetEngineValues(string delimeter) = 0;
193
194 protected:
195   /** Reduces the fuel in the active tanks by the amount required.
196       This function should be called from within the
197       derived class' Calculate() function before any other calculations are
198       done. This base class method removes fuel from the fuel tanks as
199       appropriate, and sets the starved flag if necessary. */
200   virtual void ConsumeFuel(void);
201
202   /** The fuel need is calculated based on power levels and flow rate for that
203       power level. It is also turned from a rate into an actual amount (pounds)
204       by multiplying it by the delta T and the rate.
205       @return Total fuel requirement for this engine in pounds. */
206   virtual double CalcFuelNeed(void);
207
208   FGPropertyManager* PropertyManager;
209   string Name;
210   const int   EngineNumber;
211   EngineType Type;
212   double X, Y, Z;
213   double EnginePitch;
214   double EngineYaw;
215   double SLFuelFlowMax;
216   double MaxThrottle;
217   double MinThrottle;
218
219   double Thrust;
220   double Throttle;
221   double Mixture;
222   double FuelExpended;
223   double FuelFlowRate;
224   double PctPower;
225   bool  Starter;
226   bool  Starved;
227   bool  Running;
228   bool  Cranking;
229   bool  TrimMode;
230   bool  FuelFreeze;
231
232   double FuelFlow_gph;
233   double FuelFlow_pph;
234
235   FGFDMExec*      FDMExec;
236   FGState*        State;
237   FGAtmosphere*   Atmosphere;
238   FGFCS*          FCS;
239   FGPropulsion*   Propulsion;
240   FGAircraft*     Aircraft;
241   FGPropagate*    Propagate;
242   FGAuxiliary*    Auxiliary;
243   FGThruster*     Thruster;
244
245   vector <int> SourceTanks;
246   void Debug(int from);
247 };
248 }
249 #include <FGState.h>
250 #include <FGFDMExec.h>
251 #include <models/FGAtmosphere.h>
252 #include <models/FGFCS.h>
253 #include <models/FGAircraft.h>
254 #include <models/FGPropagate.h>
255 #include <models/FGPropulsion.h>
256 #include <models/FGAuxiliary.h>
257 #include <models/propulsion/FGThruster.h>
258 #include <input_output/FGXMLElement.h>
259
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 #endif
262