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