1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
4 Date started: 12/21/2001
\r
6 ------------- Copyright (C) 2001 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 12/21/01 JSB Created
\r
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
33 #ifndef FGSCRIPT_HEADER_H
\r
34 #define FGSCRIPT_HEADER_H
\r
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
40 #include "FGJSBBase.h"
\r
41 #include "FGState.h"
\r
42 #include "FGFDMExec.h"
\r
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
49 #define ID_FGSCRIPT "$Id$"
\r
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
52 FORWARD DECLARATIONS
\r
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
56 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
\r
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
63 /** Encapsulates the JSBSim scripting capability.
\r
64 @author Jon S. Berndt
\r
67 <h4>Scripting support provided via FGScript.</h4>
\r
69 <p>There is simple scripting support provided in the FGScript
\r
70 class. Commands are specified using the <u>Simple Scripting
\r
71 Directives for JSBSim</u> (SSDJ). The script file is in XML
\r
72 format. A test condition (or conditions) can be set up in the
\r
73 script and when the condition evaluates to true, the specified
\r
74 action[s] is/are taken. A test condition can be <em>persistent</em>,
\r
75 meaning that if a test condition evaluates to true, then passes
\r
76 and evaluates to false, the condition is reset and may again be
\r
77 triggered. When the set of tests evaluates to true for a given
\r
78 condition, an item may be set to another value. This value might
\r
79 be a boolean, a value, or a delta value, and the change from the
\r
80 current value to the new value can be either via a step function,
\r
81 a ramp, or an exponential approach. The speed of a ramp or
\r
82 approach is specified via the time constant. Here is the format
\r
83 of the script file:</p>
\r
85 <pre><strong><?xml version="1.0"?>
\r
86 <runscript name="C172-01A">
\r
89 This run is for testing C172 runs
\r
92 <use aircraft="c172">
\r
93 <use initialize="reset00">
\r
95 <run start="0.0" end="4.5" dt="0.05">
\r
97 <parameter name="FG_TIME" comparison="ge" value="0.25">
\r
98 <parameter name="FG_TIME" comparison="le" value="0.50">
\r
99 <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"
\r
100 action="FG_STEP" persistent="false" tc ="0.25">
\r
103 <parameter name="FG_TIME" comparison="ge" value="0.5">
\r
104 <parameter name="FG_TIME" comparison="le" value="1.5">
\r
105 <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"
\r
106 action="FG_EXP" persistent="false" tc ="0.5">
\r
109 <parameter name="FG_TIME" comparison="ge" value="1.5">
\r
110 <parameter name="FG_TIME" comparison="le" value="2.5">
\r
111 <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"
\r
112 action="FG_RAMP" persistent="false" tc ="0.5">
\r
116 </runscript></strong></pre>
\r
118 <p>The first line must always be present. The second line
\r
119 identifies this file as a script file, and gives a descriptive
\r
120 name to the script file. Comments are next, delineated by the
\r
121 <!-- and --> symbols. The aircraft and initialization files
\r
122 to be used are specified in the "use" lines. Next,
\r
123 comes the "run" section, where the conditions are
\r
124 described in "when" clauses.</p>
\r
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
132 class FGScript : public FGJSBBase
\r
135 /// Default constructor
\r
136 FGScript(FGFDMExec* exec);
\r
138 /// Default destructor
\r
141 /** Loads a script to drive JSBSim (usually in standalone mode).
\r
142 The language is the Simple Script Directives for JSBSim (SSDJ).
\r
143 @param script the filename (including path name, if any) for the script.
\r
144 @return true if successful */
\r
145 bool LoadScript(string script);
\r
147 /** This function is called each pass through the executive Run() method IF
\r
148 scripting is enabled.
\r
149 @return false if script should exit (i.e. if time limits are violated */
\r
150 bool RunScript(void);
\r
166 vector <eParam> TestParam;
\r
167 vector <eParam> SetParam;
\r
168 vector <double> TestValue;
\r
169 vector <double> SetValue;
\r
170 vector <string> Comparison;
\r
171 vector <double> TC;
\r
172 vector <bool> Persistent;
\r
173 vector <eAction> Action;
\r
174 vector <eType> Type;
\r
175 vector <bool> Triggered;
\r
176 vector <double> newValue;
\r
177 vector <double> OriginalValue;
\r
178 vector <double> StartTime;
\r
179 vector <double> EndTime;
\r
190 vector <struct condition> Conditions;
\r
192 FGFDMExec* FDMExec;
\r
194 void Debug(int from);
\r
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\r