1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Date started: 12/21/2001
6 ------------- Copyright (C) 2001 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 --------------------------------------------------------------------------------
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 #ifndef FGSCRIPT_HEADER_H
34 #define FGSCRIPT_HEADER_H
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 #include "FGJSBBase.h"
42 #include "FGFDMExec.h"
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #define ID_FGSCRIPT "$Id$"
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /** Encapsulates the JSBSim scripting capability.
66 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGScript.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
68 @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGScript.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
71 <h4>Scripting support provided via FGScript.</h4>
73 <p>There is simple scripting support provided in the FGScript
74 class. Commands are specified using the <u>Simple Scripting
75 Directives for JSBSim</u> (SSDJ). The script file is in XML
76 format. A test condition (or conditions) can be set up in the
77 script and when the condition evaluates to true, the specified
78 action[s] is/are taken. A test condition can be <em>persistent</em>,
79 meaning that if a test condition evaluates to true, then passes
80 and evaluates to false, the condition is reset and may again be
81 triggered. When the set of tests evaluates to true for a given
82 condition, an item may be set to another value. This value might
83 be a boolean, a value, or a delta value, and the change from the
84 current value to the new value can be either via a step function,
85 a ramp, or an exponential approach. The speed of a ramp or
86 approach is specified via the time constant. Here is the format
87 of the script file:</p>
89 <pre><strong><?xml version="1.0"?>
90 <runscript name="C172-01A">
93 This run is for testing C172 runs
96 <use aircraft="c172">
97 <use initialize="reset00">
99 <run start="0.0" end="4.5" dt="0.05">
101 <parameter name="FG_TIME" comparison="ge" value="0.25">
102 <parameter name="FG_TIME" comparison="le" value="0.50">
103 <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"
104 action="FG_STEP" persistent="false" tc ="0.25">
107 <parameter name="FG_TIME" comparison="ge" value="0.5">
108 <parameter name="FG_TIME" comparison="le" value="1.5">
109 <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"
110 action="FG_EXP" persistent="false" tc ="0.5">
113 <parameter name="FG_TIME" comparison="ge" value="1.5">
114 <parameter name="FG_TIME" comparison="le" value="2.5">
115 <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"
116 action="FG_RAMP" persistent="false" tc ="0.5">
120 </runscript></strong></pre>
122 <p>The first line must always be present. The second line
123 identifies this file as a script file, and gives a descriptive
124 name to the script file. Comments are next, delineated by the
125 <!-- and --> symbols. The aircraft and initialization files
126 to be used are specified in the "use" lines. Next,
127 comes the "run" section, where the conditions are
128 described in "when" clauses.</p>
132 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
136 class FGScript : public FGJSBBase
139 /// Default constructor
140 FGScript(FGFDMExec* exec);
142 /// Default destructor
145 /** Loads a script to drive JSBSim (usually in standalone mode).
146 The language is the Simple Script Directives for JSBSim (SSDJ).
147 @param script the filename (including path name, if any) for the script.
148 @return true if successful */
149 bool LoadScript( string script );
151 /** This function is called each pass through the executive Run() method IF
152 scripting is enabled.
153 @return false if script should exit (i.e. if time limits are violated */
154 bool RunScript(void);
170 vector <FGPropertyManager*> TestParam;
171 vector <FGPropertyManager*> SetParam;
172 vector <double> TestValue;
173 vector <double> SetValue;
174 vector <string> Comparison;
176 vector <bool> Persistent;
177 vector <eAction> Action;
179 vector <bool> Triggered;
180 vector <double> newValue;
181 vector <double> OriginalValue;
182 vector <double> StartTime;
183 vector <double> EndTime;
194 vector <struct condition> Conditions;
198 FGPropertyManager* PropertyManager;
199 void Debug(int from);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%