<?xml version="1.0"?>
 
<!-- 737 Autopilot Configuration -->

<!-- Each component is evaluated in the order specified.  You can make up -->
<!-- property names to pass the result of one component on to a subsequent -->
<!-- component. -->


<PropertyList>

  <!-- =============================================================== -->
  <!-- Heading Select Mode                                             -->
  <!-- =============================================================== -->
  <!-- Heading Select Mode. This is a 2 stage cascade controller.      -->
  <!-- Stage #1 sets target roll based on difference between current   -->
  <!-- magnetic heading and heading bug. Stage #2 drives the ailerons. -->

  <pid-controller>
    <name>Heading Select Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>heading-hold</value>
    </enable>
    <input>
      <prop>/autopilot/internal/fdm-heading-bug-error-deg</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>        <!-- proportional gain -->
      <beta>3.0</beta>     <!-- input value weighing factor -->
      <alpha>0.1</alpha>   <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>   <!-- input value weighing factor for -->
                           <!-- unfiltered derivative error -->
      <Ti>5.0</Ti>         <!-- integrator time -->
      <Td>0.000001</Td>    <!-- derivator time -->
      <u_min>-25.0</u_min> <!-- minimum output clamp -->
      <u_max>25.0</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->

  <pid-controller>
    <name>Heading Select Stage 2</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>heading-hold</value>
    </enable>
    <input>
      <prop>/orientation/roll-deg</prop>
    </input>
    <reference>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </reference>
    <output>
      <prop>/controls/flight/aileron</prop>
    </output>
    <config>
      <Kp>0.01</Kp>       <!-- proportional gain -->
      <beta>1.0</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>100.0</Ti>      <!-- integrator time -->
      <Td>0.000001</Td>      <!-- derivator time -->
      <u_min>-0.5</u_min> <!-- minimum output clamp -->
      <u_max>0.5</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- =============================================================== -->
  <!-- Nav[0] hold.                                                    -->
  <!-- =============================================================== -->
  <!-- Stage #1 sets target roll based on diff between current heading -->
  <!-- and the target heading, which comes from the radios code.       -->

  <pid-controller>
    <name>Nav0 Hold Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>nav0-hold</value>
    </enable>
    <input>
      <prop>/autopilot/internal/nav0-heading-error-deg</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>        <!-- proportional gain -->
      <beta>1.0</beta>     <!-- input value weighing factor -->
      <alpha>0.1</alpha>   <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>   <!-- input value weighing factor for -->
                           <!-- unfiltered derivative error -->
      <Ti>200.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>     <!-- derivator time -->
      <u_min>-20.0</u_min> <!-- minimum output clamp -->
      <u_max>20.0</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->

  <pid-controller>
    <name>Nav0 Hold Stage 2</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>nav0-hold</value>
    </enable>
    <input>
      <prop>/orientation/roll-deg</prop>
    </input>
    <reference>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </reference>
    <output>
      <prop>/controls/flight/aileron</prop>
    </output>
    <config>
      <Kp>0.01</Kp>        <!-- proportional gain -->
      <beta>1.0</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>100.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.5</u_min> <!-- minimum output clamp -->
      <u_max>0.5</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- =============================================================== -->
  <!-- Nav[1] hold.                                                    -->
  <!-- =============================================================== -->

  <!-- Stage #1 sets target roll based on diff between current heading -->
  <!-- and the target heading, which comes from the radios code.       -->

  <pid-controller>
    <name>Nav1 Hold Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>nav1-hold</value>
    </enable>
    <input>
      <prop>/autopilot/internal/nav1-heading-error-deg</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>        <!-- proportional gain -->
      <beta>1.0</beta>     <!-- input value weighing factor -->
      <alpha>0.1</alpha>   <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>   <!-- input value weighing factor for -->
                           <!-- unfiltered derivative error -->
      <Ti>200.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>     <!-- derivator time -->
      <u_min>-20.0</u_min> <!-- minimum output clamp -->
      <u_max>20.0</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->

  <pid-controller>
    <name>Nav1 Hold Stage 2</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/heading</prop>
      <value>nav1-hold</value>
    </enable>
    <input>
      <prop>/orientation/roll-deg</prop>
    </input>
    <reference>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </reference>
    <output>
      <prop>/controls/flight/aileron</prop>
    </output>
    <config>
      <Kp>0.01</Kp>        <!-- proportional gain -->
      <beta>1.0</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>100.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.5</u_min> <!-- minimum output clamp -->
      <u_max>0.5</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


 <!-- =============================================================== -->
 <!-- Altitude Hold Mode                                              -->
 <!-- =============================================================== -->


  <!-- Altitude hold.  This is a 2 stage cascade controller.          -->
  <!-- Stage #1 sets target rate of climb based on diff between       -->
  <!-- current alt and target altitude.  The 737 altitude hold mode   -->
  <!-- doesn't work like this.  This would more properly be called    -->
  <!-- "altitude seek mode".                                          -->

  <pid-controller>
    <name>Altitude Hold Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/altitude</prop>
      <value>altitude-hold</value>
    </enable>
    <input>
      <prop>/position/altitude-ft</prop>
    </input>
    <reference>
      <prop>/autopilot/settings/target-altitude-ft</prop>
    </reference>
    <output>
      <prop>/autopilot/internal/target-climb-rate-fpm</prop>
    </output>
    <config>
      <Kp>1.0</Kp>        <!-- proportional gain -->
      <beta>0.2</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>200.0</Ti>      <!-- integrator time -->
      <Td>0.0000001</Td>    <!-- derivator time -->
      <u_min>-2000.0</u_min> <!-- minimum output clamp -->
      <u_max>2000.0</u_max> <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- Stage #2 drives the elevator to achieve the desired climb rate. -->

  <pid-controller>
    <name>Altitude Hold Stage 2</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/altitude</prop>
      <value>altitude-hold</value>
    </enable>
    <input>
      <prop>/velocities/vertical-speed-fpm</prop>
    </input>
    <reference>
      <prop>/autopilot/internal/target-climb-rate-fpm</prop>
    </reference>
    <output>
      <prop>/controls/flight/elevator</prop>
    </output>
    <config>
      <Kp>-0.0005</Kp>    <!-- proportional gain -->
      <beta>0.2</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>60.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.2</u_min> <!-- minimum output clamp -->
      <u_max>0.2</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


  <!-- ========================================================= -->
  <!-- Nav[0] Glideslope hold.                                   -->
  <!-- ========================================================= -->
  <!--                                                           -->
  <!-- Drives the elevator to achieve the desired vertical       -->
  <!-- velocity as provided by the radio code.                   -->

  <pid-controller>
    <name>Glideslope Hold</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/altitude</prop>
      <value>gs0-hold</value>
    </enable>
    <input>
      <prop>/velocities/vertical-speed-fps</prop>
    </input>
    <reference>
      <prop>/instrumentation/nav[0]/gs-rate-of-climb</prop>
    </reference>
     <output>
      <prop>/controls/flight/elevator</prop>
    </output>
    <config>
      <Kp>-0.0005</Kp>    <!-- proportional gain -->
      <beta>0.4</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>120.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.2</u_min> <!-- minimum output clamp -->
      <u_max>0.1</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


  <!-- ========================================================= -->
  <!-- Nav[1] Glideslope hold.                                   -->
  <!-- ========================================================= -->
  <!--                                                           -->
  <!-- Drives the elevator to achieve the desired vertical       -->
  <!-- velocity as provided by the radio code.                   -->

  <pid-controller>
    <name>Nav[1] Glideslope Hold</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/altitude</prop>
      <value>gs1-hold</value>
    </enable>
    <input>
      <prop>/velocities/vertical-speed-fps</prop>
    </input>
    <reference>
      <prop>/instrumentation/nav[1]/gs-rate-of-climb</prop>
    </reference>
     <output>
      <prop>/controls/flight/elevator</prop>
    </output>
    <config>
      <Kp>-0.0005</Kp>    <!-- proportional gain -->
      <beta>0.4</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>120.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.2</u_min> <!-- minimum output clamp -->
      <u_max>0.1</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


 <!-- =============================================================== -->
 <!-- Autothrottle - Speed Hold Mode                                  -->
 <!-- =============================================================== -->

 <pid-controller>
    <name>Auto Throttle Speed Hold</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/speed</prop>
      <value>speed-with-throttle</value>
    </enable>
    <input>
      <prop>/velocities/airspeed-kt</prop>
    </input>
    <reference>
      <prop>/autopilot/settings/target-speed-kt</prop>
    </reference>
    <output>
      <prop>/controls/engines/engine[0]/throttle</prop>
      <prop>/controls/engines/engine[1]/throttle</prop>
    </output>
    <config>
      <Kp>0.01</Kp>       <!-- proportional gain -->
      <beta>1.0</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>100.0</Ti>      <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>0.0</u_min>  <!-- minimum output clamp -->
      <u_max>0.9</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


 <!-- =============================================================== -->
 <!-- Speed Hold with Pitch                                           -->
 <!-- =============================================================== -->
 
 <!-- Hold speed by varying pitch (Two stage cascading controller)    --> 

 <pid-controller>
    <name>Speed hold (vary pitch) Stage #1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/speed</prop>
      <value>speed-with-pitch</value>
    </enable>
    <input>
      <prop>/velocities/airspeed-kt</prop>
    </input>
    <reference>
      <prop>/autopilot/settings/target-speed-kt</prop>
    </reference>
    <output>
      <prop>/autopilot/settings/target-pitch-deg</prop>
    </output>
    <config>
      <Kp>-0.2</Kp>       <!-- proportional gain -->
      <beta>0.4</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>120.0</Ti>      <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-8.0</u_min> <!-- minimum output clamp -->
      <u_max>15.0</u_max> <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <pid-controller>
    <name>Speed hold (vary pitch) Stage #2</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/speed</prop>
      <value>speed-with-pitch</value>
    </enable>
    <input>
      <prop>/orientation/pitch-deg</prop>
    </input>
    <reference>
      <prop>/autopilot/settings/target-pitch-deg</prop>
    </reference>
    <output>
      <prop>/controls/flight/elevator</prop>
    </output>
    <config>
      <Kp>-0.0005</Kp>    <!-- proportional gain -->
      <beta>0.4</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>120.0</Ti>      <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.2</u_min> <!-- minimum output clamp -->
      <u_max>0.1</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>

  <!-- ========================================================= -->
  <!-- Vertical Speed Hold.                                      -->
  <!-- ========================================================= -->
  <!--                                                           -->
  <!-- Drives the elevator to achieve the desired vertical       -->
  <!-- velocity.                                                 -->

  <pid-controller>
    <name>Vertical Speed Hold</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/altitude</prop>
      <value>vert-speed-hold</value>
    </enable>
    <input>
      <prop>/velocities/vertical-speed-fpm</prop>
    </input>
    <reference>
      <prop>/autopilot/settings/vert-speed-fpm</prop>
    </reference>
     <output>
      <prop>/controls/flight/elevator</prop>
    </output>
    <config>
      <Kp>-0.0005</Kp>    <!-- proportional gain -->
      <beta>0.4</beta>    <!-- input value weighing factor -->
      <alpha>0.1</alpha>  <!-- low pass filter weighing factor -->
      <gamma>0.0</gamma>  <!-- input value weighing factor for -->
                          <!-- unfiltered derivative error -->
      <Ti>120.0</Ti>       <!-- integrator time -->
      <Td>0.00001</Td>    <!-- derivator time -->
      <u_min>-0.2</u_min> <!-- minimum output clamp -->
      <u_max>0.1</u_max>  <!-- maximum output clamp -->
    </config>
  </pid-controller>


</PropertyList>
