<?xml version="1.0"?>

<!-- ####    Author: Markus Bulik, Gijs de Rooy                                                    #### -->
<!-- ####    This file is licenced under the terms of the GNU General Public Licence V2 or later   #### -->

<PropertyList>
  
  <!-- =============================================================== -->
  <!-- Legend (Parameters)                                             -->
  <!-- =============================================================== -->

	<!-- Kp: proportional gain</Kp   -->
	<!-- Ti: integrator time         -->
	<!-- Td: derivator time          -->
	<!-- u_min: minimum output clamp -->
	<!-- u_max: maximum output clamp -->


  <!-- =============================================================== -->
  <!-- aileron servo driver.                                           -->
  <!-- =============================================================== -->

	<filter>
		<name>SERVO-DRIVER:aileron</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>true-heading-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>nav1-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>wing-leveler</value>
					</equals>
				</or>
				<not><property>autopilot/locks/passive-mode</property></not>
			</condition>
		</enable>
		<input>/autopilot/internal/aileron-servo</input>
		<output>/controls/flight/aileron</output>
		<type>noise-spike</type>
		<max-rate-of-change>0.5</max-rate-of-change>
	</filter>

  <!-- =============================================================== -->
  <!-- elevator-trim servo drivers.                                    -->
  <!-- =============================================================== -->

	<filter>
		<name>SERVO-DRIVER:elevator-trim (altitude/vspeed)</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>altitude-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>agl-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>vertical-speed-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>gs1-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>pitch-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>aoa-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</or>
				<equals>
					<property>/gear/gear[0]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[1]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[2]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[3]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[4]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[5]/wow</property>
					<value>0.0</value>
				</equals>
				<not><property>autopilot/locks/passive-mode</property></not>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</input>
		<output>/controls/flight/elevator-trim</output>
		<type>noise-spike</type>
		<max-rate-of-change>0.5</max-rate-of-change>
	</filter>

  <!-- =============================================================== -->
  <!-- rudder servo driver.                                           -->
  <!-- =============================================================== -->

	<filter>
		<name>SERVO-DRIVER:rudder heading-bug</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>true-heading-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>wing-leveler</value>
					</equals>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>nav1-hold</value>
					</equals>
				</or>
				<not><property>autopilot/locks/passive-mode</property></not>
			</condition>
		</enable>
		<input>/autopilot/internal/rudder-servo</input>
		<output>/controls/flight/rudder</output>
		<type>noise-spike</type>
		<max-rate-of-change>0.08</max-rate-of-change>
	</filter>


  <!-- =============================================================== -->
  <!-- throttle servo driver.                                           -->
  <!-- =============================================================== -->

	<filter>
		<name>SERVO-DRIVER:throttle</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
		<enable>
			<condition>
				<or>
					<and>
						<equals>
							<property>/autopilot/locks/speed</property>
							<value>speed-with-throttle</value>
						</equals>
						<equals>
							<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
							<value>0</value>
						</equals>
					</and>
					<and>
						<equals>
							<property>/autopilot/locks/speed</property>
							<value>speed-with-throttle</value>
						</equals>
						<equals>
							<property>/autopilot/locks/altitude</property>
							<value>gs1-hold</value>
						</equals>
						<property>/instrumentation/nav[0]/gs-in-range</property>
						<equals>
							<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
							<value>1</value>
						</equals>
					</and>
					<and>
						<equals>
							<property>/autopilot/locks/speed</property>
							<value>speed-with-pitch-trim</value>
						</equals>
						<or>
							<equals>
								<property>/autopilot/locks/altitude</property>
								<value>vertical-speed-hold</value>
							</equals>
							<equals>
								<property>/autopilot/locks/altitude</property>
								<value>altitude-hold</value>
							</equals>
							<equals>
								<property>/autopilot/locks/altitude</property>
								<value>agl-hold</value>
							</equals>
							<equals>
								<property>/autopilot/locks/altitude</property>
								<value>gs1-hold</value>
							</equals>
						</or>
					</and>
				</or>
				<equals>
					<property>/gear/gear[0]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[1]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[2]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[3]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[4]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[5]/wow</property>
					<value>0.0</value>
				</equals>
			</condition>
		</enable>
		<input>/autopilot/internal/throttle-servo</input>
		<output>
			<property>/controls/engines/engine[0]/throttle</property>
			<property>/controls/engines/engine[1]/throttle</property>
			<property>/controls/engines/engine[2]/throttle</property>
			<property>/controls/engines/engine[3]/throttle</property>
		</output>
		<type>noise-spike</type>
		<max-rate-of-change>0.1</max-rate-of-change>
	</filter>


  <!-- =============================================================== -->
  <!-- filter for adjustment of elevator position.                     -->
  <!-- =============================================================== -->

	<filter>
		<name>elevator-adjust (altitude/vspeed)</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>altitude-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>agl-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>vertical-speed-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>gs1-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>pitch-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>aoa-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</or>
				<equals>
					<property>/gear/gear[0]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[1]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[2]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[3]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[4]/wow</property>
					<value>0.0</value>
				</equals>
				<equals>
					<property>/gear/gear[5]/wow</property>
					<value>0.0</value>
				</equals>
				<not><property>autopilot/locks/passive-mode</property></not>
			</condition>
		</enable>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<property>/autopilot/internal/elevator-position</property>
		</input>
		<output>/controls/flight/elevator</output>
	</filter>

  <!-- =============================================================== -->
  <!-- Pitch hold                                                      -->
  <!-- =============================================================== -->

	<pid-controller>
		<name>Pitch hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>pitch-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/orientation/pitch-deg</property>
			<scale>30.0</scale>
		</input>
		<reference>
			<property>/autopilot/settings/target-pitch-deg</property>
			<scale>30.0</scale>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>
	

  <!-- =============================================================== -->
  <!-- Angle of attack hold                                            -->
  <!-- =============================================================== -->

	<pid-controller>
		<name>AOA hold</name>
		<debug>false</debug>
		<enable>
			<property>/autopilot/locks/altitude</property>
			<value>aoa-hold</value>
		</enable>
		<input>
			<property>/orientation/alpha-deg</property>
			<scale>30.0</scale>
		</input>
		<reference>
			<property>/autopilot/settings/target-aoa-deg</property>
			<scale>30.0</scale>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>


  <!-- =============================================================== -->
  <!-- Altitude-/AGL hold.  2 stage cascade controller.                     -->
  <!-- =============================================================== -->

	<!-- Stage #1 sets target rate of climb based on diff between current alt -->
	<!-- and target AGL. -->
	<pi-simple-controller>
		<name>Altitude Hold (Altimeter based) Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>agl-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/altimeter/indicated-altitude-ft</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-altitude-agl-min-ft</property>
		</reference>
		<output>
			<property>/autopilot/internal/target-climb-rate-fps</property>
			<scale>0.6</scale>
		</output>
		<config>
			<Kp>/autopilot/internal/target-airspeed-factor-for-altitude-hold</Kp>
			<u_min>/autopilot/internal/target-climp-rate-fps-for-altitude-hold-clambed-min</u_min>
			<u_max>/autopilot/internal/target-climp-rate-fps-for-altitude-hold-clambed-max</u_max>
		</config>
	</pi-simple-controller>

	<!-- Stage #1 sets target rate of climb based on diff between current alt -->
	<!-- and target altitude. -->
	<pi-simple-controller>
		<name>Altitude Hold (Altimeter based) Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>altitude-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/altimeter/indicated-altitude-ft</property>
		</input>
		<reference>
			<property>/autopilot/settings/target-altitude-ft</property>
		</reference>
		<output>
			<property>/autopilot/internal/target-climb-rate-fps</property>
			<scale>0.6</scale>
		</output>
		<config>
			<Kp>/autopilot/internal/target-airspeed-factor-for-altitude-hold</Kp>
			<u_min>/autopilot/internal/target-climp-rate-fps-for-altitude-hold-clambed-min</u_min>
			<u_max>/autopilot/internal/target-climp-rate-fps-for-altitude-hold-clambed-max</u_max>
		</config>
	</pi-simple-controller>

	<!-- Stage #2 drives the elevator-trim to achieve the desired climb rate. -->
	<pid-controller>
		<name>Altitude Hold (Altimeter based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>altitude-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>agl-hold</value>
					</equals>
				</or>
				<not>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</not>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-climb-rate-fps</property>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>



  <!-- =============================================================== -->
  <!-- vertical speed hold                                             -->
  <!-- =============================================================== -->

	<!-- drives the elevator to achieve the desired climb rate -->
	<pid-controller>
		<name>Vertical Speed Hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>vertical-speed-hold</value>
				</equals>
				<not>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</not>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/internal/vertical-speed-fpm-clambed</property>
			<scale>0.0167</scale>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>


  <!-- =============================================================== -->
  <!-- Wing-level hold.                                                -->
  <!-- =============================================================== -->

	<!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->
	<pid-controller>
		<name>Wing Level Hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>wing-leveler</value>
					</equals>
					<equals>
						<property>/autopilot/internal/wing-leveler-hold-heading</property>
						<value>0</value>
					</equals>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0</reference>
		<output>
			<property>/autopilot/internal/aileron-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-clambed</Kp>
			<Ti>/autopilot/internal/target-ti-for-heading-hold</Ti>
			<Td>/autopilot/internal/target-td-for-heading-hold</Td>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.4</gamma>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<!-- Stage #2b drives the rudder in order to the actual roll. -->
	<pi-simple-controller>
		<name>Wing Level Hold - rudder</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>wing-leveler</value>
					</equals>
					<equals>
						<property>/autopilot/internal/wing-leveler-hold-heading</property>
						<value>0</value>
					</equals>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-rudder</Kp>
			<u_min>-0.4</u_min>
			<u_max>0.4</u_max>
		</config>
	</pi-simple-controller>


  <!-- =============================================================== -->
  <!-- Heading Bug Hold.  2 stage cascade controller.                  -->
  <!-- =============================================================== -->

	<!-- filter for creation of an airspeed dependent factor -->
	<filter>
		<name>Heading Bug Hold Filter</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<type>gain</type>
		<gain>/autopilot/internal/target-gain-airspeed-factor-for-heading-hold</gain>
		<input>/velocities/airspeed-kt</input>
		<output>/autopilot/internal/target-kp-airspeed-for-heading-hold</output>
	</filter>

	<!-- determine heading-error -->
	<filter>
		<name>heading bug error computer/normalizer</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<type>gain</type>
		<input>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>wing-leveler</value>
				</equals>
			</condition>
			<property>/autopilot/internal/wing-leveler-hold-heading-bug-deg</property>
			<offset>
				<property>/orientation/heading-magnetic-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<input>
			<property>/autopilot/settings/heading-bug-deg</property>
			<offset>
				<property>/orientation/heading-magnetic-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<output>/autopilot/internal/heading-bug-error-deg</output>
		<period>
			<min>-180</min>
			<max>180</max>
		</period>
		<gain>1.0</gain>
	</filter>

	<!-- clamp heading-error to avoid too heavy reaktions of the following controllers -->
	<filter>
		<name>heading bug error clamper</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<type>gain</type>
		<gain>1.0</gain>
		<input>/autopilot/internal/heading-bug-error-deg</input>
		<output>/autopilot/internal/heading-bug-error-deg-clamped</output>
		<min>-45.0</min>
		<max>45.0</max>
	</filter>

	<!-- Stage #1 sets target roll based on diff between current heading and heading bug. -->
	<pid-controller>
		<name>Heading Bug Hold Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/heading-bug-error-deg-clamped</property>
		</input>
		<reference>
			<value>0.0</value>
		</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-airspeed-for-heading-hold</Kp>
			<Ti>/autopilot/internal/target-ti-airspeed-for-heading-hold</Ti>
			<Td>0.00001</Td>
			<min>
				<property>/autopilot/internal/bank-limit-filtered</property>
				<scale>-1.0</scale>
			</min>
			<max>
				<property>/autopilot/internal/bank-limit-filtered</property>
			</max>
		</config>
	</pid-controller>

	<!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->
	<pid-controller>
		<name>Heading Bug Hold (DG based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-roll-deg</property>
		</reference>
		<output>
			<property>/autopilot/internal/aileron-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-clambed</Kp>
			<Ti>/autopilot/internal/target-ti-for-heading-hold</Ti>
			<Td>/autopilot/internal/target-td-for-heading-hold</Td>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.4</gamma>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<!-- Stage #2b drives the rudder in order to the actual roll. -->
	<pi-simple-controller>
		<name>Heading Bug Hold (DG based) Stage 3</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>dg-heading-hold</value>
					</equals>
					<and>
						<equals>
							<property>/autopilot/locks/heading</property>
							<value>wing-leveler</value>
						</equals>
						<equals>
							<property>/autopilot/internal/wing-leveler-hold-heading</property>
							<value>1</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-rudder</Kp>
			<u_min>-0.4</u_min>
			<u_max>0.4</u_max>
		</config>
	</pi-simple-controller>


  <!-- =============================================================== -->
  <!-- True Heading                                                    -->
  <!-- =============================================================== -->

	<!-- Stage #1 sets target roll based on diff between current heading -->
	<!-- and target heading. (stable over speed 190 kts) -->

	<!-- filter for creation of an airspeed dependent factor -->
	<filter>
		<name>True Heading Hold Filter</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<type>gain</type>
		<gain>/autopilot/internal/target-gain-airspeed-factor-for-heading-hold</gain>
		<input>/velocities/airspeed-kt</input>
		<output>/autopilot/internal/target-kp-airspeed-for-heading-hold</output>
	</filter>

	<!-- determine true-heading-error -->
	<filter>
		<name>true heading error computer/normalizer</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<type>gain</type>
		<input>
			<property>/autopilot/settings/true-heading-deg</property>
			<offset>
				<property>/orientation/track-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<output>/autopilot/internal/true-heading-error-deg</output>
		<period>
			<min>-180</min>
			<max>180</max>
		</period>
		<gain>1.0</gain>
	</filter>
	<!-- clamp heading-error to avoid too heavy reaktions of the following controllers -->
	<filter>
		<name>heading bug error clamper</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<type>gain</type>
		<gain>1.0</gain>
		<input>/autopilot/internal/true-heading-error-deg</input>
		<output>/autopilot/internal/true-heading-error-deg-clamped</output>
		<min>-45.0</min>
		<max>45.0</max>
	</filter>

	<!-- Stage #1 sets target roll based on diff between current heading -->
	<!-- and heading bug. -->
	<pid-controller>
		<name>True Heading Hold Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/true-heading-error-deg-clamped</property>
		</input>
		<reference>
			<value>0.0</value>
		</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-airspeed-for-heading-hold</Kp>
			<Ti>/autopilot/internal/target-ti-airspeed-for-heading-hold</Ti>
			<Td>0.00001</Td>
			<min>
				<property>/autopilot/internal/bank-limit-filtered</property>
				<scale>-1.0</scale>
			</min>
			<max>
				<property>/autopilot/internal/bank-limit-filtered</property>
			</max>
		</config>
	</pid-controller>

	<!-- Stage #2 drives the ailerons to achieve the desired roll deg. -->
	<pid-controller>
		<name>True Heading Hold (DG based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>
			<condition>
				<equals>
					<property>/autopilot/internal/route-manager-waypoint-near-by</property>
					<value>1</value>
				</equals>
			</condition>
			<value>0</value><!-- hold wing level -->
		</reference>
		<reference>
			<condition>
				<equals>
					<property>/autopilot/internal/route-manager-waypoint-near-by</property>
					<value>0</value>
				</equals>
			</condition>
			<property>/autopilot/internal/target-roll-deg</property>
		</reference>
		<output>
			<property>/autopilot/internal/aileron-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-clambed</Kp>
			<Ti>/autopilot/internal/target-ti-for-heading-hold</Ti>
			<Td>/autopilot/internal/target-td-for-heading-hold</Td>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.4</gamma>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<!-- Stage #2b drives the rudder in order to the actual roll. -->
	<pi-simple-controller>
		<name>True Heading Hold (DG based) Stage 3 - Airborne mode</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>true-heading-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-rudder</Kp>
			<u_min>-0.4</u_min>
			<u_max>0.4</u_max>
		</config>
	</pi-simple-controller>



  <!-- =============================================================== -->
  <!-- Nav1 hold.  2 stage cascade controller.                         -->
  <!-- =============================================================== -->

	<filter>
		<name>nav1 track error computer</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
			</condition>
		</enable>
		<type>gain</type>
		<input>
			<property>instrumentation/nav[0]/radials/target-auto-hdg-deg</property>
			<offset>
				<property>/orientation/track-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<output>autopilot/internal/nav1-track-error-deg</output>
		<period>
			<min>-180</min>
			<max>180</max>
		</period>
		<gain>1.0</gain>
	</filter>

	<!-- Stage #1 sets target roll based on diff between current heading -->
	<!-- and target heading. -->

	<pi-simple-controller>
		<name>Nav1 Hold Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/nav1-track-error-deg-magnified</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-nav1-hold-clambed</Kp>
			<min>
				<property>/autopilot/internal/bank-limit-filtered</property>
				<scale>-1.0</scale>
			</min>
			<max>
				<property>/autopilot/internal/bank-limit-filtered</property>
			</max>
		</config>
	</pi-simple-controller>

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

	<pid-controller>
		<name>Nav1 Hold Stage 2 - Airborne mode</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>nav1-hold</value>
					</equals>
					<not>
						<property>/gear/gear[0]/wow</property>
					</not>
					<not>
						<property>/gear/gear[1]/wow</property>
					</not>
					<not>
						<property>/gear/gear[2]/wow</property>
					</not>
					<not>
						<property>/gear/gear[3]/wow</property>
					</not>
					<not>
						<property>/gear/gear[4]/wow</property>
					</not>
					<not>
						<property>/gear/gear[5]/wow</property>
					</not>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>
			<!-- hold wing level ('smooting' behaviour at VOR-transition) -->
			<condition>
				<equals>
					<property>/autopilot/internal/VOR-near-by</property>
					<value>1</value>
				</equals>
			</condition>
			<property>/autopilot/internal/target-roll-deg-for-VOR-near-by</property>
		</reference>
		<reference>
			<condition>
				<equals>
					<property>/autopilot/internal/VOR-near-by</property>
					<value>0</value>
				</equals>
			</condition>
			<property>/autopilot/internal/target-roll-deg</property>
		</reference>
		<output>
			<property>/autopilot/internal/aileron-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-heading-hold-clambed</Kp>
			<Ti>/autopilot/internal/target-ti-for-heading-hold</Ti>
			<Td>/autopilot/internal/target-td-for-heading-hold</Td>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.4</gamma>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<pid-controller>
		<name>Nav1 Hold Stage 2 - Ground mode (hold wing level '0')</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
				<or>
					<property>/gear/gear[0]/wow</property>
					<property>/gear/gear[1]/wow</property>
					<property>/gear/gear[2]/wow</property>
					<property>/gear/gear[3]/wow</property>
					<property>/gear/gear[4]/wow</property>
				</or>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0</reference>
		<output>
			<property>/autopilot/internal/aileron-servo</property>
		</output>
		<config>
			<Kp>0.1</Kp>
			<Ti>100.0</Ti>
			<Td>0.0</Td>
			<u_min>-0.3</u_min>
			<u_max>0.3</u_max>

		</config>
	</pid-controller>

	<!-- Stage #2b drives the rudder in order to the actual roll. -->

	<pi-simple-controller>
		<name>Nav1 Hold Stage 3 - Airborne mode</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/autopilot/locks/heading</property>
						<value>nav1-hold</value>
					</equals>
					<not>
						<property>/gear/gear[0]/wow</property>
					</not>
					<not>
						<property>/gear/gear[1]/wow</property>
					</not>
					<not>
						<property>/gear/gear[2]/wow</property>
					</not>
					<not>
						<property>/gear/gear[3]/wow</property>
					</not>
					<not>
						<property>/gear/gear[4]/wow</property>
					</not>
					<not>
						<property>/gear/gear[5]/wow</property>
					</not>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>-0.0025</Kp>
			<u_min>-0.4</u_min>
			<u_max>0.4</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>Nav1 Hold Stage 3 (rudder) - Ground mode (stage 1)</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
				<or>
					<property>/gear/gear[0]/wow</property>
					<property>/gear/gear[1]/wow</property>
					<property>/gear/gear[2]/wow</property>
					<property>/gear/gear[3]/wow</property>
					<property>/gear/gear[4]/wow</property>
				</or>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/nav1-track-error-deg</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/nav1-stear-ground-mode-uncorrected</property>
		</output>
		<config>
			<Kp>0.00000003</Kp>
			<Ti>0.000001</Ti>
			<Td>1000.0</Td>
			<u_min>-100.0</u_min>
			<u_max>100.0</u_max>
		</config>
	</pid-controller>

	<pi-simple-controller>
		<name>Nav1 Hold Stage 3 (rudder) - Ground/Near mode - without nose-wheel steering (stage 2)</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
				<or>
					<property>/gear/gear[1]/wow</property>
					<property>/gear/gear[2]/wow</property>
					<property>/gear/gear[3]/wow</property>
					<property>/gear/gear[4]/wow</property>
				</or>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/nav1-stear-ground-mode-corrected</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>1.0</Kp>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pi-simple-controller>
	<pi-simple-controller>
		<name>Nav1 Hold Stage 3 (rudder) - Ground/Near mode - nose-wheel steering (stage 2)</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/heading</property>
					<value>nav1-hold</value>
				</equals>
				<property>/gear/gear[0]/wow</property>
			</condition>
		</enable>
		<input>
			<property>/autopilot/internal/nav1-stear-ground-mode-corrected</property>
		</input>
		<reference>0.0</reference>
		<output>
			<property>/autopilot/internal/rudder-servo</property>
		</output>
		<config>
			<Kp>1.0</Kp>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pi-simple-controller>



  <!-- =============================================================== -->
  <!-- Glideslope hold.                                                -->
  <!-- =============================================================== -->

	<!-- Airborne-mode: drives the elevator-trim to achieve the desired climb rate. -->

	<pid-controller>
		<name>Glideslope Hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>gs1-hold</value>
				</equals>
				<less-than-equals>
					<property>/autopilot/internal/nav1-pitch-deg-ground-mode</property>
					<value>0.0</value>
				</less-than-equals>
				<equals>
					<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
					<value>0</value>
				</equals>
				<not>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</not>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/internal/gs-rate-of-climb-near-far-filtered</property>
			<scale>1.0</scale>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>


	<!-- Near-Ground-mode: drives the elevator-trim to asure pitch hold -->

	<pid-controller>
		<name>Glideslope Hold: ground-mode fallback to pitch hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>gs1-hold</value>
				</equals>
				<property>/instrumentation/nav[0]/gs-in-range</property>
				<greater-than>
					<property>/autopilot/internal/nav1-pitch-deg-ground-mode</property>
					<value>0.0</value>
				</greater-than>
				<not>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</not>
				<and>
					<equals>
						<property>/gear/gear[0]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[3]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[4]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[5]/wow</property>
						<value>0.0</value>
					</equals>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/pitch-deg</property>
		</input>
		<reference>
			<property>/autopilot/internal/nav1-pitch-deg-ground-mode</property>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>-0.05</Kp>
			<Ti>10.0</Ti>
			<Td>0.0</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<!-- Near-Ground-mode: drives the throttle to asure vertical speed -->

	<pid-controller>
		<name>Glideslope Hold: ground-mode fallback to vertical speed hold with throttle</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>gs1-hold</value>
				</equals>
				<property>/instrumentation/nav[0]/gs-in-range</property>
				<equals>
					<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
					<value>1</value>
				</equals>
				<not>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
				</not>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/internal/nav1-vspeed-ground-mode-value</property>
			<scale>0.03</scale>
		</reference>
		<output>
           	<property>/autopilot/internal/throttle-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/nav1-kp-for-throttle-ground-mode</Kp>
			<Ti>400.0</Ti>
			<Td>0.4</Td>
			<u_min>0.0</u_min>
			<u_max>0.7</u_max>
		</config>
	</pid-controller>


  <!-- ==================================================================================== -->
  <!-- fallback for vertical-speed-hold/altitude-hold with speed-with-pitch-trim activated  -->
  <!-- ==================================================================================== -->

	<!-- fallback to 'vspeed with throttle' for alt-/vspeed-control if 'speed-with-pitch' and alt-/vspeed-hold is activated -->
	<pid-controller>
		<name>Glideslope Hold: ground-mode fallback to vertical speed hold with throttle</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/autopilot/locks/speed</property>
						<value>speed-with-pitch-trim</value>
					</equals>
					<or>
						<equals>
							<property>/autopilot/locks/altitude</property>
							<value>vertical-speed-hold</value>
						</equals>
						<equals>
							<property>/autopilot/locks/altitude</property>
							<value>altitude-hold</value>
						</equals>
						<equals>
							<property>/autopilot/locks/altitude</property>
							<value>agl-hold</value>
						</equals>
						<equals>
							<property>/autopilot/locks/altitude</property>
							<value>gs1-hold</value>
						</equals>
					</or>
					<equals>
						<property>/gear/gear[0]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[3]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[4]/wow</property>
						<value>0.0</value>
					</equals>
					<equals>
						<property>/gear/gear[5]/wow</property>
						<value>0.0</value>
					</equals>
				</and>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>vertical-speed-hold</value>
				</equals>
			</condition>
			<property>/autopilot/internal/vertical-speed-fpm-clambed</property>
			<scale>0.0167</scale>
		</reference>
		<reference>
			<condition>
				<or>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>altitude-hold</value>
					</equals>
					<equals>
						<property>/autopilot/locks/altitude</property>
						<value>agl-hold</value>
					</equals>
				</or>
			</condition>
			<property>/autopilot/internal/target-climb-rate-fps</property>
		</reference>
		<reference>
			<condition>
				<equals>
					<property>/autopilot/locks/altitude</property>
					<value>gs1-hold</value>
				</equals>
			</condition>
			<property>/autopilot/internal/gs-rate-of-climb-near-far-filtered</property>
			<scale>1.0</scale>
		</reference>
		<output>
	            <property>/autopilot/internal/throttle-servo</property>
		</output>
		<config>
			<Kp>0.005</Kp>
			<Ti>30.0</Ti>
			<Td>0.0</Td>
			<u_min>0.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>


  <!-- =============================================================== -->
  <!-- Speed with pitch                                                -->
  <!-- =============================================================== -->

	<!-- Step 1 - determine appropriate pitch (needed to clamp pitch within certain range) -->
	<pid-controller>
	        <name>Speed with Pitch (IAS)</name>
	        <debug>false</debug>
	        <enable>
			<condition>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-pitch-trim</value>
				</equals>
			</condition>
	        </enable>
	        <input>
			<condition>
				<equals>
					<property>/autopilot/settings/target-speed-mach</property>
					<value>0.0</value>
				</equals>
			</condition>
			<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
	        </input>
	        <input>
			<condition>
				<greater-than>
					<property>/autopilot/settings/target-speed-mach</property>
					<value>0.0</value>
				</greater-than>
			</condition>
			<property>/instrumentation/airspeed-indicator/indicated-mach</property>
			<scale>/autopilot/internal/speed-with-pitch-mach-scale-factor</scale>
	        </input>
	        <reference>
			<condition>
				<equals>
					<property>/autopilot/settings/target-speed-mach</property>
					<value>0</value>
				</equals>
			</condition>
			<property>/autopilot/settings/target-speed-kt</property>
	        </reference>
	        <reference>
			<condition>
				<greater-than>
					<property>/autopilot/settings/target-speed-mach</property>
					<value>0</value>
				</greater-than>
			</condition>
			<property>/autopilot/settings/target-speed-mach</property>
			<scale>/autopilot/internal/speed-with-pitch-mach-scale-factor</scale>
	        </reference>
		<output>
			<property>/autopilot/internal/speed-with-pitch-pitch-deg</property>
			<scale>0.3</scale>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-speed-with-pitch-hold</Kp>
			<Ti>100.0</Ti>
			<Td>0.0</Td>
			<u_min>/autopilot/internal/umin-for-speed-with-pitch-hold</u_min>
			<u_max>/autopilot/internal/umax-for-speed-with-pitch-hold</u_max>
		</config>
	</pid-controller>

	<filter>
		<name>Filter - speed with pitch</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
	        <enable>
			<condition>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-pitch-trim</value>
				</equals>
			</condition>
	        </enable>
		<input>/autopilot/internal/speed-with-pitch-pitch-deg</input>
		<output>/autopilot/internal/speed-with-pitch-pitch-deg-filtered</output>
		<type>noise-spike</type>
		<max-rate-of-change>0.5</max-rate-of-change>
	</filter>

	<!-- Step 2 - use pitch-hold-controller to operate the elevator-trim -->
	<pid-controller>
		<name>Pitch hold</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-pitch-trim</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/orientation/pitch-deg</property>
			<scale>30.0</scale>
		</input>
		<reference>
			<property>/autopilot/internal/speed-with-pitch-pitch-deg-filtered</property>
			<scale>30.0</scale>
		</reference>
		<output>
			<property>/autopilot/internal/elevator-trim-servo</property>
		</output>
		<config>
			<Kp>/autopilot/internal/target-kp-for-altitude-vspeed-hold</Kp>
			<Ti>/autopilot/internal/target-ti-for-altitude-vspeed-hold</Ti>
			<Td>/autopilot/internal/target-td-for-altitude-vspeed-hold</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

  <!-- =============================================================== -->
  <!-- Auto throttle                                                   -->
  <!-- =============================================================== -->

	<pid-controller>
		<name>Auto throttle Stage 1 (evaluate speed-error, amplifies the real speed-error with factor 2.0)</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
				<equals>
					<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
					<value>0</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
		</input>
		<reference>
			<property>/autopilot/settings/target-speed-kt</property>
		</reference>
		<output>
			<property>/autopilot/internal/speed-error-kt</property>
		</output>
		<config>
			<Kp>-2.0</Kp>
		        <Ti>30.0</Ti>
		        <Td>0.00001</Td>
			<u_min>-30</u_min>
			<u_max>30</u_max>
		</config>
	</pid-controller>
	<pid-controller>
	        <name>Auto throttle (IAS) Stage 2</name>
	        <debug>false</debug>
	        <enable>
			<condition>
				<equals>
					<property>/autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
				<equals>
					<property>/autopilot/internal/nav1-vspeed-ground-mode</property>
					<value>0</value>
				</equals>
			</condition>
	        </enable>
	        <input>
	            <property>/autopilot/internal/speed-error-kt</property>
	        </input>
	        <reference>
	            <value>0.0</value>
	        </reference>
	        <output>
	            <property>/autopilot/internal/throttle-servo</property>
	        </output>
	        <config>
	            <Kp>0.2</Kp>
	            <Ti>30.0</Ti>
	            <Td>0.00001</Td>
	            <u_min>0.02</u_min>
	            <u_max>1.0</u_max>
	        </config>
	</pid-controller>

</PropertyList>
