<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://jsbsim.sf.net/JSBSimScript.xsl"?>
<runscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://jsbsim.sf.net/JSBSimScript.xsd"
    name="C310-01A takeoff run">
    
  <description>For testing autopilot capability</description>
  <use aircraft="c310" initialize="ellington"/>
  
  <run start="0.0" end="3600" dt="0.02">
  
    <event name="Start engine">
      <description>
        Start engine and set initial heading and waypoints, turn on heading-hold mode.
      </description>
      <condition>simulation/sim-time-sec  ge  0.25</condition>
      <set name="fcs/mixture-cmd-norm[0]" value="1"/>
      <set name="fcs/mixture-cmd-norm[1]" value="1"/>
      <set name="fcs/advance-cmd-norm[0]" value="1.0"/>
      <set name="fcs/advance-cmd-norm[1]" value="1.0"/>
      <set name="propulsion/magneto_cmd" value="3"/>
      <set name="fcs/throttle-cmd-norm[0]" value="1.0"/>
      <set name="fcs/throttle-cmd-norm[1]" value="1.0"/>
      <set name="propulsion/starter_cmd" value="1"/>
      <set name="ap/altitude_setpoint" action="FG_EXP" value="1000.0" tc="10.0"/>
      <set name="ap/attitude_hold" value="0"/>
      <set name="guidance/target_wp_latitude_rad" value="0.517238"/>
      <set name="guidance/target_wp_longitude_rad" value="-1.662727"/>
      <set name="ap/heading_setpoint" value="0"/>
      <set name="ap/heading-setpoint-select" value="0"/>
      <set name="ap/heading_hold" value="1"/>
      <set name="ap/active-waypoint" value="0"/>
      <notify/>
    </event>
    
    <event name="Set altitude for 1,000 ft.">
      <condition>velocities/vc-fps ge 145.0</condition>
      <set name="ap/altitude_hold" value="1"/>
      <notify/>
    </event>
    
    <event name="Raise landing gear">
      <condition>position/h-agl-ft  ge  40</condition>
      <set name="gear/gear-cmd-norm" value="0"/>
      <notify/>
    </event>
    
    <event name="Head to first waypoint">
      <description>
        Set heading hold to selected waypoint (setpoint) instead of
        previously specified heading when altitude surpasses 800 feet.
      </description>
      <condition>position/h-agl-ft  ge  800</condition>
      <set name="ap/heading-setpoint-select" value="1"/>
      <set name="ap/active-waypoint" value="1"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>
    
    <event name="Terminate">
      <description>
        When the aircraft arrives back at Ellington Field (fifth waypoint)
        then terminate the simulation.
      </description>
      <condition>
        guidance/wp-distance lt 100
        ap/active-waypoint eq 5
      </condition>
      <set name="simulation/terminate" value="1"/>
      <notify/>
    </event>

    <event name="Set last waypoint">
      <description>
        When the distance to the fourth waypoint (northeast end of Galveston
        Island) is less than 100 feet, then set the last waypoint
        (back to Ellington Field).
      </description>
      <condition>
        guidance/wp-distance lt 100
        ap/active-waypoint eq 4
      </condition>
      <set name="guidance/target_wp_latitude_rad" value="0.516512"/>
      <set name="guidance/target_wp_longitude_rad" value="-1.660922"/>
      <set name="ap/active-waypoint" value="5"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>

    <event name="Set fourth waypoint">
      <description>
        When the distance to the third waypoint (southwest end of Galveston
        Island) is less than 800 feet, then set the fourth waypoint
        (northeast end of Galveston Island).
      </description>
      <condition>
        guidance/wp-distance lt 800
        ap/active-waypoint eq 3
      </condition>
      <set name="guidance/target_wp_latitude_rad" value="0.511661"/>
      <set name="guidance/target_wp_longitude_rad" value="-1.653510"/>
      <set name="ap/active-waypoint" value="4"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>

    <event name="Set third waypoint">
      <description>
        When the distance to the second waypoint (Hobby Airport) is less than
        500 feet, then set the third waypoint.
      </description>
      <condition>
        guidance/wp-distance lt 500
        ap/active-waypoint eq 2
      </condition>
      <set name="guidance/target_wp_latitude_rad" value="0.507481"/>
      <set name="guidance/target_wp_longitude_rad" value="-1.660062"/>
      <set name="ap/active-waypoint" value="3"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>
    
    <event name="Set second waypoint">
      <description>
        When the distance to the first waypoint (Hobby Airport threshold) is less than
        700 feet, then set the second waypoint.
      </description>
      <condition>
        guidance/wp-distance lt 700
        ap/active-waypoint eq 1
      </condition>
      <set name="guidance/target_wp_latitude_rad" value="0.517533"/>
      <set name="guidance/target_wp_longitude_rad" value="-1.663076"/>
      <set name="ap/active-waypoint" value="2"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>
    
  </run>
</runscript>
