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 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71 /** Encapsulates the JSBSim simulation executive.
74 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGFDMExec.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
76 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGFDMExec.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
79 @doc This class is the interface class through which all other simulation classes
80 are instantiated, initialized, and run. When integrated with FlightGear (or
81 other flight simulator) this class is typically instantiated by an interface
82 class on the simulator side.
84 When an aircraft model is loaded the config file is parsed and for each of the
85 sections of the config file (propulsion, flight control, etc.) the
86 corresponding "ReadXXX()" method is called. From within this method the
87 "Load()" method of that system is called (e.g. LoadFCS).
89 <h4>JSBSim Debugging Directives</h4>
91 This describes to any interested entity the debug level
92 requested by setting the JSBSIM_DEBUG environment variable.
93 The bitmasked value choices are as follows:<ol>
94 <li><b>unset</b>: In this case (the default) JSBSim would only print
95 out the normally expected messages, essentially echoing
96 the config files as they are read. If the environment
97 variable is not set, debug_lvl is set to 1 internally</li>
98 <li><b>0</b>: This requests JSBSim not to output any messages
100 <li><b>1</b>: This value explicity requests the normal JSBSim
101 startup messages</li>
102 <li><b>2</b>: This value asks for a message to be printed out when
103 a class is instantiated</li>
104 <li><b>4</b>: When this value is set, a message is displayed when a
105 FGModel object executes its Run() method</li>
106 <li><b>8</b>: When this value is set, various runtime state variables
107 are printed out periodically</li>
108 <li><b>16</b>: When set various parameters are sanity checked and
109 a message is printed out when they go out of bounds</li>
114 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
118 class FGFDMExec : public FGJSBBase
122 /// Default constructor
123 FGFDMExec(FGPropertyManager* root = 0);
125 /// Default destructor
128 /** This routine places a model into the runlist at the specified rate. The
129 "rate" is not really a clock rate. It represents how many calls to the
130 FGFDMExec::Run() method must be made before the model is executed. A
131 value of 1 means that the model will be executed for each call to the
132 exec's Run() method. A value of 5 means that the model will only be
133 executed every 5th call to the exec's Run() method.
134 @param model A pointer to the model being scheduled.
135 @param rate The rate at which to execute the model as described above.
136 @return Currently returns 0 always. */
137 int Schedule(FGModel* model, int rate);
139 /** This executes each scheduled model in succession.
140 @return true if successful, false if sim should be ended */
143 /** Initializes the sim from the initial condition object and executes
144 each scheduled model without integrating i.e. dt=0.
145 @return true if successful
150 void Freeze(void) {frozen = true;}
153 void Resume(void) {frozen = false;}
155 /** Loads an aircraft model.
156 @param AircraftPath path to the aircraft directory. For instance:
157 "aircraft". Under aircraft, then, would be directories for various
158 modeled aircraft such as C172/, x15/, etc.
159 @param EnginePath path to the directory under which engine config
160 files are kept, for instance "engine"
161 @param model the name of the aircraft model itself. This file will
162 be looked for in the directory specified in the AircraftPath variable,
163 and in turn under the directory with the same name as the model. For
164 instance: "aircraft/x15/x15.xml"
165 @return true if successful*/
166 bool LoadModel(string AircraftPath, string EnginePath, string model);
169 /** Loads an aircraft model. The paths to the aircraft and engine
170 config file directories must be set prior to calling this. See
172 @param model the name of the aircraft model itself. This file will
173 be looked for in the directory specified in the AircraftPath variable,
174 and in turn under the directory with the same name as the model. For
175 instance: "aircraft/x15/x15.xml"
176 @return true if successful*/
177 bool LoadModel(string model);
180 /** Sets the path to the engine config file directories.
181 @param EnginePath path to the directory under which engine config
182 files are kept, for instance "engine"
184 bool SetEnginePath(string path) { EnginePath = path; return true; }
186 /** Sets the path to the aircraft config file directories.
187 @param AircraftPath path to the aircraft directory. For instance:
188 "aircraft". Under aircraft, then, would be directories for various
189 modeled aircraft such as C172/, x15/, etc.
191 bool SetAircraftPath(string path) { AircraftPath = path; return true; }
193 /** Sets the path to the autopilot config file directories.
194 @param ControlPath path to the control directory. For instance:
197 bool SetControlPath(string path) { ControlPath = path; return true; }
200 /// @name Top-level executive State and Model retrieval mechanism
202 /// Returns the FGState pointer.
203 inline FGState* GetState(void) {return State;}
204 /// Returns the FGAtmosphere pointer.
205 inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
206 /// Returns the FGFCS pointer.
207 inline FGFCS* GetFCS(void) {return FCS;}
208 /// Returns the FGPropulsion pointer.
209 inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
210 /// Returns the FGAircraft pointer.
211 inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
212 /// Returns the FGAerodynamics pointer
213 inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
214 /// Returns the FGInertial pointer.
215 inline FGInertial* GetInertial(void) {return Inertial;}
216 /// Returns the FGGroundReactions pointer.
217 inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
218 /// Returns the FGAircraft pointer.
219 inline FGAircraft* GetAircraft(void) {return Aircraft;}
220 /// Returns the FGTranslation pointer.
221 inline FGTranslation* GetTranslation(void) {return Translation;}
222 /// Returns the FGRotation pointer.
223 inline FGRotation* GetRotation(void) {return Rotation;}
224 /// Returns the FGPosition pointer.
225 inline FGPosition* GetPosition(void) {return Position;}
226 /// Returns the FGAuxiliary pointer.
227 inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
228 /// Returns the FGOutput pointer.
229 inline FGOutput* GetOutput(void) {return Output;}
230 // Returns a pointer to the FGInitialCondition object
231 inline FGInitialCondition* GetIC(void) {return IC;}
232 // Returns a pointer to the FGTrim object
233 FGTrim* GetTrim(void);
236 /// Retrieves the engine path.
237 inline string GetEnginePath(void) {return EnginePath;}
238 /// Retrieves the aircraft path.
239 inline string GetAircraftPath(void) {return AircraftPath;}
240 /// Retrieves the control path.
241 inline string GetControlPath(void) {return ControlPath;}
243 string GetModelName(void) { return modelName; }
245 FGPropertyManager* GetPropertyManager(void);
246 vector <string> EnumerateFDMs(void);
247 void SetSlave(void) {IsSlave = true;}
257 static unsigned int FDMctr;
261 static FGPropertyManager *master;
262 FGPropertyManager *instance;
268 double roll, pitch, yaw;
274 roll = pitch = yaw = 0.0;
290 FGAtmosphere* Atmosphere;
292 FGPropulsion* Propulsion;
293 FGMassBalance* MassBalance;
294 FGAerodynamics* Aerodynamics;
295 FGInertial* Inertial;
296 FGGroundReactions* GroundReactions;
297 FGAircraft* Aircraft;
298 FGTranslation* Translation;
299 FGRotation* Rotation;
300 FGPosition* Position;
301 FGAuxiliary* Auxiliary;
304 FGInitialCondition* IC;
307 vector <slaveData*> SlaveFDMList;
309 bool ReadMetrics(FGConfigFile*);
310 bool ReadSlave(FGConfigFile*);
311 bool ReadPropulsion(FGConfigFile*);
312 bool ReadFlightControls(FGConfigFile*);
313 bool ReadAerodynamics(FGConfigFile*);
314 bool ReadUndercarriage(FGConfigFile*);
315 bool ReadPrologue(FGConfigFile*);
316 bool ReadOutput(FGConfigFile*);
319 bool DeAllocate(void);
320 void Debug(int from);
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%