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 double GetThrust(void) const { return Thrust; }
154 virtual bool GetStarved(void) { return Starved; }
155 virtual bool GetRunning(void) const { return Running; }
156 virtual bool GetCranking(void) { return Cranking; }
158 virtual void SetStarved(bool tt) { Starved = tt; }
159 virtual void SetStarved(void) { Starved = true; }
161 virtual void SetRunning(bool bb) { Running=bb; }
162 virtual void SetName(string name) { Name = name; }
163 virtual void AddFeedTank(int tkID);
164 virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
166 virtual void SetStarter(bool s) { Starter = s; }
168 virtual int InitRunning(void){ return 1; }
170 /** Resets the Engine parameters to the initial conditions */
171 void ResetToIC(void);
173 /** Calculates the thrust of the engine, and other engine functions.
174 @return Thrust in pounds */
175 virtual double Calculate(void) {return 0.0;}
177 /// Sets engine placement information
178 virtual void SetPlacement(FGColumnVector3& location, FGColumnVector3& orientation);
180 virtual double GetPowerAvailable(void) {return 0.0;};
182 virtual bool GetTrimMode(void) {return TrimMode;}
183 virtual void SetTrimMode(bool state) {TrimMode = state;}
185 virtual FGColumnVector3& GetBodyForces(void);
186 virtual FGColumnVector3& GetMoments(void);
188 bool LoadThruster(Element *el);
189 FGThruster* GetThruster(void) {return Thruster;}
191 virtual string GetEngineLabels(string delimeter) = 0;
192 virtual string GetEngineValues(string delimeter) = 0;
195 /** Reduces the fuel in the active tanks by the amount required.
196 This function should be called from within the
197 derived class' Calculate() function before any other calculations are
198 done. This base class method removes fuel from the fuel tanks as
199 appropriate, and sets the starved flag if necessary. */
200 virtual void ConsumeFuel(void);
202 /** The fuel need is calculated based on power levels and flow rate for that
203 power level. It is also turned from a rate into an actual amount (pounds)
204 by multiplying it by the delta T and the rate.
205 @return Total fuel requirement for this engine in pounds. */
206 virtual double CalcFuelNeed(void);
208 FGPropertyManager* PropertyManager;
210 const int EngineNumber;
215 double SLFuelFlowMax;
237 FGAtmosphere* Atmosphere;
239 FGPropulsion* Propulsion;
240 FGAircraft* Aircraft;
241 FGPropagate* Propagate;
242 FGAuxiliary* Auxiliary;
243 FGThruster* Thruster;
245 vector <int> SourceTanks;
246 void Debug(int from);
250 #include <FGFDMExec.h>
251 #include <models/FGAtmosphere.h>
252 #include <models/FGFCS.h>
253 #include <models/FGAircraft.h>
254 #include <models/FGPropagate.h>
255 #include <models/FGPropulsion.h>
256 #include <models/FGAuxiliary.h>
257 #include <models/propulsion/FGThruster.h>
258 #include <input_output/FGXMLElement.h>
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%