]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Removed FGMatrix.* because it is no longer used by JSBSim.
[flightgear.git] / src / FDM / JSBSim / 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 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28
29 Based on Flightgear code, which is based on LaRCSim. This class simulates
30 a generic engine.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 01/21/99   JSB   Created
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 SENTRY
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #ifndef FGENGINE_H
41 #define FGENGINE_H
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 INCLUDES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #ifdef FGFS
48 #  include <simgear/compiler.h>
49 #  include STL_STRING
50    SG_USING_STD(string);
51 #  ifdef SG_HAVE_STD_INCLUDES
52 #    include <vector>
53 #  else
54 #    include <vector.h>
55 #  endif
56 #else
57 #  include <vector>
58 #  include <string>
59 #endif
60
61 #include "FGJSBBase.h"
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 DEFINITIONS
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 #define ID_ENGINE "$Id$"
68
69 using std::string;
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 FORWARD DECLARATIONS
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 class FGFDMExec;
76 class FGState;
77 class FGAtmosphere;
78 class FGFCS;
79 class FGAircraft;
80 class FGTranslation;
81 class FGRotation;
82 class FGPropulsion;
83 class FGPosition;
84 class FGAuxiliary;
85 class FGOutput;
86
87 using std::vector;
88
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92
93 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 CLASS DOCUMENTATION
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96
97 /** Base class for all engines.
98     This base class contains methods and members common to all engines, such as
99     logic to drain fuel from the appropriate tank, etc.
100     @author Jon S. Berndt
101     @version $Id$ 
102 */
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DECLARATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 class FGEngine : public FGJSBBase
109 {
110 public:
111   FGEngine(FGFDMExec* exec);
112   virtual ~FGEngine();
113
114   enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet, etTurboShaft};
115
116   virtual double  GetThrottleMin(void) { return MinThrottle; }
117   virtual double  GetThrottleMax(void) { return MaxThrottle; }
118   double  GetThrottle(void) { return Throttle; }
119   double  GetMixture(void) { return Mixture; }
120   int     GetMagnetos(void) { return Magnetos; }
121   bool    GetStarter(void) { return Starter; }
122   double  GetThrust(void) { return Thrust; }
123   bool    GetStarved(void) { return Starved; }
124   bool    GetFlameout(void) { return Flameout; }
125   bool    GetRunning(void) { return Running; }
126   bool    GetCranking(void) { return Cranking; }
127   int     GetType(void) { return Type; }
128   string  GetName(void) { return Name; }
129
130   virtual double getManifoldPressure_inHg () const {
131     return ManifoldPressure_inHg;
132   }
133   virtual double getExhaustGasTemp_degF () const {
134     return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
135   }
136   virtual double getCylinderHeadTemp_degF () const {
137     return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
138   }
139   virtual double getOilPressure_psi () const {
140     return OilPressure_psi;
141   }
142   virtual double getOilTemp_degF () const {
143     return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
144   }
145
146   void SetStarved(bool tt) {Starved = tt;}
147   void SetStarved(void)    {Starved = true;}
148
149   void SetRunning(bool bb) { Running=bb; }
150   void SetName(string name) {Name = name;}
151   void AddFeedTank(int tkID);
152
153   void SetMagnetos(int m) { Magnetos = m; }
154   void SetStarter(bool s) { Starter = s;}
155
156   /** Calculates the thrust of the engine, and other engine functions.
157       @param PowerRequired this is the power required to run the thrusting device
158              such as a propeller. This resisting effect must be provided to the 
159              engine model.
160       @return Thrust in pounds */
161   virtual double Calculate(double PowerRequired) {return 0.0;};
162
163   /** Reduces the fuel in the active tanks by the amount required.
164       This function should be called from within the
165       derived class' Calculate() function before any other calculations are
166       done. This base class method removes fuel from the fuel tanks as
167       appropriate, and sets the starved flag if necessary. */
168   void ConsumeFuel(void);
169
170   /** The fuel need is calculated based on power levels and flow rate for that
171       power level. It is also turned from a rate into an actual amount (pounds)
172       by multiplying it by the delta T and the rate.
173       @return Total fuel requirement for this engine in pounds. */
174   double CalcFuelNeed(void);
175
176   /** The oxidizer need is calculated based on power levels and flow rate for that
177       power level. It is also turned from a rate into an actual amount (pounds)
178       by multiplying it by the delta T and the rate.
179       @return Total oxidizer requirement for this engine in pounds. */
180   double CalcOxidizerNeed(void);
181
182   /// Sets engine placement information
183   void SetPlacement(double x, double y, double z, double pitch, double yaw);
184
185   /// Sets the engine number
186   void SetEngineNumber(int nn) {EngineNumber = nn;}
187
188   virtual double GetPowerAvailable(void) {return 0.0;};
189
190   bool GetTrimMode(void) {return TrimMode;}
191   void SetTrimMode(bool state) {TrimMode = state;}
192
193 protected:
194   string Name;
195   EngineType Type;
196   double X, Y, Z;
197   double EnginePitch;
198   double EngineYaw;
199   double SLFuelFlowMax;
200   double SLOxiFlowMax;
201   double MaxThrottle;
202   double MinThrottle;
203
204   double Thrust;
205   double Throttle;
206   double Mixture;
207   int   Magnetos;
208   bool  Starter;
209   double FuelNeed, OxidizerNeed;
210   bool  Starved;
211   bool  Flameout;
212   bool  Running;
213   bool  Cranking;
214   double PctPower;
215   int   EngineNumber;
216   bool  TrimMode;
217
218   double ManifoldPressure_inHg;
219   double ExhaustGasTemp_degK;
220   double CylinderHeadTemp_degK;
221   double OilPressure_psi;
222   double OilTemp_degK;
223
224   FGFDMExec*      FDMExec;
225   FGState*        State;
226   FGAtmosphere*   Atmosphere;
227   FGFCS*          FCS;
228   FGPropulsion*   Propulsion;
229   FGAircraft*     Aircraft;
230   FGTranslation*  Translation;
231   FGRotation*     Rotation;
232   FGPosition*     Position;
233   FGAuxiliary*    Auxiliary;
234   FGOutput*       Output;
235
236   vector <int> SourceTanks;
237   virtual void Debug(int from);
238 };
239
240 #include "FGState.h"
241 #include "FGFDMExec.h"
242 #include "FGAtmosphere.h"
243 #include "FGFCS.h"
244 #include "FGAircraft.h"
245 #include "FGTranslation.h"
246 #include "FGRotation.h"
247 #include "FGPropulsion.h"
248 #include "FGPosition.h"
249 #include "FGAuxiliary.h"
250 #include "FGOutput.h"
251
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 #endif
254