]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropulsion.h
Sync. with JSBSim CVS.
[flightgear.git] / src / FDM / JSBSim / FGPropulsion.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGPropulsion.h
4  Author:       Jon S. Berndt
5  Date started: 08/20/00
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
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
12  version.
13
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
17  details.
18
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.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 08/20/00   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGPROPULSION_H
35 #define FGPROPULSION_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  ifdef SG_HAVE_STD_INCLUDES
44 #    include <vector>
45 #    include <iterator>
46 #  else
47 #    include <vector.h>
48 #    include <iterator.h>
49 #  endif
50 #else
51 #  include <vector>
52 #  include <iterator>
53 #endif
54
55 #include "FGModel.h"
56 #include "FGEngine.h"
57 #include "FGTank.h"
58 #include "FGThruster.h"
59 #include "FGMatrix33.h"
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 DEFINITIONS
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 #define ID_PROPULSION "$Id$"
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 FORWARD DECLARATIONS
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 namespace JSBSim {
72
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 CLASS DOCUMENTATION
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76
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:
83
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.
87
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.
94     @author Jon S. Berndt
95     @version $Id$
96     @see
97     FGEngine
98     FGTank
99     FGThruster
100 */
101
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 CLASS DECLARATION
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
105
106 class FGPropulsion : public FGModel
107 {
108 public:
109   /// Constructor
110   FGPropulsion(FGFDMExec*);
111   /// Destructor
112   ~FGPropulsion();
113
114   /** Executes the propulsion model.
115       The initial plan for the FGPropulsion class calls for Run() to be executed,
116       performing the following tasks:
117       <ol>
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>
127
128       [Note: Should we be checking the Starved flag here?] */
129   bool Run(void);
130
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);
137
138   /// Retrieves the number of engines defined for the aircraft.
139   inline unsigned int GetNumEngines(void) const {return Engines.size();}
140
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
144               available */
145   inline FGEngine* GetEngine(unsigned int index) {
146                       if (index <= Engines.size()-1) return Engines[index];
147                       else                           return 0L;      }
148
149   /// Retrieves the number of tanks defined for the aircraft.
150   inline unsigned int GetNumTanks(void) const {return Tanks.size();}
151
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
155               available */
156   inline FGTank* GetTank(unsigned int index) {
157                       if (index <= Tanks.size()-1) return Tanks[index];
158                       else                         return 0L;        }
159
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
163               available */
164   inline FGThruster* GetThruster(unsigned int index) {
165                       if (index <= Thrusters.size()-1) return Thrusters[index];
166                       else                             return 0L;    }
167
168   /** Returns the number of fuel tanks currently actively supplying fuel */
169   inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
170
171   /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
172   inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
173
174   /** Loops the engines/thrusters until thrust output steady (used for trimming) */
175   bool GetSteadyState(void);
176
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);
180
181   string GetPropulsionStrings(void);
182   string GetPropulsionValues(void);
183
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);}
188
189   FGColumnVector3& GetTanksMoment(void);
190   double GetTanksWeight(void);
191
192   inline int GetActiveEngine(void) const
193   {
194     return ActiveEngine;
195   }
196
197   inline int GetActiveEngine(void);
198
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);
204
205   void bind();
206   void unbind();
207
208 private:
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;
220   int ActiveEngine;
221   double dt;
222   FGColumnVector3 vForces;
223   FGColumnVector3 vMoments;
224   FGColumnVector3 vTankXYZ;
225   FGColumnVector3 vXYZtank_arm;
226   FGMatrix33 tankJ;
227   void Debug(int from);
228 };
229 }
230 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 #endif
232