<?xml version="1.0"?>

<PropertyList>
	<!-- =============================================================== -->
	<!--                        Lateral Modes                            -->
	<!-- =============================================================== -->

	<pi-simple-controller>
		<name>HDG HOLD</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>instrumentation/afds/ap-modes/roll-mode</property>
					<value>HDG HOLD</value>
				</equals>
			</condition>
		</enable>
		<input>
			<property>autopilot/internal/fdm-heading-bug-error-deg</property>
		</input>
		<reference>
			<value>0</value>
		</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>-1.75</Kp>
			<Ki>0.0</Ki>
			<u_min>-30</u_min>
			<u_max>30</u_max>
			<!--u_min>
				<property>instrumentation/afds/settings/bank-min</property>
			</u_min>
			<u_max>
				<property>instrumentation/afds/settings/bank-max</property>
			</u_max-->
		</config>
	</pi-simple-controller>

	<filter>
		<name>LNAV waypoint error computer/normalizer</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/ap-modes/roll-mode</property>
			<value>LNAV</value>
		</enable>
		<type>gain</type>
		<input>
			<property>/autopilot/route-manager/wp/bearing-deg</property>
			<offset>
			<property>/orientation/heading-magnetic-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>LNAV1</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/ap-modes/roll-mode</property>
			<value>LNAV</value>
		</enable>
		<input>
			<property>/autopilot/internal/waypoint-bearing-error-deg</property>
		</input>
		<reference>
			<property>/autopilot/internal/course-deviation</property>
			<scale>-1.5</scale>
		</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>-1.75</Kp>
			<Ki>0.0</Ki>
			<u_min>-30</u_min>
			<u_max>30</u_max>
		</config>
	</pi-simple-controller>

	<pi-simple-controller>
		<name>LOC</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/ap-modes/roll-mode</property>
			<value>LOC</value>
		</enable>
		<input>
			<property>/autopilot/internal/nav1-heading-error-deg</property>
		</input>
		<reference>
			<value>0.0</value>
		</reference>
		<output>
			<property>/autopilot/internal/target-roll-deg</property>
		</output>
		<config>
			<Kp>-3.0</Kp>
			<Ki>0.0</Ki>
			<u_min>-30</u_min>
			<u_max>30</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>Aileron Control</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/inputs/AP</property>
		</enable>
		<input>
			<property>/orientation/roll-deg</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-roll-deg</property>
		</reference>
		<output>
			<property>/controls/flight/aileron-filter</property>
		</output>
		<config>
			<Kp>0.007</Kp>
			<Ti>10</Ti>
			<Td>0.0</Td>
			<u_min>
				<value>-0.5</value>
			</u_min>
			<u_max>
				<value>0.5</value>
			</u_max>
		</config>
	</pid-controller>

	<filter>
		<name>Aileron control filter</name>
		<debug>false</debug>
		<type>noise-spike</type>
		<enable>
			<property>instrumentation/afds/inputs/AP</property>
		</enable>
		<max-rate-of-change>0.5</max-rate-of-change>
		<initialize-to>output</initialize-to>
		<input>
			<property>/controls/flight/aileron-filter</property>
		</input>
		<output>/controls/flight/aileron</output>
	</filter>

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

	<pi-simple-controller>
		<name>Altitude Stage 1</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>instrumentation/afds/ap-modes/pitch-mode</property>
						<value>ALT</value>
					</equals>
					<and>
						<equals>
							<property>instrumentation/afds/ap-modes/pitch-mode</property>
							<value>V/S</value>
						</equals>
						<equals>
							<property>autopilot/settings/vertical-speed-fpm</property>
							<value>0</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<input>
			<property>instrumentation/altimeter/indicated-altitude-ft</property>
		</input>
		<reference>
			<property>/autopilot/settings/actual-target-altitude-ft</property>
		</reference>
		<output>
			<property>/autopilot/internal/target-climb-rate-fps</property>
		</output>
		<config>
			<Kp>0.15</Kp>
			<Ki>0.01</Ki>
			<u_min>
			<value>-20.00</value>
			</u_min>
			<u_max>
			<value>20.00</value>
			</u_max>
		</config>
	</pi-simple-controller>

	<pid-controller>
		<name>Altitude Hold (Altimeter based) Stage 2</name>
		<debug>false</debug>
		<enable>
			<condition>
				<or>
					<equals>
						<property>instrumentation/afds/ap-modes/pitch-mode</property>
						<value>ALT</value>
					</equals>
					<and>
						<equals>
							<property>instrumentation/afds/ap-modes/pitch-mode</property>
							<value>V/S</value>
						</equals>
						<equals>
							<property>autopilot/settings/vertical-speed-fpm</property>
							<value>0</value>
						</equals>
					</and>
				</or>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-climb-rate-fps</property>
		</reference>
		<output>
			<property>/autopilot/internal/target-pitch-deg</property>
		</output>
		<config>
		<Kp>
			<condition>
				<greater-than>
					<property>instrumentation/altimeter/indicated-altitude-ft</property>
					<value>26000</value>
				</greater-than>
			</condition>
			<value>0.1</value>
		</Kp>
		<Kp>
			<condition>
				<greater-than>
					<property>instrumentation/altimeter/indicated-altitude-ft</property>
					<value>14000</value>
				</greater-than>
			</condition>
			<value>0.2</value>
		</Kp>
			<Kp>0.5</Kp>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.0</gamma>
			<Ti>10.0</Ti>
			<Td>0.005</Td>
			<u_min>-15</u_min>
			<u_max>15</u_max>
			<!--u_min>
				<property>instrumentation/afds/settings/pitch-min</property>
			</u_min>
			<u_max>
				<property>instrumentation/afds/settings/pitch-max</property>
			</u_max-->
		</config>
	</pid-controller>

	<pid-controller>
		<name>Glideslop Hold</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/ap-modes/pitch-mode</property>
			<value>G/S</value>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/instrumentation/nav[0]/gs-rate-of-climb</property>
		</reference>
		<output>
			<property>/autopilot/internal/target-pitch-deg</property>
		</output>
		<config>
			<Kp>0.45</Kp>
			<Td>0.0007</Td>
			<Ti>50.0</Ti>
			<u_min>-15</u_min>
			<u_max>15</u_max>
		</config>
	</pid-controller>

	<pid-controller>
		<name>VS</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>instrumentation/afds/ap-modes/pitch-mode</property>
						<value>V/S</value>
					</equals>
					<not>
						<equals>
							<property>autopilot/settings/vertical-speed-fpm</property>
							<value>0</value>
						</equals>
					</not>
				</and>
			</condition>
		</enable>
		<input>
			<property>/velocities/vertical-speed-fps</property>
		</input>
		<reference>
			<property>/autopilot/settings/vertical-speed-fpm</property>
			<scale>0.01666666</scale>
		</reference>
		<output>
			<property>/autopilot/internal/target-pitch-deg</property>
		</output>
		<config>
			<Ts>0.05</Ts>
			<Kp>0.15</Kp>
			<beta>1.0</beta>
			<alpha>0.1</alpha>
			<gamma>0.0</gamma>
			<Ti>10.0</Ti>
			<Td>0.00001</Td>
			<u_min>-15</u_min>
			<u_max>15</u_max>
			<!--u_min>
				<property>instrumentation/afds/settings/pitch-min</property>
			</u_min>
			<u_max>
				<property>instrumentation/afds/settings/pitch-max</property>
			</u_max-->
		</config>
	</pid-controller>

	<pid-controller>
		<name>Elevator Control</name>
		<debug>false</debug>
		<enable>
			<property>instrumentation/afds/inputs/AP</property>
		</enable>
		<input>
			<property>/orientation/pitch-deg</property>
		</input>
		<reference>
			<property>/autopilot/internal/target-pitch-deg</property>
		</reference>
		<output>
			<property>/controls/flight/elevator-trim-filter</property>
		</output>
		<config>
			<Kp>-0.020</Kp>
			<Ti>10.0</Ti>
			<Td>0.0</Td>
			<u_min>
				<value>-0.8</value>
			</u_min>
			<u_max>
				<value>0.8</value>
			</u_max>
		</config>
	</pid-controller>

	<filter>
		<name>Elevator control filter</name>
		<debug>false</debug>
		<type>noise-spike</type>
		<enable>
			<property>instrumentation/afds/inputs/AP</property>
		</enable>
		<max-rate-of-change>0.2</max-rate-of-change>
		<initialize-to>output</initialize-to>
		<input>
			<property>/controls/flight/elevator-trim-filter</property>
		</input>
		<output>/controls/flight/elevator-trim</output>
	</filter>

    <filter>
        <name>IAS speed limit</name>
        <type>gain</type>
        <gain>1.0</gain>
        <input>
            <condition>
                <greater-than>
                    <property>/controls/flight/flaps</property>
                    <value>0.0</value>
                </greater-than>
            </condition>

            <expression>
                <table>
                    <property>/controls/flight/flaps</property> 
                    <entry><ind>0.033</ind><dep>255</dep></entry>
                    <entry><ind>0.166</ind><dep>235</dep></entry>
                    <entry><ind>0.5</ind><dep>215</dep></entry>
                    <entry><ind>0.666</ind><dep>200</dep></entry>
                    <entry><ind>0.833</ind><dep>190</dep></entry>
                    <entry><ind>1.0</ind><dep>180</dep></entry>
                </table>
            </expression>
        </input>

        <input>
            <condition>
                <greater-than>
                    <property>/gear/gear/position-norm</property>
                    <value>0.0</value>
                </greater-than>
            </condition>
            <value>270</value>
        </input>

        <input> 
            <!-- basic IAS limit based upon diagram 7771003, Sec1.Page4 in the
              continental manual -->
            <expression>
                <table>
                    <property>instrumentation/altimeter/indicated-altitude-ft</property> 
                    <entry><ind>0</ind><dep>330</dep></entry> <!-- clean Vmo -->
                    <entry><ind>30000</ind><dep>330</dep></entry>
                    <entry><ind>43000</ind><dep>248</dep></entry>
                </table>
            </expression>
        </input>
    
        <output>instrumentation/afds/max-airspeed-kts</output>
    </filter>

    <filter>
        <type>gain</type>
        <gain>1.0</gain>

        <input>
            <expression>
                <min>
                    <property>/autopilot/settings/target-speed-kt</property>
                    <property>instrumentation/afds/max-airspeed-kts</property>
                </min>
            </expression>
        </input>

        <output>instrumentation/afds/ias-target-kt</output>
    </filter>

    <!-- thrust mode: SPD/ias -->
    <pid-controller>
        <name>Auto Throttle1 ias</name>
        <debug>false</debug>
        <enable>
            <condition>
                <property>/instrumentation/afds/inputs/at-armed[0]</property>
                <equals>
                    <property>/instrumentation/afds/inputs/autothrottle-index</property>
                    <value>1</value>
                </equals>
                <honor-passive>true</honor-passive>
            </condition>
        </enable>
		<initialize-to>output</initialize-to>
        <input>
            <prop>/instrumentation/airspeed-indicator/indicated-speed-kt</prop>
        </input>
        <reference>
            <prop>instrumentation/afds/ias-target-kt</prop>
        </reference>
        <output>
            <prop>/controls/engines/engine[0]/throttle</prop>
        </output>
        <config>
			<Kp>
				<condition>
					<and>
						<eauals>
							<property>instrumentation/afds/ap-modes/pitch-mode</property>
							<value>G/S</value>
						</eauals>
						<less-than>
							<property>position/altitude-agl-ft</property>
							<value>200</value>
						</less-than>
					</and>
				</condition>
				<value>0.0001</value>
			</Kp>
			<Kp>
            	<condition>
					<greater-than>
						<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
 						<property>instrumentation/afds/ias-target-kt</property>
					</greater-than>
            	</condition>
				<value>0.08</value>
			</Kp>
			<Kp>0.16</Kp>
            <Td>0.0001</Td>
            <Ti>
            	<condition>
					<greater-than>
						<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
 						<property>instrumentation/afds/ias-target-kt</property>
					</greater-than>
            	</condition>
				<value>20</value>
            </Ti>
            <Ti>10</Ti>
            <u_min>
            	<condition>
                	<equals>
						<property>instrumentation/afds/ap-modes/pitch-mode</property>
						<value>G/S</value>
                	</equals>
            	</condition>
				<value>0.06</value>
			</u_min>
            <u_min>0.125</u_min>
			<u_max>1</u_max>
        </config>
    </pid-controller>
</PropertyList>


