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