FGScript Class Reference

#include <FGScript.h>

Inherits FGJSBBase, and FGXMLFileRead.

List of all members.


Detailed Description

Scripting support provided via FGScript.

There is support for scripting provided in the FGScript class. Commands are specified using the Scripting Directives for JSBSim. The script file is in XML format. A test condition (or conditions) can be set up in an event in a script and when the condition evaluates to true, the specified action[s] is/are taken. An event can be persistent, meaning that at every time the test condition first evaluates to true (toggling from false to true) then the specified set actions take place. An event can also be defined to execute or evaluate continuously while the condition is true. When the set of tests evaluates to true for a given condition, an item may be set to another value. This value may be a value, or a delta value, and the change from the current value to the new value can be either via a step action, a ramp, or an exponential approach. The speed of a ramp or exponential approach is specified via the time constant. Here is an example illustrating the format of the script file:

<?xml version="1.0"?>
<runscript name="C172-01A takeoff run">
  <!--
    This run is for testing the C172 altitude hold autopilot
  -->

  <use aircraft="c172x"/>
  <use initialize="reset00"/>
  <run start="0.0" end="3000" dt="0.0083333">

    <event name="engine start">
      <notify/>
      <condition>
        sim-time-sec >= 0.25
      </condition>
      <set name="fcs/throttle-cmd-norm" value="1.0" action="FG_RAMP" tc ="0.5"/>
      <set name="fcs/mixture-cmd-norm" value="0.87" action="FG_RAMP" tc ="0.5"/>
      <set name="propulsion/magneto_cmd" value="3"/>
      <set name="propulsion/starter_cmd" value="1"/>
    </event>

    <event name="set heading hold">
      <!-- Set Heading when reach 5 ft -->
      <notify/>
      <condition>
        position/h-agl-ft >= 5
      </condition>
      <set name="ap/heading_setpoint" value="200"/>
      <set name="ap/attitude_hold" value="0"/>
      <set name="ap/heading_hold" value="1"/>
    </event>

    <event name="set autopilot">
      <!-- Set Autopilot for 20 ft -->
      <notify/>
      <condition>
        aero/qbar-psf >= 4
      </condition>
      <set name="ap/altitude_setpoint" value="100.0" action="FG_EXP" tc ="2.0"/>
      <set name="ap/altitude_hold" value="1"/>
      <set name="fcs/flap-cmd-norm" value=".33"/>
    </event>

    <event name="set autopilot 2" persistent="true">
      <!-- Set Autopilot for 6000 ft -->
      <notify/>
      <condition>
        aero/qbar-psf > 5
      </condition>
      <set name="ap/altitude_setpoint" value="6000.0"/>
    </event>

    <event name="Time Notify">
      <notify/>
      <condition> sim-time-sec >= 500 </condition>
    </event>

    <event name="Time Notify">
      <notify/>
      <condition> sim-time-sec >= 1000 </condition>
    </event>

  </run>

</runscript>

The first line must always be present - it identifies the file as an XML format file. 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 "event" clauses.

Author:
Jon S. Berndt
Version:
"$Id: FGScript.h,v 1.14 2009/03/25 12:02:49 jberndt Exp $"

Definition at line 168 of file FGScript.h.


Public Member Functions

 FGScript (FGFDMExec *exec)
 Default constructor.
bool LoadScript (string script)
 Loads a script to drive JSBSim (usually in standalone mode).
void ResetEvents (void)
bool RunScript (void)
 This function is called each pass through the executive Run() method IF scripting is enabled.
 ~FGScript ()
 Default destructor.

Classes

struct  event
struct  LocalProps

Member Function Documentation

bool LoadScript ( string  script  ) 

The language is the Script Directives for JSBSim.

Parameters:
script the filename (including path name, if any) for the script.
Returns:
true if successful

Definition at line 89 of file FGScript.cpp.

bool RunScript ( void   ) 

Returns:
false if script should exit (i.e. if time limits are violated

Definition at line 315 of file FGScript.cpp.


The documentation for this class was generated from the following files:

Generated on Tue May 26 00:55:12 2009 for JSBSim Flight Dynamics Model by  doxygen 1.5.5