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 "FGPropertyManager.h"
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 #define ID_FDMEXEC "$Id$"
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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.
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).
78 <h4>JSBSim Debugging Directives</h4>
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:<ol>
83 <li><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</li>
87 <li><b>0</b>: This requests JSBSim not to output any messages
89 <li><b>1</b>: This value explicity requests the normal JSBSim
91 <li><b>2</b>: This value asks for a message to be printed out when
92 a class is instantiated</li>
93 <li><b>4</b>: When this value is set, a message is displayed when a
94 FGModel object executes its Run() method</li>
95 <li><b>8</b>: When this value is set, various runtime state variables
96 are printed out periodically</li>
97 <li><b>16</b>: When set various parameters are sanity checked and
98 a message is printed out when they go out of bounds</li>
101 @author Jon S. Berndt
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109 class FGFDMExec : public FGJSBBase
113 /// Default constructor
114 FGFDMExec(FGPropertyManager* root = 0);
116 /// Default destructor
119 /** This routine places a model into the runlist at the specified rate. The
120 "rate" is not really a clock rate. It represents how many calls to the
121 FGFDMExec::Run() method must be made before the model is executed. A
122 value of 1 means that the model will be executed for each call to the
123 exec's Run() method. A value of 5 means that the model will only be
124 executed every 5th call to the exec's Run() method.
125 @param model A pointer to the model being scheduled.
126 @param rate The rate at which to execute the model as described above.
127 @return Currently returns 0 always. */
128 int Schedule(FGModel* model, int rate);
130 /** This executes each scheduled model in succession.
131 @return true if successful, false if sim should be ended */
134 /** Initializes the sim from the initial condition object and executes
135 each scheduled model without integrating i.e. dt=0.
136 @return true if successful
141 void Freeze(void) {frozen = true;}
144 void Resume(void) {frozen = false;}
146 /** Loads an aircraft model.
147 @param AircraftPath path to the aircraft directory. For instance:
148 "aircraft". Under aircraft, then, would be directories for various
149 modeled aircraft such as C172/, x15/, etc.
150 @param EnginePath path to the directory under which engine config
151 files are kept, for instance "engine"
152 @param model the name of the aircraft model itself. This file will
153 be looked for in the directory specified in the AircraftPath variable,
154 and in turn under the directory with the same name as the model. For
155 instance: "aircraft/x15/x15.xml"
156 @return true if successful*/
157 bool LoadModel(string AircraftPath, string EnginePath, string model);
160 /** Loads an aircraft model. The paths to the aircraft and engine
161 config file directories must be set prior to calling this. See
163 @param model the name of the aircraft model itself. This file will
164 be looked for in the directory specified in the AircraftPath variable,
165 and in turn under the directory with the same name as the model. For
166 instance: "aircraft/x15/x15.xml"
167 @return true if successful*/
168 bool LoadModel(string model);
171 /** Sets the path to the engine config file directories.
172 @param path path to the directory under which engine config
173 files are kept, for instance "engine"
175 bool SetEnginePath(string path) { EnginePath = path; return true; }
177 /** Sets the path to the aircraft config file directories.
178 @param path path to the aircraft directory. For instance:
179 "aircraft". Under aircraft, then, would be directories for various
180 modeled aircraft such as C172/, x15/, etc.
182 bool SetAircraftPath(string path) { AircraftPath = path; return true; }
184 /** Sets the path to the autopilot config file directories.
185 @param path path to the control directory. For instance:
188 bool SetControlPath(string path) { ControlPath = path; return true; }
191 /// @name Top-level executive State and Model retrieval mechanism
193 /// Returns the FGState pointer.
194 inline FGState* GetState(void) {return State;}
195 /// Returns the FGAtmosphere pointer.
196 inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
197 /// Returns the FGFCS pointer.
198 inline FGFCS* GetFCS(void) {return FCS;}
199 /// Returns the FGPropulsion pointer.
200 inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
201 /// Returns the FGAircraft pointer.
202 inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
203 /// Returns the FGAerodynamics pointer
204 inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
205 /// Returns the FGInertial pointer.
206 inline FGInertial* GetInertial(void) {return Inertial;}
207 /// Returns the FGGroundReactions pointer.
208 inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
209 /// Returns the FGAircraft pointer.
210 inline FGAircraft* GetAircraft(void) {return Aircraft;}
211 /// Returns the FGTranslation pointer.
212 inline FGTranslation* GetTranslation(void) {return Translation;}
213 /// Returns the FGRotation pointer.
214 inline FGRotation* GetRotation(void) {return Rotation;}
215 /// Returns the FGPosition pointer.
216 inline FGPosition* GetPosition(void) {return Position;}
217 /// Returns the FGAuxiliary pointer.
218 inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
219 /// Returns the FGOutput pointer.
220 inline FGOutput* GetOutput(void) {return Output;}
221 // Returns a pointer to the FGInitialCondition object
222 inline FGInitialCondition* GetIC(void) {return IC;}
223 // Returns a pointer to the FGTrim object
224 FGTrim* GetTrim(void);
227 /// Retrieves the engine path.
228 inline string GetEnginePath(void) {return EnginePath;}
229 /// Retrieves the aircraft path.
230 inline string GetAircraftPath(void) {return AircraftPath;}
231 /// Retrieves the control path.
232 inline string GetControlPath(void) {return ControlPath;}
234 string GetModelName(void) { return modelName; }
236 FGPropertyManager* GetPropertyManager(void);
237 vector <string> EnumerateFDMs(void);
238 void SetSlave(void) {IsSlave = true;}
248 static unsigned int FDMctr;
252 static FGPropertyManager *master;
253 FGPropertyManager *instance;
259 double roll, pitch, yaw;
265 roll = pitch = yaw = 0.0;
282 FGAtmosphere* Atmosphere;
284 FGPropulsion* Propulsion;
285 FGMassBalance* MassBalance;
286 FGAerodynamics* Aerodynamics;
287 FGInertial* Inertial;
288 FGGroundReactions* GroundReactions;
289 FGAircraft* Aircraft;
290 FGTranslation* Translation;
291 FGRotation* Rotation;
292 FGPosition* Position;
293 FGAuxiliary* Auxiliary;
296 FGInitialCondition* IC;
299 vector <slaveData*> SlaveFDMList;
301 bool ReadMetrics(FGConfigFile*);
302 bool ReadSlave(FGConfigFile*);
303 bool ReadPropulsion(FGConfigFile*);
304 bool ReadFlightControls(FGConfigFile*);
305 bool ReadAerodynamics(FGConfigFile*);
306 bool ReadUndercarriage(FGConfigFile*);
307 bool ReadPrologue(FGConfigFile*);
308 bool ReadOutput(FGConfigFile*);
311 bool DeAllocate(void);
312 void Debug(int from);
315 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%