]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.h
fefe6cd37544e425e307af2c6402549e947b0796
[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:
83     - <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
87     - <b>0</b>: This requests JSBSim not to output any messages
88        whatsoever
89     - <b>1</b>: This value explicity requests the normal JSBSim
90        startup messages
91     - <b>2</b>: This value asks for a message to be printed out when
92        a class is instantiated
93     - <b>4</b>: When this value is set, a message is displayed when a
94        FGModel object executes its Run() method
95     - <b>8</b>: When this value is set, various runtime state variables
96        are printed out periodically
97     - <b>16</b>: When set various parameters are sanity checked and
98        a message is printed out when they go out of bounds
99
100     @author Jon S. Berndt
101     @version $Id$
102 */
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DECLARATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 class FGFDMExec : public FGJSBBase
109 {
110 public:
111
112   /// Default constructor
113   FGFDMExec(FGPropertyManager* root = 0);
114
115   /// Default destructor
116   ~FGFDMExec();
117
118   /** This routine places a model into the runlist at the specified rate. The
119       "rate" is not really a clock rate. It represents how many calls to the
120       FGFDMExec::Run() method must be made before the model is executed. A
121       value of 1 means that the model will be executed for each call to the
122       exec's Run() method. A value of 5 means that the model will only be
123       executed every 5th call to the exec's Run() method.
124       @param model A pointer to the model being scheduled.
125       @param rate The rate at which to execute the model as described above.
126       @return Currently returns 0 always. */
127   int  Schedule(FGModel* model, int rate);
128
129   /** This executes each scheduled model in succession.
130       @return true if successful, false if sim should be ended  */
131   bool Run(void);
132
133   /** Initializes the sim from the initial condition object and executes
134       each scheduled model without integrating i.e. dt=0.
135       @return true if successful
136        */
137   bool RunIC(void);
138
139   /// Freezes the sim
140   void Freeze(void) {frozen = true;}
141
142   /// Resumes the sim
143   void Resume(void) {frozen = false;}
144
145   /** Loads an aircraft model.
146       @param AircraftPath path to the aircraft directory. For instance:
147       "aircraft". Under aircraft, then, would be directories for various
148       modeled aircraft such as C172/, x15/, etc.
149       @param EnginePath path to the directory under which engine config
150       files are kept, for instance "engine"
151       @param model the name of the aircraft model itself. This file will
152       be looked for in the directory specified in the AircraftPath variable,
153       and in turn under the directory with the same name as the model. For
154       instance: "aircraft/x15/x15.xml"
155       @return true if successful*/
156   bool LoadModel(string AircraftPath, string EnginePath, string model);
157
158
159   /** Loads an aircraft model.  The paths to the aircraft and engine
160       config file directories must be set prior to calling this.  See
161       below.
162       @param model the name of the aircraft model itself. This file will
163       be looked for in the directory specified in the AircraftPath variable,
164       and in turn under the directory with the same name as the model. For
165       instance: "aircraft/x15/x15.xml"
166       @return true if successful*/
167   bool LoadModel(string model);
168
169
170   /** Sets the path to the engine config file directories.
171       @param path path to the directory under which engine config
172       files are kept, for instance "engine"
173   */
174   bool SetEnginePath(string path)   { EnginePath = path; return true; }
175
176   /** Sets the path to the aircraft config file directories.
177       @param path path to the aircraft directory. For instance:
178       "aircraft". Under aircraft, then, would be directories for various
179       modeled aircraft such as C172/, x15/, etc.
180   */
181   bool SetAircraftPath(string path) { AircraftPath = path; return true; }
182
183   /** Sets the path to the autopilot config file directories.
184       @param path path to the control directory. For instance:
185       "control".
186   */
187 //  bool SetControlPath(string path) { ControlPath = path; return true; }
188
189
190   /// @name Top-level executive State and Model retrieval mechanism
191   //@{
192   /// Returns the FGState pointer.
193   inline FGState* GetState(void)              {return State;}
194   /// Returns the FGAtmosphere pointer.
195   inline FGAtmosphere* GetAtmosphere(void)    {return Atmosphere;}
196   /// Returns the FGFCS pointer.
197   inline FGFCS* GetFCS(void)                  {return FCS;}
198   /// Returns the FGPropulsion pointer.
199   inline FGPropulsion* GetPropulsion(void)    {return Propulsion;}
200   /// Returns the FGAircraft pointer.
201   inline FGMassBalance* GetMassBalance(void)  {return MassBalance;}
202   /// Returns the FGAerodynamics pointer
203   inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
204   /// Returns the FGInertial pointer.
205   inline FGInertial* GetInertial(void)        {return Inertial;}
206   /// Returns the FGGroundReactions pointer.
207   inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
208   /// Returns the FGAircraft pointer.
209   inline FGAircraft* GetAircraft(void)        {return Aircraft;}
210   /// Returns the FGPropagate pointer.
211   inline FGPropagate* GetPropagate(void)        {return Propagate;}
212   /// Returns the FGAuxiliary pointer.
213   inline FGAuxiliary* GetAuxiliary(void)      {return Auxiliary;}
214   /// Returns the FGOutput pointer.
215   inline FGOutput* GetOutput(void)            {return Output;}
216   // Returns a pointer to the FGInitialCondition object
217   inline FGInitialCondition* GetIC(void)      {return IC;}
218   // Returns a pointer to the FGTrim object
219   FGTrim* GetTrim(void);
220   //@}
221
222   /// Retrieves the engine path.
223   inline string GetEnginePath(void)          {return EnginePath;}
224   /// Retrieves the aircraft path.
225   inline string GetAircraftPath(void)        {return AircraftPath;}
226 //  /// Retrieves the control path.
227 //  inline string GetControlPath(void)        {return ControlPath;}
228
229   string GetModelName(void) { return modelName; }
230
231   FGPropertyManager* GetPropertyManager(void);
232   vector <string> EnumerateFDMs(void);
233   void SetSlave(void) {IsSlave = true;}
234
235 private:
236   FGModel* FirstModel;
237
238   bool frozen;
239   bool terminate;
240   int  Error;
241   unsigned int Frame;
242   unsigned int IdFDM;
243   static unsigned int FDMctr;
244   bool modelLoaded;
245   string modelName;
246   bool IsSlave;
247   static FGPropertyManager *master;
248   FGPropertyManager *instance;
249
250   struct slaveData {
251     FGFDMExec* exec;
252     string info;
253     double x, y, z;
254     double roll, pitch, yaw;
255     bool mated;
256
257     slaveData(void) {
258       info = "";
259       x = y = z = 0.0;
260       roll = pitch = yaw = 0.0;
261       mated = true;
262     }
263
264     ~slaveData(void) {
265       delete exec;
266     }
267   };
268
269   string AircraftPath;
270   string EnginePath;
271 //  string ControlPath;
272
273   string CFGVersion;
274   string Release;
275
276   FGState*           State;
277   FGAtmosphere*      Atmosphere;
278   FGFCS*             FCS;
279   FGPropulsion*      Propulsion;
280   FGMassBalance*     MassBalance;
281   FGAerodynamics*    Aerodynamics;
282   FGInertial*        Inertial;
283   FGGroundReactions* GroundReactions;
284   FGAircraft*        Aircraft;
285   FGPropagate*       Propagate;
286   FGAuxiliary*       Auxiliary;
287   FGOutput*          Output;
288
289   FGInitialCondition* IC;
290   FGTrim *Trim;
291
292   vector <slaveData*> SlaveFDMList;
293
294   bool ReadMetrics(FGConfigFile*);
295   bool ReadSlave(FGConfigFile*);
296   bool ReadPropulsion(FGConfigFile*);
297   bool ReadFlightControls(FGConfigFile*);
298   bool ReadAerodynamics(FGConfigFile*);
299   bool ReadUndercarriage(FGConfigFile*);
300   bool ReadPrologue(FGConfigFile*);
301   bool ReadOutput(FGConfigFile*);
302
303   bool Allocate(void);
304   bool DeAllocate(void);
305   void Debug(int from);
306 };
307 }
308 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 #endif
310