1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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.
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.
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.
25 FUNCTIONAL DESCRIPTION
26 --------------------------------------------------------------------------------
28 Based on Flightgear code, which is based on LaRCSim. This class simulates
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include <FGJSBBase.h>
47 #include "FGThruster.h"
48 #include <input_output/FGPropertyManager.h>
49 #include <input_output/FGXMLFileRead.h>
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 #define ID_ENGINE "$Id$"
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83 /** Base class for all engines.
84 This base class contains methods and members common to all engines, such as
85 logic to drain fuel from the appropriate tank, etc.
87 <h3>Configuration File Format:</h3>
89 <engine file="{string}">
90 <location unit="{IN | M}">
95 <!-- optional orientation definition -->
96 <orient unit="{RAD | DEG}">
97 <roll> {number} </roll>
98 <pitch> {number} </pitch>
101 <feed> {integer} </feed>
102 ... optional more feed tank index numbers ...
103 <thruster file="{string}">
104 <location unit="{IN | M}">
109 <orient unit="{RAD | DEG}">
110 <roll> {number} </roll>
111 <pitch> {number} </pitch>
112 <yaw> {number} </yaw>
119 Engines feed from all tanks equally.
121 Not all thruster types can be matched with a given engine type. See the class
122 documentation for engine and thruster classes.
124 @author Jon S. Berndt
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132 class FGEngine : public FGJSBBase, public FGXMLFileRead
135 FGEngine(FGFDMExec* exec, Element* el, int engine_number);
138 enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
140 EngineType GetType(void) { return Type; }
141 virtual string GetName(void) { return Name; }
144 virtual double GetThrottleMin(void) { return MinThrottle; }
145 virtual double GetThrottleMax(void) { return MaxThrottle; }
146 virtual double GetThrottle(void) { return Throttle; }
147 virtual double GetMixture(void) { return Mixture; }
148 virtual bool GetStarter(void) { return Starter; }
150 virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
151 virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
152 virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
153 virtual bool GetStarved(void) { return Starved; }
154 virtual bool GetRunning(void) const { return Running; }
155 virtual bool GetCranking(void) { return Cranking; }
157 virtual void SetStarved(bool tt) { Starved = tt; }
158 virtual void SetStarved(void) { Starved = true; }
160 virtual void SetRunning(bool bb) { Running=bb; }
161 virtual void SetName(string name) { Name = name; }
162 virtual void AddFeedTank(int tkID);
163 virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
165 virtual void SetStarter(bool s) { Starter = s; }
167 virtual int InitRunning(void){ return 1; }
169 /** Resets the Engine parameters to the initial conditions */
170 void ResetToIC(void);
172 /** Calculates the thrust of the engine, and other engine functions.
173 @return Thrust in pounds */
174 virtual double Calculate(void) {return 0.0;}
176 /// Sets engine placement information
177 virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
179 virtual double GetPowerAvailable(void) {return 0.0;};
181 virtual bool GetTrimMode(void) {return TrimMode;}
182 virtual void SetTrimMode(bool state) {TrimMode = state;}
184 virtual FGColumnVector3& GetBodyForces(void);
185 virtual FGColumnVector3& GetMoments(void);
187 bool LoadThruster(Element *el);
188 FGThruster* GetThruster(void) {return Thruster;}
190 virtual string GetEngineLabels(string delimeter) = 0;
191 virtual string GetEngineValues(string delimeter) = 0;
194 /** Reduces the fuel in the active tanks by the amount required.
195 This function should be called from within the
196 derived class' Calculate() function before any other calculations are
197 done. This base class method removes fuel from the fuel tanks as
198 appropriate, and sets the starved flag if necessary. */
199 virtual void ConsumeFuel(void);
201 /** The fuel need is calculated based on power levels and flow rate for that
202 power level. It is also turned from a rate into an actual amount (pounds)
203 by multiplying it by the delta T and the rate.
204 @return Total fuel requirement for this engine in pounds. */
205 virtual double CalcFuelNeed(void);
207 FGPropertyManager* PropertyManager;
209 const int EngineNumber;
214 double SLFuelFlowMax;
235 FGAtmosphere* Atmosphere;
237 FGPropulsion* Propulsion;
238 FGAircraft* Aircraft;
239 FGPropagate* Propagate;
240 FGAuxiliary* Auxiliary;
241 FGThruster* Thruster;
243 vector <int> SourceTanks;
244 void Debug(int from);
248 #include <FGFDMExec.h>
249 #include <models/FGAtmosphere.h>
250 #include <models/FGFCS.h>
251 #include <models/FGAircraft.h>
252 #include <models/FGPropagate.h>
253 #include <models/FGPropulsion.h>
254 #include <models/FGAuxiliary.h>
255 #include <models/propulsion/FGThruster.h>
256 #include <input_output/FGXMLElement.h>
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%