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