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