1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
22 Further information about the GNU General Public License can also be found on
23 the world wide web at http://www.gnu.org.
26 --------------------------------------------------------------------------------
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
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 #ifndef FGFDMEXEC_HEADER_H
37 #define FGFDMEXEC_HEADER_H
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 #include "FGInitialCondition.h"
46 #include "FGJSBBase.h"
47 #include "FGGroundCallback.h"
48 #include "FGPropertyManager.h"
49 #include "FGPropagate.h"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 #define ID_FDMEXEC "$Id$"
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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.
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).
80 <h4>JSBSim Debugging Directives</h4>
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
91 - <b>1</b>: This value explicity requests the normal JSBSim
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
102 @author Jon S. Berndt
106 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
110 class FGFDMExec : public FGJSBBase
114 /// Default constructor
115 FGFDMExec(FGPropertyManager* root = 0);
117 /// Default destructor
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);
131 /** This executes each scheduled model in succession.
132 @return true if successful, false if sim should be ended */
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
142 void Freeze(void) {frozen = true;}
145 void Resume(void) {frozen = false;}
147 void SetGroundCallback(FGGroundCallback*);
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);
166 /** Loads an aircraft model. The paths to the aircraft and engine
167 config file directories must be set prior to calling this. See
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);
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"
183 bool SetEnginePath(string path) { EnginePath = path; return true; }
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.
190 bool SetAircraftPath(string path) { AircraftPath = path; return true; }
192 /** Sets the path to the autopilot config file directories.
193 @param path path to the control directory. For instance:
196 // bool SetControlPath(string path) { ControlPath = path; return true; }
199 /// @name Top-level executive State and Model retrieval mechanism
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);
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;}
240 string GetModelName(void) { return modelName; }
242 FGPropertyManager* GetPropertyManager(void);
243 vector <string> EnumerateFDMs(void);
244 void SetSlave(void) {IsSlave = true;}
254 static unsigned int FDMctr;
258 static FGPropertyManager *master;
259 FGPropertyManager *instance;
265 double roll, pitch, yaw;
271 roll = pitch = yaw = 0.0;
282 // string ControlPath;
288 FGAtmosphere* Atmosphere;
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;
301 FGInitialCondition* IC;
304 vector <slaveData*> SlaveFDMList;
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*);
316 bool DeAllocate(void);
317 void Debug(int from);
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%