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