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