<?xml version="1.0" ?>
<!-- Mirage 2000 autopilot; based on generic-autopilot with route manager and autothrottle based on the work of J. Davidson
	 Richard Harrison; April 2020.  -->
<PropertyList>

	<!-- =============================================================== -->
	<!-- Roll Axis Modes                                                 -->
	<!-- =============================================================== -->

	<!-- Wing level -->
	<pid-controller>
		<name>Wing Leveler</name>
		<debug>false</debug>
		<enable>
			<prop>autopilot/locks/heading</prop>
			<value>wing-leveler</value>
		</enable>
		<input>
			<prop>orientation/roll-deg</prop>
		</input>
		<reference>
			<prop>autopilot/settings/target-roll-deg</prop>
		</reference>
		<output>
			<prop>/controls/flight/SAS-roll</prop>
		</output>
		<config>
			<Kp>0.038</Kp>
			<beta>1</beta>
			<Ti>10</Ti>
			<Td>0.00000000001</Td>
			<u_min>-0.3</u_min>
			<u_max>0.3</u_max>
		</config>
	</pid-controller>

	<!-- Magnetic Heading hold -->
	<pi-simple-controller>
		<name>Heading Hold</name>
		<debug>false</debug>
		<enable>
			<prop>autopilot/locks/heading</prop>
			<value>dg-heading-hold</value>
		</enable>
		<input>
			<prop>orientation/heading-magnetic-deg</prop>
		</input>
		<reference>
			<prop>autopilot/settings/heading-bug-deg</prop>
		</reference>
		<output>
			<prop>autopilot/internal/target-roll-deg</prop>
		</output>
		<config>
			<Kp>4.2</Kp>
			<u_min>-46</u_min>
			<u_max>46</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>Heading Hold Stage #2</name>
		<debug>false</debug>
		<enable>
			<prop>autopilot/locks/heading</prop>
			<value>dg-heading-hold</value>
		</enable>
		<input>
			<prop>orientation/roll-deg</prop>
		</input>
		<reference>
			<prop>autopilot/internal/target-roll-deg</prop>
		</reference>
		<output>
			<prop>/controls/flight/SAS-roll</prop>
		</output>
		<config>
			<Kp>0.05</Kp>
			<Ti>1.411</Ti>
			<Td>0.3</Td>
			<u_min>-0.3</u_min>
			<u_max>0.3</u_max>
		</config>
	</pid-controller>

	<!-- route manager -->
	<filter>
		<name>Route waypoint error normalizer</name>
		<debug>false</debug>
		<enable>
			<property>autopilot/route-manager/active</property>
		</enable>
		<type>gain</type>
		<input>
			<property>autopilot/route-manager/wp/true-bearing-deg</property>
			<offset>
				<property>orientation/heading-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<output>autopilot/internal/waypoint-bearing-error-deg</output>
		<period>
			<min>-180</min>
			<max>180</max>
		</period>
		<gain>1.0</gain>
	</filter>

	<filter>
		<name>Route waypoint error normalizer</name>
		<debug>false</debug>
		<enable>
			<not>
				<property>autopilot/route-manager/active</property>
			</not>
		</enable>
		<type>gain</type>
		<input>
			<property>autopilot/settings/true-heading-deg</property>
			<offset>
				<property>orientation/heading-deg</property>
				<scale>-1.0</scale>
			</offset>
		</input>
		<output>autopilot/internal/waypoint-bearing-error-deg</output>
		<period>
			<min>-180</min>
			<max>180</max>
		</period>
		<gain>1.0</gain>
	</filter>

	<pi-simple-controller>
		<name>Heading Route</name>
		<debug>false</debug>
		<enable>
			<prop>autopilot/locks/heading</prop>
			<value>true-heading-hold</value>
		</enable>
		<input>
			<property>autopilot/internal/waypoint-bearing-error-deg</property>
		</input>
		<reference>
			<value>0.0</value>
		</reference>
		<output>
			<prop>autopilot/internal/target-roll-deg</prop>
		</output>
		<config>
			<Kp>-2.1</Kp>
			<u_min>-46</u_min>
			<u_max>46</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>Heading Route Stage #2</name>
		<debug>false</debug>
		<enable>
			<prop>autopilot/locks/heading</prop>
			<value>true-heading-hold</value>
		</enable>
		<input>
			<prop>orientation/roll-deg</prop>
		</input>
		<reference>
			<prop>autopilot/internal/target-roll-deg</prop>
		</reference>
		<output>
			<prop>/controls/flight/SAS-roll</prop>
		</output>
		<config>
			<Kp>0.05</Kp>
			<!-- <beta>0</beta> -->
			<Ti>1.411</Ti>
			<Td>0.3</Td>
			<u_min>-0.3</u_min>
			<u_max>0.3</u_max>
		</config>
	</pid-controller>


	<!-- =============================================================== -->
	<!-- Pitch Axis Modes                                                -->
	<!-- =============================================================== -->

	<!--Pitch Hold -->
	<pid-controller>
		<name>Pitch hold</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>pitch-hold</value>
		</enable>
		<input>
			<prop>/orientation/pitch-deg</prop>
		</input>
		<reference>
			<prop>/autopilot/settings/target-pitch-deg</prop>
		</reference>
		<output>
			<prop>fdm/jsbsim/systems/afcs/elevator-cmd-delta</prop>
		</output>
		<config>
			<Kp>0.23</Kp>
			<Ti>0.08</Ti>
			<Td>2.004</Td>
			<u_min>-0.6</u_min>
			<u_max>0.6</u_max>
		</config>
	</pid-controller>

	<!-- Simple angle of attack hold -->
	<pid-controller>
		<name>AOA hold</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>aoa-hold</value>
		</enable>
		<input>
			<prop>/orientation/alpha-indicated-deg</prop>
		</input>
		<reference>
			<prop>/autopilot/settings/target-aoa-deg</prop>
		</reference>
		<output>
			<prop>fdm/jsbsim/systems/afcs/elevator-cmd-delta</prop>
		</output>
		<config>
			<Kp>0.05</Kp>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.0</gamma>
			<Ti>0.5</Ti>
			<Td>0.00001</Td>
			<u_min>-1.0</u_min>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<!--Vertical Speed Hold-->
	<pid-controller>
		<name>Vertical Speed</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>vertical-speed-hold</value>
		</enable>
		<input>
			<prop>/velocities/vertical-speed-fps</prop>
		</input>
		<reference>
			<prop>/autopilot/settings/vertical-speed-fpm</prop>
			<scale>0.01667</scale>
		</reference>
		<output>
			<prop>fdm/jsbsim/systems/afcs/elevator-cmd-delta</prop>
		</output>
		<config>
			<Kp>
				<expression>
					<property>autopilot/internal/alt-kp</property>
				</expression>
			</Kp>
			<Ti>
				<expression>
					<property>autopilot/internal/alt-ti</property>
				</expression>
			</Ti>
			<Td>
				<expression>
					<property>autopilot/internal/alt-td</property>
				</expression>
			</Td>
			<!-- nose down -ve nose up +ve -->
			<u_min>-0.6</u_min>
			<u_max>0.6</u_max>
		</config>
	</pid-controller>

	<!-- Altitude hold. -->
	<filter>
		<name>Climb limit</name>
		<type>gain</type>
		<gain>
			<expression>
				<product>
					<value>0.1667</value>
					<table>
						<property>instrumentation/airspeed-indicator/indicated-speed-kt</property>
						<entry>
							<ind>180</ind>
							<dep>0</dep>
						</entry>
						<entry>
							<ind>240</ind>
							<dep>1</dep>
						</entry>
						<entry>
							<ind>800</ind>
							<dep>3</dep>
						</entry>

					</table>
				</product>
			</expression>
		</gain>
		<input>instrumentation/airspeed-indicator/indicated-speed-kt</input>
		<output>autopilot/internal/climb-limit-fps</output>
	</filter>


	<pi-simple-controller>
		<name>Altitude Hold (Altimeter based) Stage 1</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>altitude-hold</value>
		</enable>
		<input>
			<prop>/instrumentation/altimeter/indicated-altitude-ft</prop>
		</input>
		<reference>
			<prop>/autopilot/settings/target-altitude-ft</prop>
		</reference>
		<output>
			<prop>/autopilot/internal/target-climb-rate-fps</prop>
		</output>
		<config>
			<Kp>0.08</Kp>
			<u_min>
				<expression>
					<product>
						<value>-1</value>
						<property>autopilot/internal/climb-limit-fps</property>
					</product>
				</expression>
			</u_min>
			<u_max>
				<expression>
					<product>
						<value>1</value>
						<property>autopilot/internal/climb-limit-fps</property>
					</product>
				</expression>
			</u_max>
		</config>
	</pi-simple-controller>
	<!-- Altitude hold. -->
	<filter>
		<name>CG Adjustment - Kp</name>
		<type>gain</type>
		<gain>
			<expression>
				<table>
					<property>fdm/jsbsim/inertia/cg-x-in</property>
					<entry>
						<ind>419</ind>
						<dep>0.0036</dep>
					</entry>
					<entry>
						<ind>423</ind>
						<dep>0.0036</dep>
					</entry>
					<entry>
						<ind>426</ind>
						<dep>0.0013</dep>
					</entry>
				</table>
			</expression>
		</gain>
		<input>
			<expression>
				<value>1</value>
			</expression>
		</input>
		<output>autopilot/internal/alt-kp</output>
	</filter>
	<filter>
		<name>CG Adjustment - Ti</name>
		<type>gain</type>
		<gain>
			<expression>
				<table>
					<property>fdm/jsbsim/inertia/cg-x-in</property>
					<entry>
						<ind>419</ind>
						<dep>1.5215000000</dep>
					</entry>
					<entry>
						<ind>423</ind>
						<dep>1.5215000000</dep>
					</entry>
					<entry>
						<ind>426</ind>
						<dep>3.318</dep>
					</entry>
				</table>
			</expression>
		</gain>
		<input>
			<expression>
				<value>1</value>
			</expression>
		</input>
		<output>autopilot/internal/alt-ti</output>
	</filter>
	<filter>
		<name>CG Adjustment - td</name>
		<type>gain</type>
		<gain>
			<expression>
				<table>
					<property>fdm/jsbsim/inertia/cg-x-in</property>
					<entry>
						<ind>419</ind>
						<dep>0.00200020</dep>
					</entry>
					<entry>
						<ind>423</ind>
						<dep>0.00200020</dep>
					</entry>
					<entry>
						<ind>426</ind>
						<dep>0.1018</dep>
					</entry>
				</table>
			</expression>
		</gain>
		<input>
			<expression>
				<value>1</value>
			</expression>
		</input>
		<output>autopilot/internal/alt-td</output>
	</filter>
	<pid-controller>
		<name>Altitude Hold (Altimeter based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>altitude-hold</value>
		</enable>
		<input>
			<prop>/velocities/vertical-speed-fps</prop>
		</input>
		<reference>
			<prop>/autopilot/internal/target-climb-rate-fps</prop>
		</reference>
		<output>
			<prop>fdm/jsbsim/systems/afcs/elevator-cmd-delta</prop>
		</output>
		<config>
			<Kp>
				<expression>
					<property>autopilot/internal/alt-kp</property>
				</expression>
			</Kp>
			<Ti>
				<expression>
					<property>autopilot/internal/alt-ti</property>
				</expression>
			</Ti>
			<Td>
				<expression>
					<property>autopilot/internal/alt-td</property>
				</expression>
			</Td>

			<!-- nose down -ve nose up +ve -->
			<u_min>-0.6</u_min>
			<u_max>0.6</u_max>
		</config>
	</pid-controller>


	<pi-simple-controller>
		<name>AGL Hold (Altimeter based) Stage 1</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>agl-hold</value>
		</enable>
		<input>
			<prop>/position/altitude-agl-ft</prop>
		</input>
		<reference>
			<prop>/autopilot/settings/target-agl-ft</prop>
		</reference>
		<output>
			<prop>/autopilot/internal/target-climb-rate-fps</prop>
		</output>
		<config>
			<Kp>0.08</Kp>
			<u_min>
				<expression>
					<product>
						<value>-1</value>
						<property>autopilot/internal/climb-limit-fps</property>
					</product>
				</expression>
			</u_min>
			<u_max>
				<expression>
					<product>
						<value>1</value>
						<property>autopilot/internal/climb-limit-fps</property>
					</product>
				</expression>
			</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>AGL Hold (Altimeter based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<prop>/autopilot/locks/altitude</prop>
			<value>agl-hold</value>
		</enable>
		<input>
			<prop>/velocities/vertical-speed-fps</prop>
		</input>
		<reference>
			<prop>/autopilot/internal/target-climb-rate-fps</prop>
		</reference>
		<output>
			<prop>fdm/jsbsim/systems/afcs/elevator-cmd-delta</prop>
		</output>
		<config>
			<Kp>0.0036</Kp>
			<Ti>1.5215000000</Ti>
			<Td>0.002000200</Td>

			<!-- nose down -ve nose up +ve -->
			<u_min>-0.6</u_min>
			<u_max>0.6</u_max>
		</config>
	</pid-controller>

	<!-- =============================================================== -->
	<!-- Velocity Modes                                                  -->
	<!-- =============================================================== -->

	<pid-controller>
		<name>Autothrottle knots</name>
		<debug>false</debug>
		<enable>
			<condition>
				<not>
					<or>
						<property>/gear/gear[0]/wow</property>
						<property>/gear/gear[1]/wow</property>
						<property>/gear/gear[2]/wow</property>
					</or>
				</not>
				<equals>
					<property>autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
				<greater-than>
					<property>/autopilot/settings/target-speed-kt</property>
					<value>3</value>
				</greater-than>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
		</input>
		<reference>
			<property>/autopilot/settings/target-speed-kt</property>
		</reference>
		<output>
			<property>/controls/engines/throttle-pid</property>
		</output>
		<config>
			<Kp>0.1</Kp>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.0</gamma>
			<Ti>6.0</Ti>
			<Td>0.6</Td>
			<u_min>0.081</u_min>
			<u_max>
				<condition>
					<equals>
						<property>/autopilot/locks/autothrottle-permit-augmentation</property>
						<value>1</value>
					</equals>
				</condition>
				<value>4.0</value>
			</u_max>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<pid-controller>
		<name>Autothrottle mach</name>
		<debug>false</debug>
		<enable>
			<condition>
				<not>
					<or>
						<property>/gear/gear[0]/wow</property>
						<property>/gear/gear[1]/wow</property>
						<property>/gear/gear[2]/wow</property>
					</or>
				</not>
				<equals>
					<property>autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
				<less-than-equals>
					<property>/autopilot/settings/target-speed-kt</property>
					<value>3</value>
				</less-than-equals>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/airspeed-indicator/indicated-mach</property>
		</input>
		<reference>
			<property>/autopilot/settings/target-speed-kt</property>
		</reference>
		<output>
			<property>/controls/engines/throttle-pid</property>
		</output>
		<config>
			<Kp>50</Kp>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.0</gamma>
			<Ti>10.0</Ti>
			<Td>0.00001</Td>
			<u_min>0.081</u_min>
			<u_max>
				<condition>
					<equals>
						<property>/autopilot/locks/autothrottle-permit-augmentation</property>
						<value>1</value>
					</equals>
				</condition>
				<value>4.0</value>
			</u_max>
			<u_max>1.0</u_max>
		</config>
	</pid-controller>

	<filter>
		<name>Throttle bias for augmentation.</name>
		<type>gain</type>
		<gain>1.0</gain>
		<enable>
			<condition>
				<not>
					<or>
						<property>/gear/gear[0]/wow</property>
						<property>/gear/gear[1]/wow</property>
						<property>/gear/gear[2]/wow</property>
					</or>
				</not>
				<equals>
					<property>autopilot/locks/speed</property>
					<value>speed-with-throttle</value>
				</equals>
			</condition>
		</enable>
		<input>
			<expression>
				<table>
					<property>/controls/engines/throttle-pid</property>
					<entry>
						<ind>0.0</ind>
						<dep>0.00000</dep>
					</entry>
					<entry>
						<ind>1.0</ind>
						<dep>0.91722</dep>
					</entry>
					<entry>
						<ind>4.0</ind>
						<dep>1.00000</dep>
					</entry>
				</table>
			</expression>
		</input>
		<output>
			<property>/controls/engines/engine[0]/throttle</property>
			<property>/controls/engines/engine[1]/throttle</property>
		</output>
	</filter>
</PropertyList>
