]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGEngine.h
783fbc0fe5fb6fdfc8475bd897fdb5c86ba01c70
[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 bool   GetStarved(void) { return Starved; }
154   virtual bool   GetRunning(void) const { return Running; }
155   virtual bool   GetCranking(void) { return Cranking; }
156
157   virtual void SetStarved(bool tt) { Starved = tt; }
158   virtual void SetStarved(void)    { Starved = true; }
159
160   virtual void SetRunning(bool bb) { Running=bb; }
161   virtual void SetName(string name) { Name = name; }
162   virtual void AddFeedTank(int tkID);
163   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
164
165   virtual void SetStarter(bool s) { Starter = s; }
166
167   virtual int InitRunning(void){ return 1; }
168
169   /** Resets the Engine parameters to the initial conditions */
170   void ResetToIC(void);
171
172   /** Calculates the thrust of the engine, and other engine functions.
173       @return Thrust in pounds */
174   virtual double Calculate(void) {return 0.0;}
175
176   /// Sets engine placement information
177   virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
178
179   virtual double GetPowerAvailable(void) {return 0.0;};
180
181   virtual bool GetTrimMode(void) {return TrimMode;}
182   virtual void SetTrimMode(bool state) {TrimMode = state;}
183
184   virtual FGColumnVector3& GetBodyForces(void);
185   virtual FGColumnVector3& GetMoments(void);
186
187   bool LoadThruster(Element *el);
188   FGThruster* GetThruster(void) {return Thruster;}
189
190   virtual string GetEngineLabels(string delimeter) = 0;
191   virtual string GetEngineValues(string delimeter) = 0;
192
193 protected:
194   /** Reduces the fuel in the active tanks by the amount required.
195       This function should be called from within the
196       derived class' Calculate() function before any other calculations are
197       done. This base class method removes fuel from the fuel tanks as
198       appropriate, and sets the starved flag if necessary. */
199   virtual void ConsumeFuel(void);
200
201   /** The fuel need is calculated based on power levels and flow rate for that
202       power level. It is also turned from a rate into an actual amount (pounds)
203       by multiplying it by the delta T and the rate.
204       @return Total fuel requirement for this engine in pounds. */
205   virtual double CalcFuelNeed(void);
206
207   FGPropertyManager* PropertyManager;
208   string Name;
209   const int   EngineNumber;
210   EngineType Type;
211   double X, Y, Z;
212   double EnginePitch;
213   double EngineYaw;
214   double SLFuelFlowMax;
215   double MaxThrottle;
216   double MinThrottle;
217
218   double Throttle;
219   double Mixture;
220   double FuelExpended;
221   double FuelFlowRate;
222   double PctPower;
223   bool  Starter;
224   bool  Starved;
225   bool  Running;
226   bool  Cranking;
227   bool  TrimMode;
228   bool  FuelFreeze;
229
230   double FuelFlow_gph;
231   double FuelFlow_pph;
232
233   FGFDMExec*      FDMExec;
234   FGState*        State;
235   FGAtmosphere*   Atmosphere;
236   FGFCS*          FCS;
237   FGPropulsion*   Propulsion;
238   FGAircraft*     Aircraft;
239   FGPropagate*    Propagate;
240   FGAuxiliary*    Auxiliary;
241   FGThruster*     Thruster;
242
243   vector <int> SourceTanks;
244   void Debug(int from);
245 };
246 }
247 #include <FGState.h>
248 #include <FGFDMExec.h>
249 #include <models/FGAtmosphere.h>
250 #include <models/FGFCS.h>
251 #include <models/FGAircraft.h>
252 #include <models/FGPropagate.h>
253 #include <models/FGPropulsion.h>
254 #include <models/FGAuxiliary.h>
255 #include <models/propulsion/FGThruster.h>
256 #include <input_output/FGXMLElement.h>
257
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 #endif
260