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