]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.h
Adjust the turbine names for N1, N2 and EGT_degC to match those already specified...
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  Header:       FGFDMExec.h
3  Author:       Jon Berndt
4  Date started: 11/17/98
5
6  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
7
8  This program is free software; you can redistribute it and/or modify it under
9  the terms of the GNU General Public License as published by the Free Software
10  Foundation; either version 2 of the License, or (at your option) any later
11  version.
12
13  This program is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  details.
17
18  You should have received a copy of the GNU 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.
21
22  Further information about the GNU General Public License can also be found on
23  the world wide web at http://www.gnu.org.
24
25 HISTORY
26 --------------------------------------------------------------------------------
27 11/17/98   JSB   Created
28 7/31/99     TP   Added RunIC function that runs the sim so that every frame
29                  begins with the IC values from the given FGInitialCondition
30                                    object and dt=0.
31
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 SENTRY
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
35
36 #ifndef FGFDMEXEC_HEADER_H
37 #define FGFDMEXEC_HEADER_H
38
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 INCLUDES
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42
43 #include "FGModel.h"
44 #include "FGTrim.h"
45 #include "FGInitialCondition.h"
46 #include "FGJSBBase.h"
47 #include "FGPropertyManager.h"
48
49 #include <vector>
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 DEFINITIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 #define ID_FDMEXEC "$Id$"
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FORWARD DECLARATIONS
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 namespace JSBSim {
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /** Encapsulates the JSBSim simulation executive.
68     This class is the interface class through which all other simulation classes
69     are instantiated, initialized, and run. When integrated with FlightGear (or
70     other flight simulator) this class is typically instantiated by an interface
71     class on the simulator side.
72
73     When an aircraft model is loaded the config file is parsed and for each of the
74     sections of the config file (propulsion, flight control, etc.) the
75     corresponding "ReadXXX()" method is called. From within this method the 
76     "Load()" method of that system is called (e.g. LoadFCS).
77
78     <h4>JSBSim Debugging Directives</h4>
79
80     This describes to any interested entity the debug level
81     requested by setting the JSBSIM_DEBUG environment variable.
82     The bitmasked value choices are as follows:<ol>
83     <li><b>unset</b>: In this case (the default) JSBSim would only print
84        out the normally expected messages, essentially echoing
85        the config files as they are read. If the environment
86        variable is not set, debug_lvl is set to 1 internally</li>
87     <li><b>0</b>: This requests JSBSim not to output any messages
88        whatsoever.</li>
89     <li><b>1</b>: This value explicity requests the normal JSBSim
90        startup messages</li>
91     <li><b>2</b>: This value asks for a message to be printed out when
92        a class is instantiated</li>
93     <li><b>4</b>: When this value is set, a message is displayed when a
94        FGModel object executes its Run() method</li>
95     <li><b>8</b>: When this value is set, various runtime state variables
96        are printed out periodically</li>
97     <li><b>16</b>: When set various parameters are sanity checked and
98        a message is printed out when they go out of bounds</li>
99     </ol>
100
101     @author Jon S. Berndt
102     @version $Id$
103 */
104
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 CLASS DECLARATION
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108
109 class FGFDMExec : public FGJSBBase
110 {
111 public:
112
113   /// Default constructor
114   FGFDMExec(FGPropertyManager* root = 0);
115   
116   /// Default destructor
117   ~FGFDMExec();
118
119   /** This routine places a model into the runlist at the specified rate. The
120       "rate" is not really a clock rate. It represents how many calls to the
121       FGFDMExec::Run() method must be made before the model is executed. A
122       value of 1 means that the model will be executed for each call to the
123       exec's Run() method. A value of 5 means that the model will only be
124       executed every 5th call to the exec's Run() method.
125       @param model A pointer to the model being scheduled.
126       @param rate The rate at which to execute the model as described above.
127       @return Currently returns 0 always. */
128   int  Schedule(FGModel* model, int rate);
129
130   /** This executes each scheduled model in succession.
131       @return true if successful, false if sim should be ended  */
132   bool Run(void);
133
134   /** Initializes the sim from the initial condition object and executes
135       each scheduled model without integrating i.e. dt=0.
136       @return true if successful
137        */
138   bool RunIC(void);
139
140   /// Freezes the sim
141   void Freeze(void) {frozen = true;}
142
143   /// Resumes the sim
144   void Resume(void) {frozen = false;}
145   
146   /** Loads an aircraft model.  
147       @param AircraftPath path to the aircraft directory. For instance:
148       "aircraft". Under aircraft, then, would be directories for various
149       modeled aircraft such as C172/, x15/, etc.
150       @param EnginePath path to the directory under which engine config
151       files are kept, for instance "engine"
152       @param model the name of the aircraft model itself. This file will
153       be looked for in the directory specified in the AircraftPath variable,
154       and in turn under the directory with the same name as the model. For
155       instance: "aircraft/x15/x15.xml"
156       @return true if successful*/
157   bool LoadModel(string AircraftPath, string EnginePath, string model);
158   
159
160   /** Loads an aircraft model.  The paths to the aircraft and engine
161       config file directories must be set prior to calling this.  See
162       below.
163       @param model the name of the aircraft model itself. This file will
164       be looked for in the directory specified in the AircraftPath variable,
165       and in turn under the directory with the same name as the model. For
166       instance: "aircraft/x15/x15.xml"
167       @return true if successful*/
168   bool LoadModel(string model);
169   
170
171   /** Sets the path to the engine config file directories.
172       @param path path to the directory under which engine config
173       files are kept, for instance "engine"
174   */
175   bool SetEnginePath(string path)   { EnginePath = path; return true; }
176
177   /** Sets the path to the aircraft config file directories.
178       @param path path to the aircraft directory. For instance:
179       "aircraft". Under aircraft, then, would be directories for various
180       modeled aircraft such as C172/, x15/, etc.
181   */
182   bool SetAircraftPath(string path) { AircraftPath = path; return true; }
183   
184   /** Sets the path to the autopilot config file directories.
185       @param path path to the control directory. For instance:
186       "control".
187   */
188   bool SetControlPath(string path) { ControlPath = path; return true; }
189   
190  
191   /// @name Top-level executive State and Model retrieval mechanism
192   //@{
193   /// Returns the FGState pointer.
194   inline FGState* GetState(void)              {return State;}
195   /// Returns the FGAtmosphere pointer.
196   inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
197   /// Returns the FGFCS pointer.
198   inline FGFCS* GetFCS(void)                  {return FCS;}
199   /// Returns the FGPropulsion pointer.
200   inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
201   /// Returns the FGAircraft pointer.
202   inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
203   /// Returns the FGAerodynamics pointer
204   inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
205   /// Returns the FGInertial pointer.
206   inline FGInertial* GetInertial(void)        {return Inertial;}
207   /// Returns the FGGroundReactions pointer.
208   inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
209   /// Returns the FGAircraft pointer.
210   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
211   /// Returns the FGTranslation pointer.
212   inline FGTranslation* GetTranslation(void)  {return Translation;}
213   /// Returns the FGRotation pointer.
214   inline FGRotation* GetRotation(void)        {return Rotation;}
215   /// Returns the FGPosition pointer.
216   inline FGPosition* GetPosition(void)        {return Position;}
217   /// Returns the FGAuxiliary pointer.
218   inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
219   /// Returns the FGOutput pointer.
220   inline FGOutput* GetOutput(void)            {return Output;}
221   // Returns a pointer to the FGInitialCondition object
222   inline FGInitialCondition* GetIC(void)      {return IC;}
223   // Returns a pointer to the FGTrim object
224   FGTrim* GetTrim(void);
225   //@}
226   
227   /// Retrieves the engine path.
228   inline string GetEnginePath(void)          {return EnginePath;}
229   /// Retrieves the aircraft path.
230   inline string GetAircraftPath(void)        {return AircraftPath;}
231   /// Retrieves the control path.
232   inline string GetControlPath(void)        {return ControlPath;}
233   
234   string GetModelName(void) { return modelName; }
235   
236   FGPropertyManager* GetPropertyManager(void);
237   vector <string> EnumerateFDMs(void);
238   void SetSlave(void) {IsSlave = true;}
239   
240 private:
241   FGModel* FirstModel;
242
243   bool frozen;
244   bool terminate;
245   int  Error;
246   unsigned int Frame;
247   unsigned int IdFDM;
248   static unsigned int FDMctr;
249   bool modelLoaded;
250   string modelName;
251   bool IsSlave;
252   static FGPropertyManager *master;
253   FGPropertyManager *instance;
254   
255   struct slaveData {
256     FGFDMExec* exec;
257     string info;
258     double x, y, z;
259     double roll, pitch, yaw;
260     bool mated;
261
262     slaveData(void) {
263       info = "";
264       x = y = z = 0.0;
265       roll = pitch = yaw = 0.0;
266       mated = true;
267     }
268
269     ~slaveData(void) {
270       delete exec;
271     }
272   };
273
274   string AircraftPath;
275   string EnginePath;
276   string ControlPath;
277   
278   string CFGVersion;
279   string Release;
280
281   FGState*           State;
282   FGAtmosphere*      Atmosphere;
283   FGFCS*             FCS;
284   FGPropulsion*      Propulsion;
285   FGMassBalance*     MassBalance;
286   FGAerodynamics*    Aerodynamics;
287   FGInertial*        Inertial;
288   FGGroundReactions* GroundReactions;
289   FGAircraft*        Aircraft;
290   FGTranslation*     Translation;
291   FGRotation*        Rotation;
292   FGPosition*        Position;
293   FGAuxiliary*       Auxiliary;
294   FGOutput*          Output;
295   
296   FGInitialCondition* IC;
297   FGTrim *Trim;
298
299   vector <slaveData*> SlaveFDMList;
300
301   bool ReadMetrics(FGConfigFile*);
302   bool ReadSlave(FGConfigFile*);
303   bool ReadPropulsion(FGConfigFile*);
304   bool ReadFlightControls(FGConfigFile*);
305   bool ReadAerodynamics(FGConfigFile*);
306   bool ReadUndercarriage(FGConfigFile*);
307   bool ReadPrologue(FGConfigFile*);
308   bool ReadOutput(FGConfigFile*);
309
310   bool Allocate(void);
311   bool DeAllocate(void);
312   void Debug(int from);
313 };
314 }
315 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 #endif
317