]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.h
First commit of properties code. JSBSim now has a basic property tree all
[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 "FGInitialCondition.h"
45 #include "FGJSBBase.h"
46 #include "FGPropertyManager.h"
47
48 #include <vector>
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 DEFINITIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 #define ID_FDMEXEC "$Id$"
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 FORWARD DECLARATIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 class FGInitialCondition;
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS DOCUMENTATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 /** Encapsulates the JSBSim simulation executive.
70     @author Jon S. Berndt
71     @version $Id$
72
73     @doc This class is the interface class through which all other simulation classes
74     are instantiated, initialized, and run. When integrated with FlightGear (or
75     other flight simulator) this class is typically instantiated by an interface
76     class on the simulator side.
77
78     When an aircraft model is loaded the config file is parsed and for each of the
79     sections of the config file (propulsion, flight control, etc.) the
80     corresponding "ReadXXX()" method is called. From within this method the 
81     "Load()" method of that system is called (e.g. LoadFCS).
82
83     <h4>JSBSim Debugging Directives</h4>
84
85     This describes to any interested entity the debug level
86     requested by setting the JSBSIM_DEBUG environment variable.
87     The bitmasked value choices are as follows:<ol>
88     <li><b>unset</b>: In this case (the default) JSBSim would only print
89        out the normally expected messages, essentially echoing
90        the config files as they are read. If the environment
91        variable is not set, debug_lvl is set to 1 internally</li>
92     <li><b>0</b>: This requests JSBSim not to output any messages
93        whatsoever.</li>
94     <li><b>1</b>: This value explicity requests the normal JSBSim
95        startup messages</li>
96     <li><b>2</b>: This value asks for a message to be printed out when
97        a class is instantiated</li>
98     <li><b>4</b>: When this value is set, a message is displayed when a
99        FGModel object executes its Run() method</li>
100     <li><b>8</b>: When this value is set, various runtime state variables
101        are printed out periodically</li>
102     <li><b>16</b>: When set various parameters are sanity checked and
103        a message is printed out when they go out of bounds</li>
104     </ol>
105
106 */
107
108 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 CLASS DECLARATION
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
111
112 class FGFDMExec : public FGJSBBase
113 {
114 public:
115
116   
117   /// Default constructor
118   FGFDMExec(FGPropertyManager* root = 0);
119   
120   /// Default destructor
121   ~FGFDMExec();
122
123   /** This routine places a model into the runlist at the specified rate. The
124       "rate" is not really a clock rate. It represents how many calls to the
125       FGFDMExec::Run() method must be made before the model is executed. A
126       value of 1 means that the model will be executed for each call to the
127       exec's Run() method. A value of 5 means that the model will only be
128       executed every 5th call to the exec's Run() method.
129       @param model A pointer to the model being scheduled.
130       @param rate The rate at which to execute the model as described above.
131       @return Currently returns 0 always. */
132   int  Schedule(FGModel* model, int rate);
133
134   /** This executes each scheduled model in succession.
135       @return true if successful, false if sim should be ended  */
136   bool Run(void);
137
138   /** Initializes the sim with a set of initial conditions.
139       @param fgic A pointer to a filled out initial conditions class which
140       describes the desired initial conditions.
141       @return true if successful
142        */
143   bool RunIC(FGInitialCondition *fgic);
144
145   /// Freezes the sim
146   void Freeze(void) {frozen = true;}
147
148   /// Resumes the sim
149   void Resume(void) {frozen = false;}
150
151   /** Loads an aircraft model.
152       @param AircraftPath path to the aircraft directory. For instance:
153       "aircraft". Under aircraft, then, would be directories for various
154       modeled aircraft such as C172/, x15/, etc.
155       @param EnginePath path to the directory under which engine config
156       files are kept, for instance "engine"
157       @param model the name of the aircraft model itself. This file will
158       be looked for in the directory specified in the AircraftPath variable,
159       and in turn under the directory with the same name as the model. For
160       instance: "aircraft/x15/x15.xml"
161       @return true if successful*/
162   bool LoadModel(string AircraftPath, string EnginePath, string model);
163
164   bool SetEnginePath(string path)   {EnginePath = path; return true;}
165   bool SetAircraftPath(string path) {AircraftPath = path; return true;}
166
167   /// @name Top-level executive State and Model retrieval mechanism
168   //@{
169   /// Returns the FGState pointer.
170   inline FGState* GetState(void)              {return State;}
171   /// Returns the FGAtmosphere pointer.
172   inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
173   /// Returns the FGFCS pointer.
174   inline FGFCS* GetFCS(void)                  {return FCS;}
175   /// Returns the FGPropulsion pointer.
176   inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
177   /// Returns the FGAircraft pointer.
178   inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
179   /// Returns the FGAerodynamics pointer
180   inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
181   /// Returns the FGInertial pointer.
182   inline FGInertial* GetInertial(void)        {return Inertial;}
183   /// Returns the FGGroundReactions pointer.
184   inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
185   /// Returns the FGAircraft pointer.
186   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
187   /// Returns the FGTranslation pointer.
188   inline FGTranslation* GetTranslation(void)  {return Translation;}
189   /// Returns the FGRotation pointer.
190   inline FGRotation* GetRotation(void)        {return Rotation;}
191   /// Returns the FGPosition pointer.
192   inline FGPosition* GetPosition(void)        {return Position;}
193   /// Returns the FGAuxiliary pointer.
194   inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
195   /// Returns the FGOutput pointer.
196   inline FGOutput* GetOutput(void)            {return Output;}
197   //@}
198
199   /// Retrieves the engine path.
200   inline string GetEnginePath(void)          {return EnginePath;}
201   /// Retrieves the aircraft path.
202   inline string GetAircraftPath(void)        {return AircraftPath;}
203   
204   FGPropertyManager* GetPropertyManager(void);
205
206 private:
207   FGModel* FirstModel;
208
209   bool frozen;
210   bool terminate;
211   int  Error;
212   unsigned int Frame;
213   unsigned int IdFDM;
214   static unsigned int FDMctr;
215   bool modelLoaded;
216   
217   FGPropertyManager *master;
218   FGPropertyManager *instance;
219
220   string AircraftPath;
221   string EnginePath;
222   string CFGVersion;
223
224   FGState*           State;
225   FGAtmosphere*      Atmosphere;
226   FGFCS*             FCS;
227   FGPropulsion*      Propulsion;
228   FGMassBalance*     MassBalance;
229   FGAerodynamics*    Aerodynamics;
230   FGInertial*        Inertial;
231   FGGroundReactions* GroundReactions;
232   FGAircraft*        Aircraft;
233   FGTranslation*     Translation;
234   FGRotation*        Rotation;
235   FGPosition*        Position;
236   FGAuxiliary*       Auxiliary;
237   FGOutput*          Output;
238
239   bool ReadMetrics(FGConfigFile*);
240   bool ReadPropulsion(FGConfigFile*);
241   bool ReadFlightControls(FGConfigFile*);
242   bool ReadAerodynamics(FGConfigFile*);
243   bool ReadUndercarriage(FGConfigFile*);
244   bool ReadPrologue(FGConfigFile*);
245   bool ReadOutput(FGConfigFile*);
246
247   bool Allocate(void);
248   bool DeAllocate(void);
249   void Debug(int from);
250 };
251
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 #endif
254