]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFDMExec.h
046b2403f0a367697c787e6b56bed3598145f1f9
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
2  Header:       FGFDMExec.h\r
3  Author:       Jon Berndt\r
4  Date started: 11/17/98\r
5 \r
6  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------\r
7 \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
11  version.\r
12 \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
16  details.\r
17 \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
21 \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
24 \r
25 HISTORY\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
30                                    object and dt=0.\r
31 \r
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
33 SENTRY\r
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
35 \r
36 #ifndef FGFDMEXEC_HEADER_H\r
37 #define FGFDMEXEC_HEADER_H\r
38 \r
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
40 INCLUDES\r
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
42 \r
43 #ifdef FGFS\r
44 #  include <simgear/compiler.h>\r
45 #  ifdef FG_HAVE_STD_INCLUDES\r
46 #    include <vector>\r
47 #  else\r
48 #    include <vector.h>\r
49 #  endif\r
50 #else\r
51 #  include <vector>\r
52 #endif\r
53 \r
54 #include "FGModel.h"\r
55 #include "FGInitialCondition.h"\r
56 \r
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
58 DEFINITIONS\r
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
60 \r
61 #define ID_FDMEXEC "$Id$"\r
62 \r
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
64 FORWARD DECLARATIONS\r
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
66 \r
67 class FGState;\r
68 class FGAtmosphere;\r
69 class FGFCS;\r
70 class FGPropulsion;\r
71 class FGAircraft;\r
72 class FGTranslation;\r
73 class FGRotation;\r
74 class FGPosition;\r
75 class FGAuxiliary;\r
76 class FGOutput;\r
77 class FGInitialCondition;\r
78 \r
79 struct condition {\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
85   vector <float>   TC;\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
94 \r
95   condition() {\r
96   }\r
97 };\r
98 \r
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
100 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]\r
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
102 \r
103 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
104 CLASS DOCUMENTATION\r
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
106 \r
107 /** Encapsulates the JSBSim simulation executive.\r
108     @author Jon S. Berndt\r
109     @version $Id$\r
110 \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
115 \r
116     <h4>Scripting support provided in the Executive</h4>\r
117 \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
133 \r
134     <pre><strong>&lt;?xml version=&quot;1.0&quot;?&gt;\r
135     &lt;runscript name=&quot;C172-01A&quot;&gt;\r
136 \r
137     &lt;!--\r
138     This run is for testing C172 runs\r
139     --&gt;\r
140 \r
141     &lt;use aircraft=&quot;c172&quot;&gt;\r
142     &lt;use initialize=&quot;reset00&quot;&gt;\r
143 \r
144     &lt;run start=&quot;0.0&quot; end=&quot;4.5&quot; dt=&quot;0.05&quot;&gt;\r
145       &lt;when&gt;\r
146         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.25&quot;&gt;\r
147         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;0.50&quot;&gt;\r
148         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_VALUE&quot; value=&quot;0.25&quot;\r
149         action=&quot;FG_STEP&quot; persistent=&quot;false&quot; tc =&quot;0.25&quot;&gt;\r
150       &lt;/when&gt;\r
151       &lt;when&gt;\r
152         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.5&quot;&gt;\r
153         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;1.5&quot;&gt;\r
154         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;\r
155         action=&quot;FG_EXP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;\r
156       &lt;/when&gt;\r
157       &lt;when&gt;\r
158         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;1.5&quot;&gt;\r
159         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;2.5&quot;&gt;\r
160         &lt;set name=&quot;FG_RUDDER_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;\r
161         action=&quot;FG_RAMP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;\r
162       &lt;/when&gt;\r
163     &lt;/run&gt;\r
164 \r
165     &lt;/runscript&gt;</strong></pre>\r
166 \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     &lt;!-- and --&gt; symbols. The aircraft and initialization files\r
171     to be used are specified in the &quot;use&quot; lines. Next,\r
172     comes the &quot;run&quot; section, where the conditions are\r
173     described in &quot;when&quot; clauses.</p>\r
174 \r
175     <h4>JSBSim Debugging Directives</h4>\r
176 \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
185        whatsoever.</li>\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
194     </ol>\r
195 \r
196 */\r
197 \r
198 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
199 CLASS DECLARATION\r
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
201 \r
202 class FGFDMExec\r
203 {\r
204 public:\r
205   /// Default constructor\r
206   FGFDMExec(void);\r
207 \r
208   /// Default destructor\r
209   ~FGFDMExec();\r
210 \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
221 \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
225   bool Run(void);\r
226 \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
231        */\r
232   bool RunIC(FGInitialCondition *fgic);\r
233 \r
234   /// Freezes the sim\r
235   void Freeze(void) {frozen = true;}\r
236 \r
237   /// Resumes the sim\r
238   void Resume(void) {frozen = false;}\r
239 \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
252 \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
258 \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
262 \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
266 \r
267   /// @name Top-level executive State and Model retrieval mechanism\r
268   //@{\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
289   //@}\r
290 \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
295 \r
296 private:\r
297   FGModel* FirstModel;\r
298 \r
299   bool frozen;\r
300   bool terminate;\r
301   int  Error;\r
302   bool modelLoaded;\r
303   bool Scripted;\r
304 \r
305   string AircraftPath;\r
306   string EnginePath;\r
307   string ScriptPath;\r
308   string ScriptName;\r
309   float  StartTime;\r
310   float  EndTime;\r
311   vector <struct condition> Conditions;\r
312 \r
313   FGState*       State;\r
314   FGAtmosphere*  Atmosphere;\r
315   FGFCS*         FCS;\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
322   FGOutput*      Output;\r
323 \r
324   bool Allocate(void);\r
325   bool DeAllocate(void);\r
326   void Debug(void);\r
327 };\r
328 \r
329 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
330 #endif\r
331 \r