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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGInitialCondition.h"
45 #include "FGJSBBase.h"
46 #include "FGPropertyManager.h"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 #define ID_FDMEXEC "$Id$"
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 class FGInitialCondition;
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 /** Encapsulates the JSBSim simulation executive.
73 @doc This class is the interface class through which all other simulation classes
74 are instantiated, initialized, and run. When integrated with FlightGear (or
75 other flight simulator) this class is typically instantiated by an interface
76 class on the simulator side.
78 When an aircraft model is loaded the config file is parsed and for each of the
79 sections of the config file (propulsion, flight control, etc.) the
80 corresponding "ReadXXX()" method is called. From within this method the
81 "Load()" method of that system is called (e.g. LoadFCS).
83 <h4>JSBSim Debugging Directives</h4>
85 This describes to any interested entity the debug level
86 requested by setting the JSBSIM_DEBUG environment variable.
87 The bitmasked value choices are as follows:<ol>
88 <li><b>unset</b>: In this case (the default) JSBSim would only print
89 out the normally expected messages, essentially echoing
90 the config files as they are read. If the environment
91 variable is not set, debug_lvl is set to 1 internally</li>
92 <li><b>0</b>: This requests JSBSim not to output any messages
94 <li><b>1</b>: This value explicity requests the normal JSBSim
96 <li><b>2</b>: This value asks for a message to be printed out when
97 a class is instantiated</li>
98 <li><b>4</b>: When this value is set, a message is displayed when a
99 FGModel object executes its Run() method</li>
100 <li><b>8</b>: When this value is set, various runtime state variables
101 are printed out periodically</li>
102 <li><b>16</b>: When set various parameters are sanity checked and
103 a message is printed out when they go out of bounds</li>
108 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
112 class FGFDMExec : public FGJSBBase
116 /// Default constructor
117 FGFDMExec(FGPropertyManager* root = 0);
119 /// Default destructor
122 /** This routine places a model into the runlist at the specified rate. The
123 "rate" is not really a clock rate. It represents how many calls to the
124 FGFDMExec::Run() method must be made before the model is executed. A
125 value of 1 means that the model will be executed for each call to the
126 exec's Run() method. A value of 5 means that the model will only be
127 executed every 5th call to the exec's Run() method.
128 @param model A pointer to the model being scheduled.
129 @param rate The rate at which to execute the model as described above.
130 @return Currently returns 0 always. */
131 int Schedule(FGModel* model, int rate);
133 /** This executes each scheduled model in succession.
134 @return true if successful, false if sim should be ended */
137 /** Initializes the sim with a set of initial conditions.
138 @param fgic A pointer to a filled out initial conditions class which
139 describes the desired initial conditions.
140 @return true if successful
142 bool RunIC(FGInitialCondition *fgic);
145 void Freeze(void) {frozen = true;}
148 void Resume(void) {frozen = false;}
150 /** Loads an aircraft model.
151 @param AircraftPath path to the aircraft directory. For instance:
152 "aircraft". Under aircraft, then, would be directories for various
153 modeled aircraft such as C172/, x15/, etc.
154 @param EnginePath path to the directory under which engine config
155 files are kept, for instance "engine"
156 @param model the name of the aircraft model itself. This file will
157 be looked for in the directory specified in the AircraftPath variable,
158 and in turn under the directory with the same name as the model. For
159 instance: "aircraft/x15/x15.xml"
160 @return true if successful*/
161 bool LoadModel(string AircraftPath, string EnginePath, string model);
163 bool SetEnginePath(string path) {EnginePath = path; return true;}
164 bool SetAircraftPath(string path) {AircraftPath = path; return true;}
166 /// @name Top-level executive State and Model retrieval mechanism
168 /// Returns the FGState pointer.
169 inline FGState* GetState(void) {return State;}
170 /// Returns the FGAtmosphere pointer.
171 inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
172 /// Returns the FGFCS pointer.
173 inline FGFCS* GetFCS(void) {return FCS;}
174 /// Returns the FGPropulsion pointer.
175 inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
176 /// Returns the FGAircraft pointer.
177 inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
178 /// Returns the FGAerodynamics pointer
179 inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
180 /// Returns the FGInertial pointer.
181 inline FGInertial* GetInertial(void) {return Inertial;}
182 /// Returns the FGGroundReactions pointer.
183 inline FGGroundReactions* GetGroundReactions(void) {return GroundReactions;}
184 /// Returns the FGAircraft pointer.
185 inline FGAircraft* GetAircraft(void) {return Aircraft;}
186 /// Returns the FGTranslation pointer.
187 inline FGTranslation* GetTranslation(void) {return Translation;}
188 /// Returns the FGRotation pointer.
189 inline FGRotation* GetRotation(void) {return Rotation;}
190 /// Returns the FGPosition pointer.
191 inline FGPosition* GetPosition(void) {return Position;}
192 /// Returns the FGAuxiliary pointer.
193 inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
194 /// Returns the FGOutput pointer.
195 inline FGOutput* GetOutput(void) {return Output;}
198 /// Retrieves the engine path.
199 inline string GetEnginePath(void) {return EnginePath;}
200 /// Retrieves the aircraft path.
201 inline string GetAircraftPath(void) {return AircraftPath;}
203 FGPropertyManager* GetPropertyManager(void);
204 vector <string> EnumerateFDMs(void);
205 void SetSlave(void) {IsSlave = true;}
215 static unsigned int FDMctr;
218 static FGPropertyManager *master;
219 FGPropertyManager *instance;
225 double roll, pitch, yaw;
231 roll = pitch = yaw = 0.0;
245 FGAtmosphere* Atmosphere;
247 FGPropulsion* Propulsion;
248 FGMassBalance* MassBalance;
249 FGAerodynamics* Aerodynamics;
250 FGInertial* Inertial;
251 FGGroundReactions* GroundReactions;
252 FGAircraft* Aircraft;
253 FGTranslation* Translation;
254 FGRotation* Rotation;
255 FGPosition* Position;
256 FGAuxiliary* Auxiliary;
259 vector <slaveData*> SlaveFDMList;
261 bool ReadMetrics(FGConfigFile*);
262 bool ReadSlave(FGConfigFile*);
263 bool ReadPropulsion(FGConfigFile*);
264 bool ReadFlightControls(FGConfigFile*);
265 bool ReadAerodynamics(FGConfigFile*);
266 bool ReadUndercarriage(FGConfigFile*);
267 bool ReadPrologue(FGConfigFile*);
268 bool ReadOutput(FGConfigFile*);
270 void TransferState(int idx);
272 bool DeAllocate(void);
273 void Debug(int from);
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%