<?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="180 Degree turn in A6M2">

  <description>
    decrease throttle so boost shows -200mmHg, (22.05 inHg)
    and then start pushing the pitch lever gradually, carefully monitoring rpm and speed.
    while pushing the lever, the rpm decreases but the boost increases to -100mmHg(26.98 inHg), which means the pitch is increasing
    when the engine RPM drops to 1850 (1272 prop rpm), Zero's speed is stable at around 130 kt, the most fuel efficient speed.
    when you climb or in a combat, you need to bring the pitch lever back to 0 position.
    while you're flying at 1850 engine rpm (at full pitch), you cannot reach to the max speed even with full boost.

    This script starts the aircraft at altitude with engine at 2550 rpm and 36 inHg and runs out to 30 seconds.
    
    The script sets  an empircally chosen throttle value to give 22.05 inHg then decreases advance command to 1850 rpm.
    
    Since the piston engine model does not exibit the manifold pressure increase the throttle is set to 27 inHg to demonstrate the 130 knot cruise.

  </description>

  <use aircraft="A6M2-jsbsim" initialize="Resources/init_cruise"/> 

  <run start="0" end="90" dt="0.008333">

    <property value="100"> simulation/notify-time-trigger </property>

<!-- 

  altitude   mixture 

     12000   0.5
     10000   0.58
         0   1.0
-->

    <event name="Set engines running">
      <condition> simulation/sim-time-sec le 0.1 </condition>
      <set name="propulsion/set-running" value="-1"/>
      <set name="fcs/throttle-cmd-norm[0]" value=".979"/>
      <set name="fcs/mixture-cmd-norm[0]" value="0.5"/>
      <set name="fcs/advance-cmd-norm[0]" value="1.0"/>
      <set name="gear/gear-cmd-norm" value="0"/>
      <set name="gear/gear-pos-norm" value="0"/>
      <notify>
        <property>fcs/mixture-cmd-norm</property>
        <property>fcs/mixture-pos-norm</property>
      </notify>
    </event>


    <event name="Engage Pilot">
      <condition> simulation/sim-time-sec gt 1 </condition>
      <set name="ap/afcs/theta-trim-rad" value="-0.000"/>
      <set name="ap/afcs/psi-trim-rad" value="3.1415"/>
      <set name="ap/afcs/phi-trim-rad" value="0.0"/>
      <set name="ap/afcs/pitch-channel-active-norm" value="15"/>
      <set name="ap/afcs/yaw-channel-active-norm" value="10"/>
      <set name="ap/afcs/roll-channel-active-norm" value="20"/>
      <notify>
        <property>fcs/mixture-cmd-norm</property>
        <property>fcs/mixture-pos-norm</property>
      </notify>
    </event>

    <event name="Reduce Throttle">
      <condition> simulation/sim-time-sec gt 20 </condition>
      <set name="fcs/throttle-cmd-norm"  value="0.6"/>
      <notify/>
    </event>

    <event name="Reduce RPM">
      <condition> simulation/sim-time-sec gt 35 </condition>
      <set name="fcs/advance-cmd-norm[0]" value="0.05"/>
      <notify/>
    </event>

    <event name="Increase Throttle">
      <condition> simulation/sim-time-sec gt 45 </condition>
      <set name="fcs/throttle-cmd-norm"  value="0.72"/>
      <set name="ap/afcs/theta-trim-rad" value="-0.01"/>
      <notify/>
    </event>
<!--
    <event name="Roll Out">
      <condition>
       simulation/sim-time-sec gt 25
       attitude/psi-rad gt 3.14
      </condition>
      <set name="ap/afcs/theta-trim-rad" value="-0.095"/>
      <set name="ap/afcs/psi-trim-rad" value="0.0"/>
      <set name="ap/afcs/phi-trim-rad" value="0.0"/>
      <set name="ap/afcs/pitch-channel-active-norm" value="10"/>
      <set name="ap/afcs/yaw-channel-active-norm" value="0"/>
      <set name="ap/afcs/roll-channel-active-norm" value="20"/>
      <set name="fcs/elevator-cmd-norm"  value="-0.0"/>
      <set name="fcs/rudder-cmd-norm"  value="-0.00"/>
      <set name="ap/afcs/pitch-channel-active-norm" value="0"/>
      <notify/>
    </event>
-->

    <!--

      For "do_simple_trim" (Classic trim):
      0: Longitudinal
      1: Full
      2: Ground
      3: Pullup
      4: Custom
      5: Turn
      6: None
    <event name="Trim">
      <condition> simulation/sim-time-sec gt 0.1 </condition>
      <set name="simulation/do_simple_trim" value="0"/>
      <delay>5.0</delay>
      <notify>
        <property>propulsion/engine[0]/rpm</property>
        <property>propulsion/engine[0]/thrust-lbs</property>
        <property>propulsion/engine[0]/map-inhg</property>
        <property>position/h-agl-ft</property>
        <property>velocities/vc-kts</property>
        <property>attitude/phi-rad</property>
        <property>attitude/theta-rad</property>
        <property>attitude/psi-rad</property>
        <property>fcs/throttle-cmd-norm</property>
        <property>fcs/throttle-pos-norm</property>
        <property>fcs/mixture-cmd-norm</property>
        <property>fcs/mixture-pos-norm</property>
        <property>fcs/advance-cmd-norm</property>
        <property>fcs/advance-pos-norm</property>
      </notify>
    </event>
    -->

    <event name="Repeating Notify" persistent="true">
      <description>Output message at 5 second intervals</description>
      <notify>
        <property>propulsion/engine[0]/rpm</property>
        <property>propulsion/engine[0]/thrust-lbs</property>
        <property>propulsion/engine[0]/map-inhg</property>
        <property>fcs/left-aileron-pos-rad</property>
        <property>fcs/elevator-pos-rad</property>
        <property>fcs/rudder-pos-rad</property>
        <property>position/h-agl-ft</property>
        <property>velocities/vc-kts</property>
        <property>velocities/mach</property>
        <property>accelerations/n-pilot-z-norm</property>
        <property>aero/alpha-deg</property>
	<property>aero/beta-deg</property>
        <property>attitude/phi-rad</property>
        <property>attitude/theta-rad</property>
        <property>attitude/psi-rad</property>

      </notify>
      <condition> simulation/sim-time-sec >= simulation/notify-time-trigger </condition>
      <set name="simulation/notify-time-trigger" value="10" type="FG_DELTA"/>
    </event>

  </run>

</runscript>

