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