]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.h
Updated to match changes in radiostack.[ch]xx
[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   virtual double  GetThrottle(void) { return Throttle; }
119   virtual double  GetMixture(void) { return Mixture; }
120   virtual int     GetMagnetos(void) { return Magnetos; }
121   virtual bool    GetStarter(void) { return Starter; }
122   virtual double  GetThrust(void) { return Thrust; }
123   virtual bool    GetStarved(void) { return Starved; }
124   virtual bool    GetFlameout(void) { return Flameout; }
125   virtual bool    GetRunning(void) { return Running; }
126   virtual bool    GetCranking(void) { return Cranking; }
127   virtual int     GetType(void) { return Type; }
128   virtual string  GetName(void) { return Name; }
129
130   virtual double getFuelFlow_gph () const {
131     return FuelFlow_gph;
132   }
133
134   virtual double getManifoldPressure_inHg () const {
135     return ManifoldPressure_inHg;
136   }
137   virtual double getExhaustGasTemp_degF () const {
138     return (ExhaustGasTemp_degK - 273) * (9.0 / 5.0) + 32.0;
139   }
140   virtual double getCylinderHeadTemp_degF () const {
141     return (CylinderHeadTemp_degK - 273) * (9.0 / 5.0) + 32.0;
142   }
143   virtual double getOilPressure_psi () const {
144     return OilPressure_psi;
145   }
146   virtual double getOilTemp_degF () const {
147     return (OilTemp_degK - 273.0) * (9.0 / 5.0) + 32.0;
148   }
149
150   virtual void SetStarved(bool tt) {Starved = tt;}
151   virtual void SetStarved(void)    {Starved = true;}
152
153   virtual void SetRunning(bool bb) { Running=bb; }
154   virtual void SetName(string name) {Name = name;}
155   virtual void AddFeedTank(int tkID);
156
157   virtual void SetMagnetos(int m) { Magnetos = m; }
158   virtual void SetStarter(bool s) { Starter = s;}
159
160   /** Calculates the thrust of the engine, and other engine functions.
161       @param PowerRequired this is the power required to run the thrusting device
162              such as a propeller. This resisting effect must be provided to the 
163              engine model.
164       @return Thrust in pounds */
165   virtual double Calculate(double PowerRequired) {return 0.0;};
166
167   /** Reduces the fuel in the active tanks by the amount required.
168       This function should be called from within the
169       derived class' Calculate() function before any other calculations are
170       done. This base class method removes fuel from the fuel tanks as
171       appropriate, and sets the starved flag if necessary. */
172   virtual void ConsumeFuel(void);
173
174   /** The fuel need is calculated based on power levels and flow rate for that
175       power level. It is also turned from a rate into an actual amount (pounds)
176       by multiplying it by the delta T and the rate.
177       @return Total fuel requirement for this engine in pounds. */
178   virtual double CalcFuelNeed(void);
179
180   /** The oxidizer need is calculated based on power levels and flow rate for that
181       power level. It is also turned from a rate into an actual amount (pounds)
182       by multiplying it by the delta T and the rate.
183       @return Total oxidizer requirement for this engine in pounds. */
184   virtual double CalcOxidizerNeed(void);
185
186   /// Sets engine placement information
187   virtual void SetPlacement(double x, double y, double z, double pitch, double yaw);
188
189   /// Sets the engine number
190   virtual void SetEngineNumber(int nn) {EngineNumber = nn;}
191
192   virtual double GetPowerAvailable(void) {return 0.0;};
193
194   virtual bool GetTrimMode(void) {return TrimMode;}
195   virtual void SetTrimMode(bool state) {TrimMode = state;}
196
197 protected:
198   string Name;
199   EngineType Type;
200   double X, Y, Z;
201   double EnginePitch;
202   double EngineYaw;
203   double SLFuelFlowMax;
204   double SLOxiFlowMax;
205   double MaxThrottle;
206   double MinThrottle;
207
208   double Thrust;
209   double Throttle;
210   double Mixture;
211   int   Magnetos;
212   bool  Starter;
213   double FuelNeed, OxidizerNeed;
214   bool  Starved;
215   bool  Flameout;
216   bool  Running;
217   bool  Cranking;
218   double PctPower;
219   int   EngineNumber;
220   bool  TrimMode;
221
222   double FuelFlow_gph;
223   double ManifoldPressure_inHg;
224   double ExhaustGasTemp_degK;
225   double CylinderHeadTemp_degK;
226   double OilPressure_psi;
227   double OilTemp_degK;
228
229   FGFDMExec*      FDMExec;
230   FGState*        State;
231   FGAtmosphere*   Atmosphere;
232   FGFCS*          FCS;
233   FGPropulsion*   Propulsion;
234   FGAircraft*     Aircraft;
235   FGTranslation*  Translation;
236   FGRotation*     Rotation;
237   FGPosition*     Position;
238   FGAuxiliary*    Auxiliary;
239   FGOutput*       Output;
240
241   vector <int> SourceTanks;
242   virtual void Debug(int from);
243 };
244
245 #include "FGState.h"
246 #include "FGFDMExec.h"
247 #include "FGAtmosphere.h"
248 #include "FGFCS.h"
249 #include "FGAircraft.h"
250 #include "FGTranslation.h"
251 #include "FGRotation.h"
252 #include "FGPropulsion.h"
253 #include "FGPosition.h"
254 #include "FGAuxiliary.h"
255 #include "FGOutput.h"
256
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 #endif
259