<?xml version="1.0"?>

<!--
##############################################
# Copyright (c) Joshua Davidson (it0uchpods) #
##############################################
-->

<!-- Airbus A3XX FBW System -->
<!-- Joshua Davidson (it0uchpods) -->

<PropertyList>

 <!-- =============================================================== -->
 <!-- Lateral                                                         -->
 <!-- =============================================================== -->
 
	<filter>
	   <name>IT-CONTROLLER: ROLL</name>
		<type>gain</type>
		<gain>1.0</gain>
		<update-interval-secs type="double">0.05</update-interval-secs>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-fbw/roll-lim</property>
						<value>33</value>
					</equals>
					<not-equals>
						<property>/it-fbw/roll-back</property>
						<value>1</value>
					</not-equals>
					<not-equals>
						<property>/it-fbw/protections/overspeed</property>
						<value>1</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<sum>
					<table>
						<property>/controls/flight/aileron-input</property> 
						<entry><ind>-1</ind><dep>-12.0</dep></entry>
						<entry><ind> 0</ind><dep>  0.0</dep></entry>
						<entry><ind> 1</ind><dep> 12.0</dep></entry>
					</table>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>-33.00000</ind><dep>1</dep></entry>
							<entry><ind>-32.99999</ind><dep>0</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>-1</ind><dep>12.0</dep></entry>
							<entry><ind> 0</ind><dep> 0.0</dep></entry>
						</table>
					</product>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>32.99999</ind><dep>0</dep></entry>
							<entry><ind>33.00000</ind><dep>1</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>0</ind><dep>  0.0</dep></entry>
							<entry><ind>1</ind><dep>-12.0</dep></entry>
						</table>
					</product>
				</sum>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-fbw/roll-lim</property>
						<value>67</value>
					</equals>
					<not-equals>
						<property>/it-fbw/protections/overspeed</property>
						<value>1</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<sum>
					<table>
						<property>/controls/flight/aileron-input</property> 
						<entry><ind>-1</ind><dep>-12.0</dep></entry>
						<entry><ind> 0</ind><dep>  0.0</dep></entry>
						<entry><ind> 1</ind><dep> 12.0</dep></entry>
					</table>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>-67.00000</ind><dep>1</dep></entry>
							<entry><ind>-66.99999</ind><dep>0</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>-1</ind><dep>12.0</dep></entry>
							<entry><ind> 0</ind><dep> 0.0</dep></entry>
						</table>
					</product>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>66.99999</ind><dep>0</dep></entry>
							<entry><ind>67.00000</ind><dep>1</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>0</ind><dep>  0.0</dep></entry>
							<entry><ind>1</ind><dep>-12.0</dep></entry>
						</table>
					</product>
				</sum>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-fbw/roll-back</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/protections/overspeed</property>
						<value>1</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/orientation/roll-deg</property>
					<entry><ind>-67</ind><dep> 25.0</dep></entry>
					<entry><ind>-40</ind><dep> 10.0</dep></entry>
					<entry><ind>-33</ind><dep>  0.0</dep></entry>
					<entry><ind> 33</ind><dep>  0.0</dep></entry>
					<entry><ind> 40</ind><dep>-10.0</dep></entry>
					<entry><ind> 67</ind><dep>-25.0</dep></entry>
				</table>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-fbw/protections/overspeed</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/protections/overspeed-roll-back</property>
						<value>1</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<sum>
					<table>
						<property>/controls/flight/aileron-input</property> 
						<entry><ind>-1</ind><dep>-12.0</dep></entry>
						<entry><ind> 0</ind><dep>  0.0</dep></entry>
						<entry><ind> 1</ind><dep> 12.0</dep></entry>
					</table>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>-40.00000</ind><dep>1</dep></entry>
							<entry><ind>-39.99999</ind><dep>0</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>-1</ind><dep>12.0</dep></entry>
							<entry><ind> 0</ind><dep> 0.0</dep></entry>
						</table>
					</product>
					<product>
						<table>
							<property>/orientation/roll-deg</property>
							<entry><ind>39.99999</ind><dep>0</dep></entry>
							<entry><ind>40.00000</ind><dep>1</dep></entry>
						</table>
						<table>
							<property>/controls/flight/aileron-input</property> 
							<entry><ind>0</ind><dep>  0.0</dep></entry>
							<entry><ind>1</ind><dep>-12.0</dep></entry>
						</table>
					</product>
				</sum>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-fbw/protections/overspeed</property>
						<value>1</value>
					</equals>
					<equals>
						<property>/it-fbw/protections/overspeed-roll-back</property>
						<value>1</value>
					</equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/orientation/roll-deg</property>
					<entry><ind>-40</ind><dep> 25.0</dep></entry>
					<entry><ind>-15</ind><dep> 10.0</dep></entry>
					<entry><ind>  0</ind><dep>  0.0</dep></entry>
					<entry><ind> 15</ind><dep>-10.0</dep></entry>
					<entry><ind> 40</ind><dep>-25.0</dep></entry>
				</table>
			</expression>
		</input>
		<output>/it-fbw/roll-rate</output>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: ROLL KP (P Gain)</name>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<expression>
				<table>
					<property>/velocities/mach</property>
					<entry><ind>0.2</ind><dep>0.13</dep></entry>
					<entry><ind>0.9</ind><dep>0.06</dep></entry>
				</table>
			</expression>
		</input>
		<output>/it-fbw/roll-kp</output>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: ROLL TI (I Time)</name>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<expression>
				<table>
					<property>/velocities/mach</property>
					<entry><ind>0.2</ind><dep>0.75</dep></entry>
					<entry><ind>0.9</ind><dep>0.65</dep></entry>
				</table>
			</expression>
		</input>
		<output>/it-fbw/roll-ti</output>
	</filter>
	
	<pid-controller>
		<name>IT-CONTROLLER: ROLL</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</equals>
				</and>
			</condition>
		</enable>
		<input>
			<property>/orientation/roll-rate-degps</property>
		</input>
		<reference>
			<property>/it-fbw/roll-rate</property>
		</reference>
		<output>
			<property>/controls/flight/aileron-fbw-cmd</property>
		</output>
		<config>
			<Kp>
				<property>/it-fbw/roll-kp</property>
			</Kp>
			<beta>1</beta>
			<alpha>0.1</alpha>
			<gamma>0</gamma>
			<Ti>
				<property>/it-fbw/roll-ti</property>
			</Ti>
			<Td>0.005</Td>
			<u_min>-1</u_min>
			<u_max>1</u_max>
		</config>
	</pid-controller>
	
	<filter>
		<name>IT-CONTROLLER: ROLL OPTION</name>
		<debug>false</debug>
		<type>gain</type>
		<gain>1.0</gain>
		<feedback-if-disabled>true</feedback-if-disabled>
		<initialize-to>output</initialize-to>
		<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>
						<and>
							<equals>
								<property>/gear/gear[1]/wow</property>
								<value>0</value>
							</equals>
							<equals>
								<property>/gear/gear[2]/wow</property>
								<value>0</value>
							</equals>
						</and>
					</or>
					<equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</equals>
				</and>
			</condition>
			<property>/controls/flight/aileron-fbw-cmd</property>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/it-autoflight/output/ap1</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/it-autoflight/output/ap2</property>
						<value>0</value>
					</equals>
					<or>
						<equals>
							<property>/gear/gear[1]/wow</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/gear/gear[2]/wow</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-fbw/law</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/it-fbw/law</property>
							<value>2</value>
						</equals>
					</or>
				</and>
			</condition>
			<property>/controls/flight/aileron-input-fast</property>
		</input>
		<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>
					<or>
						<equals>
							<property>/gear/gear[1]/wow</property>
							<value>1</value>
						</equals>
						<equals>
							<property>/gear/gear[2]/wow</property>
							<value>1</value>
						</equals>
					</or>
					<equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</equals>
				</and>
			</condition>
			<property>/controls/flight/rudder</property>
			<scale>-1</scale>
		</input>
		<input>
			<condition>
				<equals>
					<property>/it-fbw/law</property>
					<value>3</value>
				</equals>
			</condition>
			<value>0</value>
		</input>
		<output>/controls/flight/roll-fbw</output>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: SPOILER</name>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<condition>
				<equals>
					<property>/it-fbw/roll-back</property>
					<value>0</value>
				</equals>
			</condition>
			<expression>
				<product>
					<property>/controls/flight/aileron-input</property>
					<table>
						<property>/instrumentation/airspeed-indicator/indicated-mach</property>
						<entry><ind>0.2</ind><dep>1.00</dep></entry>
						<entry><ind>0.9</ind><dep>0.25</dep></entry>
					</table>
				</product>
			</expression>
		</input>
		<input>
			<condition>
				<equals>
					<property>/it-fbw/roll-back</property>
					<value>1</value>
				</equals>
			</condition>
			<value>0</value>
		</input>
		<output>/controls/flight/spoiler-input</output>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: LEFT SPOILER</name>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<condition>
				<and>
					<equals>
						<property>/systems/failures/aileron-left</property>
						<value>0</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>3</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/controls/flight/spoiler-input</property>
					<entry><ind>-1.0</ind><dep>-1.0</dep></entry>
					<entry><ind>-0.2</ind><dep> 0.0</dep></entry>
					<entry><ind> 0.0</ind><dep> 0.0</dep></entry>
					<entry><ind> 0.2</ind><dep> 0.0</dep></entry>
					<entry><ind> 1.0</ind><dep> 1.0</dep></entry>
				</table>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/systems/failures/aileron-left</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>3</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/controls/flight/roll-fbw</property>
					<entry><ind>-1.0</ind><dep>-1.0</dep></entry>
					<entry><ind> 0.0</ind><dep> 0.0</dep></entry>
					<entry><ind> 1.0</ind><dep> 1.0</dep></entry>
				</table>
			</expression>
		</input>
		<input>0</input>
		<output>/controls/flight/spoiler-left-fbw-cmd</output>
		<min>-1</min>
		<max>1</max>
	</filter>
	
	<filter>
		<name>IT-CONTROLLER: RIGHT SPOILER</name>
		<type>gain</type>
		<gain>1.0</gain>
		<input>
			<condition>
				<and>
					<equals>
						<property>/systems/failures/aileron-right</property>
						<value>0</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>3</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/controls/flight/spoiler-input</property>
					<entry><ind>-1.0</ind><dep>-1.0</dep></entry>
					<entry><ind>-0.2</ind><dep> 0.0</dep></entry>
					<entry><ind> 0.0</ind><dep> 0.0</dep></entry>
					<entry><ind> 0.2</ind><dep> 0.0</dep></entry>
					<entry><ind> 1.0</ind><dep> 1.0</dep></entry>
				</table>
			</expression>
		</input>
		<input>
			<condition>
				<and>
					<equals>
						<property>/systems/failures/aileron-right</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>3</value>
					</not-equals>
				</and>
			</condition>
			<expression>
				<table>
					<property>/controls/flight/roll-fbw</property>
					<entry><ind>-1.0</ind><dep>-1.0</dep></entry>
					<entry><ind> 0.0</ind><dep> 0.0</dep></entry>
					<entry><ind> 1.0</ind><dep> 1.0</dep></entry>
				</table>
			</expression>
		</input>
		<input>0</input>
		<output>/controls/flight/spoiler-right-fbw-cmd</output>
		<min>-1</min>
		<max>1</max>
	</filter>

 <!-- =============================================================== -->
 <!-- Yaw Damper/Turn Coordinator                                     -->
 <!-- =============================================================== -->

	<filter>
		<name>IT-CONTROLLER: YAW DAMPER/TURN COORDINATOR FEEDBACK IF DISABLED</name>
		<enable>
			<condition>
				<or>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>1</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</not-equals>
					<greater-than-equals>
						<property>/controls/flight/rudder</property>
						<value>0.1</value>
					</greater-than-equals>
					<less-than-equals>
						<property>/controls/flight/rudder</property>
						<value>-0.1</value>
					</less-than-equals>
					<less-than>
						<property>/position/gear-agl-ft</property>
						<value>50</value>
					</less-than>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</equals>
				</or>
			</condition>
		</enable>
		<type>gain</type>
		<gain>1.0</gain>
		<input>0</input>
		<output>/controls/flight/rudder-fbw-cmd</output>
		<min>-0.2</min>
		<max>0.2</max>
	</filter>
	
	<pid-controller>
		<name>IT-CONTROLLER: YAW DAMPER/TURN COORDINATOR</name>
		<debug>false</debug>
		<enable>
			<condition>
				<and>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</equals>
					<greater-than-equals>
						<property>/position/gear-agl-ft</property>
						<value>50</value>
					</greater-than-equals>
					<not-equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</not-equals>
					<less-than>
						<property>/controls/flight/rudder</property>
						<value>0.1</value>
					</less-than>
					<greater-than>
						<property>/controls/flight/rudder</property>
						<value>-0.1</value>
					</greater-than>
				</and>
			</condition>
		</enable>
		<input>
			<property>/instrumentation/slip-skid-ball/indicated-slip-skid</property>
		</input>
		<reference>
			<value>0</value>
		</reference>
		<output>
			<property>/controls/flight/rudder-fbw-cmd</property>
		</output>
		<config>
			<Kp>0.025</Kp>
			<beta>1</beta>
			<alpha>0.1</alpha>
			<gamma>0</gamma>
			<Ti>3.0</Ti>
			<Td>0.00001</Td>
			<u_min>-0.2</u_min>
			<u_max>0.2</u_max>
		</config>
	</pid-controller>
	
	<filter>
		<name>IT-CONTROLLER: RUDDER OPTION</name>
		<debug>false</debug>
		<feedback-if-disabled>true</feedback-if-disabled>
		<initialize-to>output</initialize-to>
		<input>
			<condition>
				<and>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>0</value>
					</equals>
					<equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</equals>
					<less-than>
						<property>/controls/flight/rudder</property>
						<value>0.1</value>
					</less-than>
					<greater-than>
						<property>/controls/flight/rudder</property>
						<value>-0.1</value>
					</greater-than>
					<greater-than-equals>
						<property>/position/gear-agl-ft</property>
						<value>50</value>
					</greater-than-equals>
					<not-equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</not-equals>
				</and>
			</condition>
			<property>/controls/flight/rudder-fbw-cmd</property>
		</input>
		<input>
			<condition>
				<or>
					<equals>
						<property>/gear/gear[1]/wow</property>
						<value>1</value>
					</equals>
					<equals>
						<property>/gear/gear[2]/wow</property>
						<value>1</value>
					</equals>
					<not-equals>
						<property>/it-fbw/law</property>
						<value>0</value>
					</not-equals>
					<greater-than-equals>
						<property>/controls/flight/rudder</property>
						<value>0.1</value>
					</greater-than-equals>
					<less-than-equals>
						<property>/controls/flight/rudder</property>
						<value>-0.1</value>
					</less-than-equals>
					<less-than>
						<property>/position/gear-agl-ft</property>
						<value>50</value>
					</less-than>
					<equals>
						<property>/it-autoflight/output/lat</property>
						<value>4</value>
					</equals>
				</or>
			</condition>
			<property>/controls/flight/rudder</property>
		</input>
		<output>/controls/flight/rudder-fbw</output>
		<type>noise-spike</type>
		<max-rate-of-change>2.5</max-rate-of-change>
	</filter>

</PropertyList>