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 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 General Public License for more
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.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGPROPULSION_H
35 #define FGPROPULSION_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
48 # include <iterator.h>
58 #include "FGThruster.h"
59 #include "FGMatrix33.h"
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 #define ID_PROPULSION "$Id$"
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 /** Propulsion management class.
78 The Propulsion class is the container for the entire propulsion system, which is
79 comprised of engines, tanks, and "thrusters" (the device that transforms the
80 engine power into a force that acts on the aircraft, such as a nozzle or
81 propeller). Once the Propulsion class gets the config file, it reads in
82 information which is specific to a type of engine. Then:
84 -# The appropriate engine type instance is created
85 -# A thruster object is instantiated, and is linked to the engine
86 -# At least one tank object is created, and is linked to an engine.
88 At Run time each engines Calculate() method is called to return the excess power
89 generated during that iteration. The drag from the previous iteration is sub-
90 tracted to give the excess power available for thrust this pass. That quantity
91 is passed to the thrusters associated with a particular engine - perhaps with a
92 scaling mechanism (gearing?) to allow the engine to give its associated thrust-
93 ers specific distributed portions of the excess power.
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
106 class FGPropulsion : public FGModel
110 FGPropulsion(FGFDMExec*);
114 /** Executes the propulsion model.
115 The initial plan for the FGPropulsion class calls for Run() to be executed,
116 performing the following tasks:
118 <li>Determine the drag - or power required - for the attached thrust effector
119 for this engine so that any feedback to the engine can be performed. This
120 is done by calling FGThruster::CalculatePReq()</li>
121 <li>Given 1, above, calculate the power available from the engine. This is
122 done by calling FGEngine::CalculatePAvail()</li>
123 <li>Next, calculate the thrust output from the thruster model given the power
124 available and the power required. This may also result in new performance
125 numbers for the thruster in the case of the propeller, at least. This
126 result is returned from a call to Calculate().</li></ol>
128 [Note: Should we be checking the Starved flag here?] */
131 /** Loads the propulsion system (engine[s], tank[s], thruster[s]).
132 Characteristics of the propulsion system are read in from the config file.
133 @param AC_cfg pointer to the config file instance that describes the
134 aircraft being modeled.
135 @return true if successfully loaded, otherwise false */
136 bool Load(FGConfigFile* AC_cfg);
138 /// Retrieves the number of engines defined for the aircraft.
139 inline unsigned int GetNumEngines(void) const {return Engines.size();}
141 /** Retrieves an engine object pointer from the list of engines.
142 @param index the engine index within the vector container
143 @return the address of the specific engine, or zero if no such engine is
145 inline FGEngine* GetEngine(unsigned int index) {
146 if (index <= Engines.size()-1) return Engines[index];
149 /// Retrieves the number of tanks defined for the aircraft.
150 inline unsigned int GetNumTanks(void) const {return Tanks.size();}
152 /** Retrieves a tank object pointer from the list of tanks.
153 @param index the tank index within the vector container
154 @return the address of the specific tank, or zero if no such tank is
156 inline FGTank* GetTank(unsigned int index) {
157 if (index <= Tanks.size()-1) return Tanks[index];
160 /** Retrieves a thruster object pointer from the list of thrusters.
161 @param index the thruster index within the vector container
162 @return the address of the specific thruster, or zero if no such thruster is
164 inline FGThruster* GetThruster(unsigned int index) {
165 if (index <= Thrusters.size()-1) return Thrusters[index];
168 /** Returns the number of fuel tanks currently actively supplying fuel */
169 inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
171 /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
172 inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
174 /** Loops the engines/thrusters until thrust output steady (used for trimming) */
175 bool GetSteadyState(void);
177 /** starts the engines in IC mode (dt=0). All engine-specific setup must
178 be done before calling this (i.e. magnetos, starter engage, etc.) */
179 bool ICEngineStart(void);
181 string GetPropulsionStrings(void);
182 string GetPropulsionValues(void);
184 inline FGColumnVector3& GetForces(void) {return vForces; }
185 inline double GetForces(int n) const { return vForces(n);}
186 inline FGColumnVector3& GetMoments(void) {return vMoments;}
187 inline double GetMoments(int n) const {return vMoments(n);}
189 FGColumnVector3& GetTanksMoment(void);
190 double GetTanksWeight(void);
192 inline int GetActiveEngine(void) const
197 inline int GetActiveEngine(void);
199 void SetMagnetos(int setting);
200 void SetStarter(int setting);
201 void SetCutoff(int setting=0);
202 void SetActiveEngine(int engine);
203 FGMatrix33& CalculateTankInertias(void);
209 vector <FGEngine*> Engines;
210 vector <FGTank*> Tanks;
211 vector <FGTank*>::iterator iTank;
212 vector <FGThruster*> Thrusters;
213 unsigned int numSelectedFuelTanks;
214 unsigned int numSelectedOxiTanks;
215 unsigned int numFuelTanks;
216 unsigned int numOxiTanks;
217 unsigned int numEngines;
218 unsigned int numTanks;
219 unsigned int numThrusters;
222 FGColumnVector3 vForces;
223 FGColumnVector3 vMoments;
224 FGColumnVector3 vTankXYZ;
225 FGColumnVector3 vXYZtank_arm;
227 void Debug(int from);
230 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%