1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.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 "math/FGModelFunctions.h"
47 #include "input_output/FGXMLFileRead.h"
48 #include "input_output/FGXMLElement.h"
49 #include "models/FGFCS.h"
50 #include "math/FGColumnVector3.h"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 #define ID_ENGINE "$Id: FGEngine.h,v 1.23 2011/03/03 12:16:26 jberndt Exp $"
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74 class FGPropertyManager;
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 /** Base class for all engines.
81 This base class contains methods and members common to all engines, such as
82 logic to drain fuel from the appropriate tank, etc.
84 <h3>Configuration File Format:</h3>
86 <engine file="{string}">
87 <location unit="{IN | M}">
92 <!-- optional orientation definition -->
93 <orient unit="{RAD | DEG}">
94 <roll> {number} </roll>
95 <pitch> {number} </pitch>
98 <feed> {integer} </feed>
99 ... optional more feed tank index numbers ...
100 <thruster file="{string}">
101 <location unit="{IN | M}">
106 <orient unit="{RAD | DEG}">
107 <roll> {number} </roll>
108 <pitch> {number} </pitch>
109 <yaw> {number} </yaw>
117 Not all thruster types can be matched with a given engine type. See the class
118 documentation for engine and thruster classes.
120 @author Jon S. Berndt
121 @version $Id: FGEngine.h,v 1.23 2011/03/03 12:16:26 jberndt Exp $
124 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
128 class FGEngine : public FGModelFunctions, public FGXMLFileRead
131 FGEngine(FGFDMExec* exec, Element* el, int engine_number);
134 enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
136 EngineType GetType(void) { return Type; }
137 virtual string GetName(void) { return Name; }
140 virtual double GetThrottleMin(void) { return MinThrottle; }
141 virtual double GetThrottleMax(void) { return MaxThrottle; }
142 virtual double GetThrottle(void) { return Throttle; }
143 virtual double GetMixture(void) { return Mixture; }
144 virtual bool GetStarter(void) { return Starter; }
146 virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
147 virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
148 virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
149 virtual double GetFuelUsedLbs(void) const {return FuelUsedLbs;}
150 virtual bool GetStarved(void) { return Starved; }
151 virtual bool GetRunning(void) const { return Running; }
152 virtual bool GetCranking(void) { return Cranking; }
154 virtual void SetStarved(bool tt) { Starved = tt; }
155 virtual void SetStarved(void) { Starved = true; }
157 virtual void SetRunning(bool bb) { Running=bb; }
158 virtual void SetName(string name) { Name = name; }
159 virtual void AddFeedTank(int tkID, int priority);
160 virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
162 virtual void SetStarter(bool s) { Starter = s; }
164 virtual int InitRunning(void){ return 1; }
166 /** Resets the Engine parameters to the initial conditions */
167 void ResetToIC(void);
169 /** Calculates the thrust of the engine, and other engine functions. */
170 virtual void Calculate(void) = 0;
172 /// Sets engine placement information
173 virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
175 virtual double GetPowerAvailable(void) {return 0.0;};
177 virtual FGColumnVector3& GetBodyForces(void);
178 virtual FGColumnVector3& GetMoments(void);
180 bool LoadThruster(Element *el);
181 FGThruster* GetThruster(void) {return Thruster;}
183 virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
184 virtual std::string GetEngineValues(const std::string& delimiter) = 0;
187 /** Reduces the fuel in the active tanks by the amount required.
188 This function should be called from within the
189 derived class' Calculate() function before any other calculations are
190 done. This base class method removes fuel from the fuel tanks as
191 appropriate, and sets the starved flag if necessary. */
192 virtual void ConsumeFuel(void);
194 /** The fuel need is calculated based on power levels and flow rate for that
195 power level. It is also turned from a rate into an actual amount (pounds)
196 by multiplying it by the delta T and the rate.
197 @return Total fuel requirement for this engine in pounds. */
198 virtual double CalcFuelNeed(void);
200 FGPropertyManager* PropertyManager;
202 const int EngineNumber;
207 double SLFuelFlowMax;
228 FGAtmosphere* Atmosphere;
230 FGPropulsion* Propulsion;
231 FGAircraft* Aircraft;
232 FGPropagate* Propagate;
233 FGAuxiliary* Auxiliary;
234 FGThruster* Thruster;
236 std::vector <int> SourceTanks;
238 void Debug(int from);
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%