]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.h
Sync. w. JSBSim CVS.
[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 "FGGroundCallback.h"
48 #include "FGPropertyManager.h"
49 #include "FGPropagate.h"
50
51 #include <vector>
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 DEFINITIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 #define ID_FDMEXEC "$Id$"
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 FORWARD DECLARATIONS
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
63 namespace JSBSim {
64
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS DOCUMENTATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68
69 /** Encapsulates the JSBSim simulation executive.
70     This class is the interface class through which all other simulation classes
71     are instantiated, initialized, and run. When integrated with FlightGear (or
72     other flight simulator) this class is typically instantiated by an interface
73     class on the simulator side.
74
75     When an aircraft model is loaded the config file is parsed and for each of the
76     sections of the config file (propulsion, flight control, etc.) the
77     corresponding "ReadXXX()" method is called. From within this method the
78     "Load()" method of that system is called (e.g. LoadFCS).
79
80     <h4>JSBSim Debugging Directives</h4>
81
82     This describes to any interested entity the debug level
83     requested by setting the JSBSIM_DEBUG environment variable.
84     The bitmasked value choices are as follows:
85     - <b>unset</b>: In this case (the default) JSBSim would only print
86        out the normally expected messages, essentially echoing
87        the config files as they are read. If the environment
88        variable is not set, debug_lvl is set to 1 internally
89     - <b>0</b>: This requests JSBSim not to output any messages
90        whatsoever
91     - <b>1</b>: This value explicity requests the normal JSBSim
92        startup messages
93     - <b>2</b>: This value asks for a message to be printed out when
94        a class is instantiated
95     - <b>4</b>: When this value is set, a message is displayed when a
96        FGModel object executes its Run() method
97     - <b>8</b>: When this value is set, various runtime state variables
98        are printed out periodically
99     - <b>16</b>: When set various parameters are sanity checked and
100        a message is printed out when they go out of bounds
101
102     @author Jon S. Berndt
103     @version $Id$
104 */
105
106 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 CLASS DECLARATION
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109
110 class FGFDMExec : public FGJSBBase
111 {
112 public:
113
114   /// Default constructor
115   FGFDMExec(FGPropertyManager* root = 0);
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 from the initial condition object and executes
136       each scheduled model without integrating i.e. dt=0.
137       @return true if successful
138        */
139   bool RunIC(void);
140
141   /// Freezes the sim
142   void Freeze(void) {frozen = true;}
143
144   /// Resumes the sim
145   void Resume(void) {frozen = false;}
146
147   void SetGroundCallback(FGGroundCallback*);
148
149   /** Loads an aircraft model.
150       @param AircraftPath path to the aircraft directory. For instance:
151       "aircraft". Under aircraft, then, would be directories for various
152       modeled aircraft such as C172/, x15/, etc.
153       @param EnginePath path to the directory under which engine config
154       files are kept, for instance "engine"
155       @param model the name of the aircraft model itself. This file will
156       be looked for in the directory specified in the AircraftPath variable,
157       and in turn under the directory with the same name as the model. For
158       instance: "aircraft/x15/x15.xml"
159       @param addModelToPath set to true to add the model name to the
160       AircraftPath, defaults to true
161       @return true if successful*/
162   bool LoadModel(string AircraftPath, string EnginePath, string model,
163                  bool addModelToPath = true);
164
165
166   /** Loads an aircraft model.  The paths to the aircraft and engine
167       config file directories must be set prior to calling this.  See
168       below.
169       @param model the name of the aircraft model itself. This file will
170       be looked for in the directory specified in the AircraftPath variable,
171       and in turn under the directory with the same name as the model. For
172       instance: "aircraft/x15/x15.xml"
173       @param addModelToPath set to true to add the model name to the
174       AircraftPath, defaults to true
175       @return true if successful*/
176   bool LoadModel(string model, bool addModelToPath = true);
177
178
179   /** Sets the path to the engine config file directories.
180       @param path path to the directory under which engine config
181       files are kept, for instance "engine"
182   */
183   bool SetEnginePath(string path)   { EnginePath = path; return true; }
184
185   /** Sets the path to the aircraft config file directories.
186       @param path path to the aircraft directory. For instance:
187       "aircraft". Under aircraft, then, would be directories for various
188       modeled aircraft such as C172/, x15/, etc.
189   */
190   bool SetAircraftPath(string path) { AircraftPath = path; return true; }
191
192   /** Sets the path to the autopilot config file directories.
193       @param path path to the control directory. For instance:
194       "control".
195   */
196 //  bool SetControlPath(string path) { ControlPath = path; return true; }
197
198
199   /// @name Top-level executive State and Model retrieval mechanism
200   //@{
201   /// Returns the FGState pointer.
202   inline FGState* GetState(void)              {return State;}
203   /// Returns the FGAtmosphere pointer.
204   inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
205   /// Returns the FGFCS pointer.
206   inline FGFCS* GetFCS(void)                  {return FCS;}
207   /// Returns the FGGroundCallback pointer.
208   inline FGGroundCallback* GetGroundCallback(void) {return GroundCallback;}
209   /// Returns the FGPropulsion pointer.
210   inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
211   /// Returns the FGAircraft pointer.
212   inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
213   /// Returns the FGAerodynamics pointer
214   inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
215   /// Returns the FGInertial pointer.
216   inline FGInertial* GetInertial(void)        {return Inertial;}
217   /// Returns the FGGroundReactions pointer.
218   inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
219   /// Returns the FGAircraft pointer.
220   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
221   /// Returns the FGPropagate pointer.
222   inline FGPropagate* GetPropagate(void)      {return Propagate;}
223   /// Returns the FGAuxiliary pointer.
224   inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
225   /// Returns the FGOutput pointer.
226   inline FGOutput* GetOutput(void)            {return Output;}
227   // Returns a pointer to the FGInitialCondition object
228   inline FGInitialCondition* GetIC(void)      {return IC;}
229   // Returns a pointer to the FGTrim object
230   FGTrim* GetTrim(void);
231   //@}
232
233   /// Retrieves the engine path.
234   inline string GetEnginePath(void)          {return EnginePath;}
235   /// Retrieves the aircraft path.
236   inline string GetAircraftPath(void)        {return AircraftPath;}
237 //  /// Retrieves the control path.
238 //  inline string GetControlPath(void)        {return ControlPath;}
239
240   string GetModelName(void) { return modelName; }
241
242   FGPropertyManager* GetPropertyManager(void);
243   vector <string> EnumerateFDMs(void);
244   void SetSlave(void) {IsSlave = true;}
245
246 private:
247   FGModel* FirstModel;
248
249   bool frozen;
250   bool terminate;
251   int  Error;
252   unsigned int Frame;
253   unsigned int IdFDM;
254   static unsigned int FDMctr;
255   bool modelLoaded;
256   string modelName;
257   bool IsSlave;
258   static FGPropertyManager *master;
259   FGPropertyManager *instance;
260
261   struct slaveData {
262     FGFDMExec* exec;
263     string info;
264     double x, y, z;
265     double roll, pitch, yaw;
266     bool mated;
267
268     slaveData(void) {
269       info = "";
270       x = y = z = 0.0;
271       roll = pitch = yaw = 0.0;
272       mated = true;
273     }
274
275     ~slaveData(void) {
276       delete exec;
277     }
278   };
279
280   string AircraftPath;
281   string EnginePath;
282 //  string ControlPath;
283
284   string CFGVersion;
285   string Release;
286
287   FGState*           State;
288   FGAtmosphere*      Atmosphere;
289   FGFCS*             FCS;
290   FGGroundCallback*  GroundCallback;
291   FGPropulsion*      Propulsion;
292   FGMassBalance*     MassBalance;
293   FGAerodynamics*    Aerodynamics;
294   FGInertial*        Inertial;
295   FGGroundReactions* GroundReactions;
296   FGAircraft*        Aircraft;
297   FGPropagate*       Propagate;
298   FGAuxiliary*       Auxiliary;
299   FGOutput*          Output;
300
301   FGInitialCondition* IC;
302   FGTrim *Trim;
303
304   vector <slaveData*> SlaveFDMList;
305
306   bool ReadMetrics(FGConfigFile*);
307   bool ReadSlave(FGConfigFile*);
308   bool ReadPropulsion(FGConfigFile*);
309   bool ReadFlightControls(FGConfigFile*);
310   bool ReadAerodynamics(FGConfigFile*);
311   bool ReadUndercarriage(FGConfigFile*);
312   bool ReadPrologue(FGConfigFile*);
313   bool ReadOutput(FGConfigFile*);
314
315   bool Allocate(void);
316   bool DeAllocate(void);
317   void Debug(int from);
318 };
319 }
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 #endif
322