-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
- Header: FGScript.h\r
- Author: Jon Berndt\r
- Date started: 12/21/2001\r
-\r
- ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) -------------\r
-\r
- This program is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License as published by the Free Software\r
- Foundation; either version 2 of the License, or (at your option) any later\r
- version.\r
-\r
- This program is distributed in the hope that it will be useful, but WITHOUT\r
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\r
- details.\r
-\r
- You should have received a copy of the GNU General Public License along with\r
- this program; if not, write to the Free Software Foundation, Inc., 59 Temple\r
- Place - Suite 330, Boston, MA 02111-1307, USA.\r
-\r
- Further information about the GNU General Public License can also be found on\r
- the world wide web at http://www.gnu.org.\r
-\r
-HISTORY\r
---------------------------------------------------------------------------------\r
-12/21/01 JSB Created\r
-\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-SENTRY\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-#ifndef FGSCRIPT_HEADER_H\r
-#define FGSCRIPT_HEADER_H\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-INCLUDES\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-#include "FGJSBBase.h"\r
-#include "FGState.h"\r
-#include "FGFDMExec.h"\r
-#include <vector>\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-DEFINITIONS\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-#define ID_FGSCRIPT "$Id$"\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-FORWARD DECLARATIONS\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-CLASS DOCUMENTATION\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-/** Encapsulates the JSBSim scripting capability.\r
- @author Jon S. Berndt\r
- @version $Id$\r
-\r
- <h4>Scripting support provided via FGScript.</h4>\r
-\r
- <p>There is simple scripting support provided in the FGScript\r
- class. Commands are specified using the <u>Simple Scripting\r
- Directives for JSBSim</u> (SSDJ). The script file is in XML\r
- format. A test condition (or conditions) can be set up in the\r
- script and when the condition evaluates to true, the specified\r
- action[s] is/are taken. A test condition can be <em>persistent</em>,\r
- meaning that if a test condition evaluates to true, then passes\r
- and evaluates to false, the condition is reset and may again be\r
- triggered. When the set of tests evaluates to true for a given\r
- condition, an item may be set to another value. This value might\r
- be a boolean, a value, or a delta value, and the change from the\r
- current value to the new value can be either via a step function,\r
- a ramp, or an exponential approach. The speed of a ramp or\r
- approach is specified via the time constant. Here is the format\r
- of the script file:</p>\r
-\r
- <pre><strong><?xml version="1.0"?>\r
- <runscript name="C172-01A">\r
-\r
- <!--\r
- This run is for testing C172 runs\r
- -->\r
-\r
- <use aircraft="c172">\r
- <use initialize="reset00">\r
-\r
- <run start="0.0" end="4.5" dt="0.05">\r
- <when>\r
- <parameter name="FG_TIME" comparison="ge" value="0.25">\r
- <parameter name="FG_TIME" comparison="le" value="0.50">\r
- <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"\r
- action="FG_STEP" persistent="false" tc ="0.25">\r
- </when>\r
- <when>\r
- <parameter name="FG_TIME" comparison="ge" value="0.5">\r
- <parameter name="FG_TIME" comparison="le" value="1.5">\r
- <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"\r
- action="FG_EXP" persistent="false" tc ="0.5">\r
- </when>\r
- <when>\r
- <parameter name="FG_TIME" comparison="ge" value="1.5">\r
- <parameter name="FG_TIME" comparison="le" value="2.5">\r
- <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"\r
- action="FG_RAMP" persistent="false" tc ="0.5">\r
- </when>\r
- </run>\r
-\r
- </runscript></strong></pre>\r
-\r
- <p>The first line must always be present. The second line\r
- identifies this file as a script file, and gives a descriptive\r
- name to the script file. Comments are next, delineated by the\r
- <!-- and --> symbols. The aircraft and initialization files\r
- to be used are specified in the "use" lines. Next,\r
- comes the "run" section, where the conditions are\r
- described in "when" clauses.</p>\r
-\r
-*/\r
-\r
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-CLASS DECLARATION\r
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
-\r
-class FGScript : public FGJSBBase\r
-{\r
-public:\r
- /// Default constructor\r
- FGScript(FGFDMExec* exec);\r
-\r
- /// Default destructor\r
- ~FGScript();\r
-\r
- /** Loads a script to drive JSBSim (usually in standalone mode).\r
- The language is the Simple Script Directives for JSBSim (SSDJ).\r
- @param script the filename (including path name, if any) for the script.\r
- @return true if successful */\r
- bool LoadScript(string script);\r
-\r
- /** This function is called each pass through the executive Run() method IF\r
- scripting is enabled. \r
- @return false if script should exit (i.e. if time limits are violated */\r
- bool RunScript(void);\r
-\r
-private:\r
- enum eAction {\r
- FG_RAMP = 1,\r
- FG_STEP = 2,\r
- FG_EXP = 3\r
- };\r
-\r
- enum eType {\r
- FG_VALUE = 1,\r
- FG_DELTA = 2,\r
- FG_BOOL = 3\r
- };\r
-\r
- struct condition {\r
- vector <eParam> TestParam;\r
- vector <eParam> SetParam;\r
- vector <double> TestValue;\r
- vector <double> SetValue;\r
- vector <string> Comparison;\r
- vector <double> TC;\r
- vector <bool> Persistent;\r
- vector <eAction> Action;\r
- vector <eType> Type;\r
- vector <bool> Triggered;\r
- vector <double> newValue;\r
- vector <double> OriginalValue;\r
- vector <double> StartTime;\r
- vector <double> EndTime;\r
-\r
- condition() {\r
- }\r
- };\r
-\r
- bool Scripted;\r
-\r
- string ScriptName;\r
- double StartTime;\r
- double EndTime;\r
- vector <struct condition> Conditions;\r
-\r
- FGFDMExec* FDMExec;\r
- FGState* State;\r
- void Debug(int from);\r
-};\r
-\r
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
-#endif\r
-\r
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ Header: FGScript.h
+ Author: Jon Berndt
+ Date started: 12/21/2001
+
+ ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) -------------
+
+ This program is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Further information about the GNU General Public License can also be found on
+ the world wide web at http://www.gnu.org.
+
+HISTORY
+--------------------------------------------------------------------------------
+12/21/01 JSB Created
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+SENTRY
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+#ifndef FGSCRIPT_HEADER_H
+#define FGSCRIPT_HEADER_H
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+INCLUDES
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+#include "FGJSBBase.h"
+#include "FGState.h"
+#include "FGFDMExec.h"
+#include <vector>
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+#define ID_FGSCRIPT "$Id$"
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+FORWARD DECLARATIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+namespace JSBSim {
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DOCUMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/** Encapsulates the JSBSim scripting capability.
+ <h4>Scripting support provided via FGScript.</h4>
+
+ <p>There is simple scripting support provided in the FGScript
+ class. Commands are specified using the <em>Simple Scripting
+ Directives for JSBSim</em> (SSDJ). The script file is in XML
+ format. A test condition (or conditions) can be set up in the
+ script and when the condition evaluates to true, the specified
+ action[s] is/are taken. A test condition can be <em>persistent</em>,
+ meaning that if a test condition evaluates to true, then passes
+ and evaluates to false, the condition is reset and may again be
+ triggered. When the set of tests evaluates to true for a given
+ condition, an item may be set to another value. This value might
+ be a boolean, a value, or a delta value, and the change from the
+ current value to the new value can be either via a step function,
+ a ramp, or an exponential approach. The speed of a ramp or
+ approach is specified via the time constant. Here is the format
+ of the script file:</p>
+
+ <pre><strong><?xml version="1.0"?>
+ <runscript name="C172-01A">
+
+ <!--
+ This run is for testing C172 runs
+ -->
+
+ <use aircraft="c172">
+ <use initialize="reset00">
+
+ <run start="0.0" end="4.5" dt="0.05">
+ <when>
+ <parameter name="FG_TIME" comparison="ge" value="0.25">
+ <parameter name="FG_TIME" comparison="le" value="0.50">
+ <set name="FG_AILERON_CMD" type="FG_VALUE" value="0.25"
+ action="FG_STEP" persistent="false" tc ="0.25">
+ </when>
+ <when>
+ <parameter name="FG_TIME" comparison="ge" value="0.5">
+ <parameter name="FG_TIME" comparison="le" value="1.5">
+ <set name="FG_AILERON_CMD" type="FG_DELTA" value="0.5"
+ action="FG_EXP" persistent="false" tc ="0.5">
+ </when>
+ <when>
+ <parameter name="FG_TIME" comparison="ge" value="1.5">
+ <parameter name="FG_TIME" comparison="le" value="2.5">
+ <set name="FG_RUDDER_CMD" type="FG_DELTA" value="0.5"
+ action="FG_RAMP" persistent="false" tc ="0.5">
+ </when>
+ </run>
+
+ </runscript></strong></pre>
+
+ <p>The first line must always be present. The second line
+ identifies this file as a script file, and gives a descriptive
+ name to the script file. Comments are next, delineated by the
+ <!-- and --> symbols. The aircraft and initialization files
+ to be used are specified in the "use" lines. Next,
+ comes the "run" section, where the conditions are
+ described in "when" clauses.</p>
+ @author Jon S. Berndt
+ @version "$Id$"
+
+*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS DECLARATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+class FGScript : public FGJSBBase
+{
+public:
+ /// Default constructor
+ FGScript(FGFDMExec* exec);
+
+ /// Default destructor
+ ~FGScript();
+
+ /** Loads a script to drive JSBSim (usually in standalone mode).
+ The language is the Simple Script Directives for JSBSim (SSDJ).
+ @param script the filename (including path name, if any) for the script.
+ @return true if successful */
+ bool LoadScript( string script );
+
+ /** This function is called each pass through the executive Run() method IF
+ scripting is enabled.
+ @return false if script should exit (i.e. if time limits are violated */
+ bool RunScript(void);
+
+private:
+ enum eAction {
+ FG_RAMP = 1,
+ FG_STEP = 2,
+ FG_EXP = 3
+ };
+
+ enum eType {
+ FG_VALUE = 1,
+ FG_DELTA = 2,
+ FG_BOOL = 3
+ };
+
+ struct condition {
+ vector <FGPropertyManager*> TestParam;
+ vector <FGPropertyManager*> SetParam;
+ vector <double> TestValue;
+ vector <double> SetValue;
+ vector <string> Comparison;
+ vector <double> TC;
+ vector <bool> Persistent;
+ vector <eAction> Action;
+ vector <eType> Type;
+ vector <bool> Triggered;
+ vector <double> newValue;
+ vector <double> OriginalValue;
+ vector <double> StartTime;
+ vector <double> EndTime;
+
+ condition() {
+ }
+ };
+
+ bool Scripted;
+
+ string ScriptName;
+ double StartTime;
+ double EndTime;
+ vector <struct condition> Conditions;
+
+ FGFDMExec* FDMExec;
+ FGState* State;
+ FGPropertyManager* PropertyManager;
+ void Debug(int from);
+};
+}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+#endif
+