]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGScript.h
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / FGScript.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  Header:       FGScript.h
3  Author:       Jon Berndt
4  Date started: 12/21/2001
5
6  ------------- Copyright (C) 2001  Jon S. Berndt (jsb@hal-pc.org) -------------
7
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
11  version.
12
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
16  details.
17
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.
21
22  Further information about the GNU General Public License can also be found on
23  the world wide web at http://www.gnu.org.
24
25 HISTORY
26 --------------------------------------------------------------------------------
27 12/21/01   JSB   Created
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33 #ifndef FGSCRIPT_HEADER_H
34 #define FGSCRIPT_HEADER_H
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGJSBBase.h"
41 #include "FGState.h"
42 #include "FGFDMExec.h"
43 #include <vector>
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 #define ID_FGSCRIPT "$Id$"
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 namespace JSBSim {
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 /** Encapsulates the JSBSim scripting capability.
62     <h4>Scripting support provided via FGScript.</h4>
63
64     <p>There is simple scripting support provided in the FGScript
65     class. Commands are specified using the <em>Simple Scripting
66     Directives for JSBSim</em> (SSDJ). The script file is in XML
67     format. A test condition (or conditions) can be set up in the
68     script and when the condition evaluates to true, the specified
69     action[s] is/are taken. A test condition can be <em>persistent</em>,
70     meaning that if a test condition evaluates to true, then passes
71     and evaluates to false, the condition is reset and may again be
72     triggered. When the set of tests evaluates to true for a given
73     condition, an item may be set to another value. This value might
74     be a boolean, a value, or a delta value, and the change from the
75     current value to the new value can be either via a step function,
76     a ramp, or an exponential approach. The speed of a ramp or
77     approach is specified via the time constant. Here is the format
78     of the script file:</p>
79
80     <pre><strong>&lt;?xml version=&quot;1.0&quot;?&gt;
81     &lt;runscript name=&quot;C172-01A&quot;&gt;
82
83     &lt;!--
84     This run is for testing C172 runs
85     --&gt;
86
87     &lt;use aircraft=&quot;c172&quot;&gt;
88     &lt;use initialize=&quot;reset00&quot;&gt;
89
90     &lt;run start=&quot;0.0&quot; end=&quot;4.5&quot; dt=&quot;0.05&quot;&gt;
91       &lt;when&gt;
92         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.25&quot;&gt;
93         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;0.50&quot;&gt;
94         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_VALUE&quot; value=&quot;0.25&quot;
95         action=&quot;FG_STEP&quot; persistent=&quot;false&quot; tc =&quot;0.25&quot;&gt;
96       &lt;/when&gt;
97       &lt;when&gt;
98         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.5&quot;&gt;
99         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;1.5&quot;&gt;
100         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;
101         action=&quot;FG_EXP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;
102       &lt;/when&gt;
103       &lt;when&gt;
104         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;1.5&quot;&gt;
105         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;2.5&quot;&gt;
106         &lt;set name=&quot;FG_RUDDER_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;
107         action=&quot;FG_RAMP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;
108       &lt;/when&gt;
109     &lt;/run&gt;
110
111     &lt;/runscript&gt;</strong></pre>
112
113     <p>The first line must always be present. The second line
114     identifies this file as a script file, and gives a descriptive
115     name to the script file. Comments are next, delineated by the
116     &lt;!-- and --&gt; symbols. The aircraft and initialization files
117     to be used are specified in the &quot;use&quot; lines. Next,
118     comes the &quot;run&quot; section, where the conditions are
119     described in &quot;when&quot; clauses.</p>
120     @author Jon S. Berndt
121     @version "$Id$"
122
123 */
124
125 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 CLASS DECLARATION
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
128
129 class FGScript : public FGJSBBase
130 {
131 public:
132   /// Default constructor
133   FGScript(FGFDMExec* exec);
134
135   /// Default destructor
136   ~FGScript();
137
138   /** Loads a script to drive JSBSim (usually in standalone mode).
139       The language is the Simple Script Directives for JSBSim (SSDJ).
140       @param script the filename (including path name, if any) for the script.
141       @return true if successful */
142   bool LoadScript( string script );
143
144   /** This function is called each pass through the executive Run() method IF
145       scripting is enabled. 
146       @return false if script should exit (i.e. if time limits are violated */
147   bool RunScript(void);
148
149 private:
150   enum eAction {
151     FG_RAMP  = 1,
152     FG_STEP  = 2,
153     FG_EXP   = 3
154   };
155
156   enum eType {
157     FG_VALUE = 1,
158     FG_DELTA = 2,
159     FG_BOOL  = 3
160   };
161
162   struct condition {
163     vector <FGPropertyManager*>  TestParam;
164     vector <FGPropertyManager*>  SetParam;
165     vector <double>  TestValue;
166     vector <double>  SetValue;
167     vector <string>  Comparison;
168     vector <double>  TC;
169     vector <bool>    Persistent;
170     vector <eAction> Action;
171     vector <eType>   Type;
172     vector <bool>    Triggered;
173     vector <double>  newValue;
174     vector <double>  OriginalValue;
175     vector <double>  StartTime;
176     vector <double>  EndTime;
177
178     condition() {
179     }
180   };
181
182   bool Scripted;
183
184   string  ScriptName;
185   double  StartTime;
186   double  EndTime;
187   vector <struct condition> Conditions;
188
189   FGFDMExec* FDMExec;
190   FGState* State;
191   FGPropertyManager* PropertyManager;
192   void Debug(int from);
193 };
194 }
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 #endif
197