]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGScript.h
Removed FGMatrix.* because it is no longer used by JSBSim.
[flightgear.git] / src / FDM / JSBSim / FGScript.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
2  Header:       FGScript.h\r
3  Author:       Jon Berndt\r
4  Date started: 12/21/2001\r
5 \r
6  ------------- Copyright (C) 2001  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 12/21/01   JSB   Created\r
28 \r
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
30 SENTRY\r
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
32 \r
33 #ifndef FGSCRIPT_HEADER_H\r
34 #define FGSCRIPT_HEADER_H\r
35 \r
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
37 INCLUDES\r
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
39 \r
40 #include "FGJSBBase.h"\r
41 #include "FGState.h"\r
42 #include "FGFDMExec.h"\r
43 #include <vector>\r
44 \r
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
46 DEFINITIONS\r
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
48 \r
49 #define ID_FGSCRIPT "$Id$"\r
50 \r
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
52 FORWARD DECLARATIONS\r
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
54 \r
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
56 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]\r
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
58 \r
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
60 CLASS DOCUMENTATION\r
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
62 \r
63 /** Encapsulates the JSBSim scripting capability.\r
64     @author Jon S. Berndt\r
65     @version $Id$\r
66 \r
67     <h4>Scripting support provided via FGScript.</h4>\r
68 \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
84 \r
85     <pre><strong>&lt;?xml version=&quot;1.0&quot;?&gt;\r
86     &lt;runscript name=&quot;C172-01A&quot;&gt;\r
87 \r
88     &lt;!--\r
89     This run is for testing C172 runs\r
90     --&gt;\r
91 \r
92     &lt;use aircraft=&quot;c172&quot;&gt;\r
93     &lt;use initialize=&quot;reset00&quot;&gt;\r
94 \r
95     &lt;run start=&quot;0.0&quot; end=&quot;4.5&quot; dt=&quot;0.05&quot;&gt;\r
96       &lt;when&gt;\r
97         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.25&quot;&gt;\r
98         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;0.50&quot;&gt;\r
99         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_VALUE&quot; value=&quot;0.25&quot;\r
100         action=&quot;FG_STEP&quot; persistent=&quot;false&quot; tc =&quot;0.25&quot;&gt;\r
101       &lt;/when&gt;\r
102       &lt;when&gt;\r
103         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;0.5&quot;&gt;\r
104         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;1.5&quot;&gt;\r
105         &lt;set name=&quot;FG_AILERON_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;\r
106         action=&quot;FG_EXP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;\r
107       &lt;/when&gt;\r
108       &lt;when&gt;\r
109         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;ge&quot; value=&quot;1.5&quot;&gt;\r
110         &lt;parameter name=&quot;FG_TIME&quot; comparison=&quot;le&quot; value=&quot;2.5&quot;&gt;\r
111         &lt;set name=&quot;FG_RUDDER_CMD&quot; type=&quot;FG_DELTA&quot; value=&quot;0.5&quot;\r
112         action=&quot;FG_RAMP&quot; persistent=&quot;false&quot; tc =&quot;0.5&quot;&gt;\r
113       &lt;/when&gt;\r
114     &lt;/run&gt;\r
115 \r
116     &lt;/runscript&gt;</strong></pre>\r
117 \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     &lt;!-- and --&gt; symbols. The aircraft and initialization files\r
122     to be used are specified in the &quot;use&quot; lines. Next,\r
123     comes the &quot;run&quot; section, where the conditions are\r
124     described in &quot;when&quot; clauses.</p>\r
125 \r
126 */\r
127 \r
128 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
129 CLASS DECLARATION\r
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
131 \r
132 class FGScript : public FGJSBBase\r
133 {\r
134 public:\r
135   /// Default constructor\r
136   FGScript(FGFDMExec* exec);\r
137 \r
138   /// Default destructor\r
139   ~FGScript();\r
140 \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
146 \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
151 \r
152 private:\r
153   enum eAction {\r
154     FG_RAMP  = 1,\r
155     FG_STEP  = 2,\r
156     FG_EXP   = 3\r
157   };\r
158 \r
159   enum eType {\r
160     FG_VALUE = 1,\r
161     FG_DELTA = 2,\r
162     FG_BOOL  = 3\r
163   };\r
164 \r
165   struct condition {\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
180 \r
181     condition() {\r
182     }\r
183   };\r
184 \r
185   bool Scripted;\r
186 \r
187   string  ScriptName;\r
188   double  StartTime;\r
189   double  EndTime;\r
190   vector <struct condition> Conditions;\r
191 \r
192   FGFDMExec* FDMExec;\r
193   FGState* State;\r
194   void Debug(int from);\r
195 };\r
196 \r
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
198 #endif\r
199 \r