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"
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_FDMEXEC "$Id$"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 class FGInitialCondition;
73 vector <eParam> TestParam;
74 vector <eParam> SetParam;
75 vector <float> TestValue;
76 vector <float> SetValue;
77 vector <string> Comparison;
79 vector <bool> Persistent;
80 vector <eAction> Action;
82 vector <bool> Triggered;
83 vector <float> newValue;
84 vector <float> OriginalValue;
85 vector <float> StartTime;
86 vector <float> EndTime;
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
100 /** Encapsulates the JSBSim simulation executive.
101 @author Jon S. Berndt
104 @doc This class is the interface class through which all other simulation classes
105 are instantiated, initialized, and run. When integrated with FlightGear (or
106 other flight simulator) this class is typically instantiated by an interface
107 class on the simulator side.
109 <h4>Scripting support provided in the Executive</h4>
111 <p>There is simple scripting support provided in the FGFDMExec
112 class. Commands are specified using the <u>Simple Scripting
113 Directives for JSBSim</u> (SSDJ). The script file is in XML
114 format. A test condition (or conditions) can be set up in the
115 script and when the condition evaluates to true, the specified
116 action[s] is/are taken. A test condition can be <em>persistent</em>,
117 meaning that if a test condition evaluates to true, then passes
118 and evaluates to false, the condition is reset and may again be
119 triggered. When the set of tests evaluates to true for a given
120 condition, an item may be set to another value. This value might
121 be a boolean, a value, or a delta value, and the change from the
122 current value to the new value can be either via a step function,
123 a ramp, or an exponential approach. The speed of a ramp or
124 approach is specified via the time constant. Here is the format
125 of the script file:</p>
127 <pre><strong><?xml version="1.0"?>
128 <runscript name="C172-01A">
131 This run is for testing C172 runs
134 <use aircraft="c172">
135 <use initialize="reset00">
137 <run start="0.0" end="4.5" dt="0.05">
139 <parameter name="FG_TIME" comparison="ge" value="0.25">
140 <parameter name="FG_TIME" comparison="le" value="0.50">
141 <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"
142 action="FG_STEP" persistent="false" tc ="0.25">
145 <parameter name="FG_TIME" comparison="ge" value="0.5">
146 <parameter name="FG_TIME" comparison="le" value="1.5">
147 <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"
148 action="FG_EXP" persistent="false" tc ="0.5">
151 <parameter name="FG_TIME" comparison="ge" value="1.5">
152 <parameter name="FG_TIME" comparison="le" value="2.5">
153 <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"
154 action="FG_RAMP" persistent="false" tc ="0.5">
158 </runscript></strong></pre>
160 <p>The first line must always be present. The second line
161 identifies this file as a script file, and gives a descriptive
162 name to the script file. Comments are next, delineated by the
163 <!-- and --> symbols. The aircraft and initialization files
164 to be used are specified in the "use" lines. Next,
165 comes the "run" section, where the conditions are
166 described in "when" clauses.</p>
168 <h4>JSBSim Debugging Directives</h4>
170 This describes to any interested entity the debug level
171 requested by setting the JSBSIM_DEBUG environment variable.
172 The bitmasked value choices are as follows:<ol>
173 <li><b>unset</b>: In this case (the default) JSBSim would only print
174 out the normally expected messages, essentially echoing
175 the config files as they are read. If the environment
176 variable is not set, debug_lvl is set to 1 internally</li>
177 <li><b>0</b>: This requests JSBSim not to output any messages
179 <li><b>1</b>: This value explicity requests the normal JSBSim
180 startup messages</li>
181 <li><b>2</b>: This value asks for a message to be printed out when
182 a class is instantiated</li>
183 <li><b>4</b>: When this value is set, a message is displayed when a
184 FGModel object executes its Run() method</li>
185 <li><b>8</b>: When this value is set, various runtime state variables
186 are printed out periodically</li>
187 <li><b>16</b>: When set various parameters are sanity checked and
188 a message is printed out when they go out of bounds</li>
193 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
200 /// Default constructor
203 /// Default destructor
206 /** This routine places a model into the runlist at the specified rate. The
207 "rate" is not really a clock rate. It represents how many calls to the
208 FGFDMExec::Run() method must be made before the model is executed. A
209 value of 1 means that the model will be executed for each call to the
210 exec's Run() method. A value of 5 means that the model will only be
211 executed every 5th call to the exec's Run() method.
212 @param model A pointer to the model being scheduled.
213 @param rate The rate at which to execute the model as described above.
214 @return Currently returns 0 always. */
215 int Schedule(FGModel* model, int rate);
217 /** This executes each scheduled model in succession, as well as running any
218 scripts which are loaded.
219 @return true if successful, false if sim should be ended */
222 /** Initializes the sim with a set of initial conditions.
223 @param fgic A pointer to a filled out initial conditions class which
224 describes the desired initial conditions.
225 @return true if successful
227 bool RunIC(FGInitialCondition *fgic);
230 void Freeze(void) {frozen = true;}
233 void Resume(void) {frozen = false;}
235 /** Loads an aircraft model.
236 @param AircraftPath path to the aircraft directory. For instance:
237 "aircraft". Under aircraft, then, would be directories for various
238 modeled aircraft such as C172/, x15/, etc.
239 @param EnginePath path to the directory under which engine config
240 files are kept, for instance "engine"
241 @param model the name of the aircraft model itself. This file will
242 be looked for in the directory specified in the AircraftPath variable,
243 and in turn under the directory with the same name as the model. For
244 instance: "aircraft/x15/x15.xml"
245 @return true if successful*/
246 bool LoadModel(string AircraftPath, string EnginePath, string model);
248 /** Loads a script to drive JSBSim (usually in standalone mode).
249 The language is the Simple Script Directives for JSBSim (SSDJ).
250 @param script the filename (including path name, if any) for the script.
251 @return true if successful */
252 bool LoadScript(string script);
254 /** This function is called each pass through the executive Run() method IF
255 scripting is enabled. */
256 void RunScript(void);
258 bool SetEnginePath(string path) {EnginePath = path; return true;}
259 bool SetAircraftPath(string path) {AircraftPath = path; return true;}
260 bool SetScriptPath(string path) {ScriptPath = path; return true;}
262 /// @name Top-level executive State and Model retrieval mechanism
264 /// Returns the FGState pointer.
265 inline FGState* GetState(void) {return State;}
266 /// Returns the FGAtmosphere pointer.
267 inline FGAtmosphere* GetAtmosphere(void) {return Atmosphere;}
268 /// Returns the FGFCS pointer.
269 inline FGFCS* GetFCS(void) {return FCS;}
270 /// Returns the FGPropulsion pointer.
271 inline FGPropulsion* GetPropulsion(void) {return Propulsion;}
272 /// Returns the FGAircraft pointer.
273 inline FGMassBalance* GetMassBalance(void) {return MassBalance;}
274 /// Returns the FGAerodynamics pointer
275 inline FGAerodynamics* GetAerodynamics(void){return Aerodynamics;}
276 /// Returns the FGInertial pointer.
277 inline FGInertial* GetInertial(void) {return Inertial;}
278 /// Returns the FGAircraft pointer.
279 inline FGAircraft* GetAircraft(void) {return Aircraft;}
280 /// Returns the FGTranslation pointer.
281 inline FGTranslation* GetTranslation(void) {return Translation;}
282 /// Returns the FGRotation pointer.
283 inline FGRotation* GetRotation(void) {return Rotation;}
284 /// Returns the FGPosition pointer.
285 inline FGPosition* GetPosition(void) {return Position;}
286 /// Returns the FGAuxiliary pointer.
287 inline FGAuxiliary* GetAuxiliary(void) {return Auxiliary;}
288 /// Returns the FGOutput pointer.
289 inline FGOutput* GetOutput(void) {return Output;}
292 /// Retrieves the engine path.
293 inline string GetEnginePath(void) {return EnginePath;}
294 /// Retrieves the aircraft path.
295 inline string GetAircraftPath(void) {return AircraftPath;}
313 vector <struct condition> Conditions;
316 FGAtmosphere* Atmosphere;
318 FGPropulsion* Propulsion;
319 FGMassBalance* MassBalance;
320 FGAerodynamics* Aerodynamics;
321 FGInertial* Inertial;
322 FGAircraft* Aircraft;
323 FGTranslation* Translation;
324 FGRotation* Rotation;
325 FGPosition* Position;
326 FGAuxiliary* Auxiliary;
330 bool DeAllocate(void);
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%