<?xml version="1.0"?>

<!-- IT-AUTOFLIGHT -->
<!-- Copyright (c) 2021 Josh Davidson (Octal450) -->

<PropertyList>
	
	<!-- Roll Axis -->
	<filter>
		<name>IT-CONTROLLER: Heading/LNAV</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>
			<expression>
				<table>
					<property>/velocities/airspeed-kt</property>
					<entry><ind>140</ind><dep>1.6</dep></entry>
					<entry><ind>360</ind><dep>2.6</dep></entry>
				</table>
			</expression>
		</gain>
		<enable>
			<condition>
				<and>
					<or>
						<equals>
							<property>/it-autoflight/output/lat</property>
							<value>0</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/lat</property>
							<value>1</value>
						</equals>
					</or>
					<or>
						<equals>
							<property>/it-autoflight/output/ap1</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/ap2</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/fd1</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/fd2</property>
							<value>1</value>
						</equals>
					</or>
				</and>
			</condition>
		</enable>
		<input>/it-autoflight/internal/heading-error-deg</input>
		<reference>0</reference>
		<output>/it-autoflight/internal/target-roll-deg</output>
		<min>
			<property>/it-autoflight/internal/bank-limit</property>
			<scale>-1.0</scale>
		</min>
		<max>/it-autoflight/internal/bank-limit</max>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: VOR/LOC</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>
			<expression>
				<table>
					<property>/velocities/airspeed-kt</property>
					<entry><ind>140</ind><dep>1.6</dep></entry>
					<entry><ind>360</ind><dep>2.6</dep></entry>
				</table>
			</expression>
		</gain>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>2</value>
					</equals>
					<or>
						<equals>
							<property>/it-autoflight/output/ap1</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/ap2</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/fd1</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/fd2</property>
							<value>1</value>
						</equals>
					</or>
				</and>
			</condition>
		</enable>
		<input>/it-autoflight/internal/nav-heading-error-deg</input>
		<reference>0</reference>
		<output>/it-autoflight/internal/target-roll-deg</output>
		<min>
			<property>/it-autoflight/internal/bank-limit</property>
			<scale>-1.0</scale>
		</min>
		<max>/it-autoflight/internal/bank-limit</max>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: Align/Rollout/Takeoff</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>1.0</gain>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</equals>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>5</value>
					</equals>
				</or>
			</condition>
		</enable>
		<input>0</input>
		<output>/it-autoflight/internal/target-roll-deg</output>
	</filter>
	
	<filter>
		<name>System Command: Roll Target Inactive Sync</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>1.0</gain>
		<enable>
			<condition>
				<or>
					<and>
						<not-equals>
							<property>/it-autoflight/output/ap1</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/ap2</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/fd1</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/fd2</property>
							<value>1</value>
						</not-equals>
					</and>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>9</value>
					</equals>
				</or>
			</condition>
		</enable>
		<input>/orientation/roll-deg</input>
		<output>/it-autoflight/internal/target-roll-deg</output>
		<min>
			<property>/it-autoflight/internal/bank-limit</property>
			<scale>-1.0</scale>
		</min>
		<max>/it-autoflight/internal/bank-limit</max>
	</filter>
	
	<filter>
		<name>System Command: Target Roll Filter</name>
		<debug>false</debug>
		<type>noise-spike</type>
		<input>/it-autoflight/internal/target-roll-deg</input>
		<output>/it-autoflight/internal/target-roll</output>
		<max-rate-of-change>
			<condition>
				<or>
					<and>
						<not-equals>
							<property>/it-autoflight/output/ap1</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/ap2</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/fd1</property>
							<value>1</value>
						</not-equals>
						<not-equals>
							<property>/it-autoflight/output/fd2</property>
							<value>1</value>
						</not-equals>
					</and>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>9</value>
					</equals>
				</or>
			</condition>
			<value>1000</value>
		</max-rate-of-change>
		<max-rate-of-change>
			<condition>
				<and>
					<not-equals>
						<property>/it-autoflight/output/ap1</property>
						<value>1</value>
					</not-equals>
					<not-equals>
						<property>/it-autoflight/output/ap2</property>
						<value>1</value>
					</not-equals>
				</and>
			</condition>
			<value>15</value>
		</max-rate-of-change>
		<max-rate-of-change>6</max-rate-of-change>
	</filter>
	
	<filter>
		<name>System Command: Roll Rate Target</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>-0.1</gain>
		<input>/orientation/roll-deg</input>
		<reference>/it-autoflight/internal/target-roll</reference>
		<output>/fdm/jsbsim/fbw/fmgc/roll-cmd</output> <!-- Inputs to the FBW Roll -->
		<min>-0.32</min>
		<max>0.32</max>
	</filter>
	
	<!-- Yaw Axis -->
	<pi-simple-controller>
		<name>IT-CONTROLLER: Yaw VOR/LOC</name>
		<debug>false</debug>
		<enable>
			<condition>
				<equals>
					<property>/it-autoflight/output/lat</property>
					<value>4</value>
				</equals>
			</condition>
		</enable>
		<input>/it-autoflight/internal/nav-heading-error-deg</input>
		<reference>0</reference>
		<output>/it-autoflight/internal/rudder-cmd</output>
		<config>
			<Kp>
				<condition>
					<and>
						<equals>
							<property>/gear/gear[1]/wow</property>
							<value>0</value>
						</equals>
						<equals>
							<property>/gear/gear[2]/wow</property>
							<value>0</value>
						</equals>
					</and>
				</condition>
				<value>-0.05</value>
			</Kp>
			<Kp>-0.02</Kp>
			<Ki>0</Ki>
		</config>
		<min>-0.15</min>
		<max>0.15</max>
	</pi-simple-controller>
	
	<filter>
		<name>System Command: Rudder</name>
		<debug>false</debug>
		<type>noise-spike</type>
		<input>
			<condition>
				<and>
					<or>
						<equals>
							<property>/it-autoflight/output/ap1</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-autoflight/output/ap2</property>
							<value>1</value>
						</equals>
					</or>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</equals>
				</and>
			</condition>
			<property>/it-autoflight/internal/rudder-cmd</property>
		</input>
		<input>0</input>
		<output>/fdm/jsbsim/fbw/fmgc/yaw-cmd</output> <!-- Inputs to the FBW Yaw -->
		<max-rate-of-change>1.2</max-rate-of-change>
	</filter>

</PropertyList>