<?xml version="1.0"?>

<!-- Airbus A320 FCS -->
<!-- Copyright (c) 2020 Josh Davidson (Octal450) -->

<system name="A320: FCS">
	
	<property value="0">/controls/flight/flaps-input-last</property>
	
	<channel name="Surface Droop">
		
		<fcs_function name="hydraulics/aileron-droop">
			<function>
				<table>
					<independentVar lookup="row">/velocities/airspeed-kt</independentVar>
					<tableData>
						 62  1.0
						116  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="hydraulics/elevator-droop">
			<function>
				<table>
					<independentVar lookup="row">/velocities/airspeed-kt</independentVar>
					<tableData>
						 72  1.0
						121  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="hydraulics/rudder-swing">
			<function>
				<table>
					<independentVar lookup="row">/velocities/airspeed-kt</independentVar> <!-- rudder is rather large at 7m2... so it doesn't take much speed to stop it -->
					<tableData>
						 12  1.0
						 35  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<actuator name="spoilers/anti-droop-cmd">
			<input>fbw/spoiler-output</input>
			<rate_limit sense="incr">0.9</rate_limit>
			<rate_limit sense="decr">2.5</rate_limit>
		</actuator>
		
		<fcs_function name="spoilers/anti-droop-final">
			<function>
				<table>
					<independentVar lookup="row">spoilers/anti-droop-cmd</independentVar>
					<tableData>
						0.5  0.0
						1.0  1.0
					</tableData>
				</table>
			</function>
		</fcs_function>
	
	</channel>
	
	<channel name="Aileron L">
		
		<fcs_function name="hydraulics/aileron-l/extended">
			<function>
				<sum>
					<value>-1</value>
					<property>fbw/aileron-output</property>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="hydraulics/aileron-l/retracted">
			<function>
				<sum>
					<property>fbw/aileron-output</property>
					<table>
						<independentVar lookup="row">/fdm/jsbsim/fcs/flap-pos-deg</independentVar>
						<tableData>
							1  0.00
							5  0.26
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<switch name="hydraulics/aileron-l/pressure-switch-or">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					/systems/fctl/elac1 eq 1
					/systems/hydraulic/blue-psi ge 1500
				</test>
				<test logic="AND">
					/systems/fctl/elac2 eq 1
					/systems/hydraulic/green-psi ge 1500
				</test>
			</test>
		</switch>
		
		<switch name="hydraulics/aileron-l/switch">
			<default value="hydraulics/aileron-droop"/>
			<test logic="AND" value="hydraulics/aileron-l/extended">
				hydraulics/aileron-l/pressure-switch-or eq 1
				spoilers/anti-droop-final ne 0
				/gear/gear[1]/wow eq 1
				/gear/gear[2]/wow eq 1
				/systems/failures/aileron-left eq 0
			</test>
			<test logic="AND" value="hydraulics/aileron-l/retracted">
				hydraulics/aileron-l/pressure-switch-or eq 1
				/systems/failures/aileron-left eq 0
			</test>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</switch>
		
		<pure_gain name="hydraulics/aileron-l/cmd-deg">
			<input>hydraulics/aileron-l/switch</input>
			<gain>25</gain>
		</pure_gain>
		
		<actuator name="hydraulics/aileron-l/final-actuator">
			<input>hydraulics/aileron-l/cmd-deg</input>
			<rate_limit>82</rate_limit>
			<lag>26.5</lag>
			<output>hydraulics/aileron-l/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="Aileron R">
		
		<fcs_function name="hydraulics/aileron-r/extended">
			<function>
				<product>
					<sum>
						<value>1</value>
						<property>fbw/aileron-output</property>
					</sum>
					<value>-1.0</value>
				</product>
			</function>
		</fcs_function>
		
		<fcs_function name="hydraulics/aileron-r/retracted">
			<function>
				<sum>
					<product>
						<property>fbw/aileron-output</property>
						<value>-1.0</value>
					</product>
					<table>
						<independentVar lookup="row">/fdm/jsbsim/fcs/flap-pos-deg</independentVar>
						<tableData>
							1  0.00
							5  0.26
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<switch name="hydraulics/aileron-r/pressure-switch-or">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					/systems/fctl/elac1 eq 1
					/systems/hydraulic/green-psi ge 1500
				</test>
				<test logic="AND">
					/systems/fctl/elac2 eq 1
					/systems/hydraulic/blue-psi ge 1500
				</test>
			</test>
		</switch>
		
		<switch name="hydraulics/aileron-r/switch">
			<default value="hydraulics/aileron-droop"/>
			<test logic="AND" value="hydraulics/aileron-r/extended">
				hydraulics/aileron-r/pressure-switch-or eq 1
				spoilers/anti-droop-final ne 0
				/gear/gear[1]/wow eq 1
				/gear/gear[2]/wow eq 1
				/systems/failures/aileron-right eq 0
			</test>
			<test logic="AND" value="hydraulics/aileron-r/retracted">
				hydraulics/aileron-r/pressure-switch-or eq 1
				/systems/failures/aileron-right eq 0
			</test>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</switch>
		
		<pure_gain name="hydraulics/aileron-r/cmd-deg">
			<input>hydraulics/aileron-r/switch</input>
			<gain>25</gain>
		</pure_gain>
		
		<actuator name="hydraulics/aileron-r/final-actuator">
			<input>hydraulics/aileron-r/cmd-deg</input>
			<rate_limit>82</rate_limit>
			<lag>26.5</lag>
			<output>hydraulics/aileron-r/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="Elevator Common">
		
		<aerosurface_scale name="hydraulics/elevator-output-scale">
			<input>fbw/elevator-output</input>
			<range>
				<min>-0.6666666666666666666666666666666</min> <!-- -20 degrees -->
				<max>0.5</max> <!-- 15 degrees -->
			</range>
		</aerosurface_scale>
		
		<switch name="hydraulics/elevator-output-switch">
			<default value="hydraulics/elevator-output-scale"/>
			<test value="fbw/elevator-output">
				/velocities/groundspeed-kt lt 75
			</test>
		</switch>
	
	</channel>
	
	<channel name="Elevator L">
		
		<switch name="hydraulics/elevator-l/pressure-switch-or">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					<test logic="OR">
						/systems/fctl/elac1 eq 1
						/systems/fctl/sec1 eq 1
					</test>
					/systems/hydraulic/blue-psi ge 1500
				</test>
				<test logic="AND">
					<test logic="OR">
						/systems/fctl/elac2 eq 1
						/systems/fctl/sec2 eq 1
					</test>
					/systems/hydraulic/green-psi ge 1500
				</test>
			</test>
		</switch>
		
		<switch name="hydraulics/elevator-l/switch">
			<default value="hydraulics/elevator-droop"/>
			<test logic="AND" value="0">
				<test logic="OR">
					/systems/hydraulic/blue-psi ge 1500
					/systems/hydraulic/green-psi ge 1500
				</test>
				/systems/failures/elevator-left eq 0
				<test logic="AND"> <!-- only pitch trim available -->
					/systems/fctl/elac1 eq 0
					/systems/fctl/sec1 eq 0
					/systems/fctl/elac2 eq 0
					/systems/fctl/sec2 eq 0
				</test>
			</test>
			<test logic="AND" value="hydraulics/elevator-output-switch">
				hydraulics/elevator-l/pressure-switch-or eq 1
				/systems/failures/elevator-left eq 0
				/it-fbw/law ne 3
			</test>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</switch>
		
		<pure_gain name="hydraulics/elevator-l/cmd-deg">
			<input>hydraulics/elevator-l/switch</input>
			<gain>30</gain>
			<clipto>
				<min>-30</min>
				<max>15</max>
			</clipto>
		</pure_gain>
		
		<actuator name="hydraulics/elevator-l/final-actuator">
			<input>hydraulics/elevator-l/cmd-deg</input>
			<rate_limit>82</rate_limit>
			<lag>26.5</lag>
			<output>hydraulics/elevator-l/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="Elevator R">
		
		<switch name="hydraulics/elevator-r/pressure-switch-or">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					<test logic="OR">
						/systems/fctl/elac1 eq 1
						/systems/fctl/sec1 eq 1
					</test>
					/systems/hydraulic/blue-psi ge 1500
				</test>
				<test logic="AND">
					<test logic="OR">
						/systems/fctl/elac2 eq 1
						/systems/fctl/sec2 eq 1
					</test>
					/systems/hydraulic/yellow-psi ge 1500
				</test>
			</test>
		</switch>
		
		<switch name="hydraulics/elevator-r/switch">
			<default value="hydraulics/elevator-droop"/>
			<test logic="AND" value="0">
				<test logic="OR">
					/systems/hydraulic/blue-psi ge 1500
					/systems/hydraulic/yellow-psi ge 1500
				</test>
				/systems/failures/elevator-right eq 0
				<test logic="AND">  <!-- only pitch trim available -->
					/systems/fctl/elac1 eq 0
					/systems/fctl/sec1 eq 0
					/systems/fctl/elac2 eq 0
					/systems/fctl/sec2 eq 0
				</test>
			</test>
			<test logic="AND" value="hydraulics/elevator-output-switch">
				hydraulics/elevator-r/pressure-switch-or eq 1
				/systems/failures/elevator-right eq 0
				/it-fbw/law ne 3
			</test>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</switch>
		
		<pure_gain name="hydraulics/elevator-r/cmd-deg">
			<input>hydraulics/elevator-r/switch</input>
			<gain>30</gain>
			<clipto>
				<min>-30</min>
				<max>15</max>
			</clipto>
		</pure_gain>
		
		<actuator name="hydraulics/elevator-r/final-actuator">
			<input>hydraulics/elevator-r/cmd-deg</input>
			<rate_limit>82</rate_limit>
			<lag>26.5</lag>
			<output>hydraulics/elevator-r/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="Pitch Trim">
		
		<switch name="hydraulics/stabilizer/rate">
			<default value="0"/> <!-- only mechanical input to hyd actuator. So it does need hydraulic power -->
			<test value="0">
				/systems/failures/fctl/ths-jam eq 1
			</test>
			<test logic="OR" value="0.25">
				/systems/hydraulic/yellow-psi ge 1500
				/systems/hydraulic/green-psi ge 1500
				/systems/acconfig/autoconfig-running eq 1
			</test>
		</switch>
		
		<aerosurface_scale name="hydraulics/stabilizer/cmd-deg">
			<input>/controls/flight/elevator-trim</input>
			<domain>
				<min>-1.0</min>
				<max>0.296296</max>
			</domain>
			<range>
				<min>-13.5</min>
				<max>4.0</max>
			</range>
		</aerosurface_scale>
		
		<actuator name="hydraulics/stabilizer/final-actuator">
			<input>hydraulics/stabilizer/cmd-deg</input>
			<rate_limit>hydraulics/stabilizer/rate</rate_limit>
			<lag>22.5</lag>
			<output>hydraulics/stabilizer/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="Rudder">
		
		<switch name="hydraulics/rudder/pressure-switch-or">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/hydraulic/green-psi ge 1500
				/systems/hydraulic/blue-psi ge 1500
				/systems/hydraulic/yellow-psi ge 1500
			</test>
		</switch>
		
		<switch name="/systems/fctl/yawdamper-1-active">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/fctl/fac1-healthy-signal eq 1
				/systems/hydraulic/green-psi ge 1500
				<test logic="OR">
					/systems/navigation/adr/operating-1 eq 1
					/systems/navigation/adr/operating-3 eq 1
				</test>
				/systems/failures/fctl/yaw-damper-1 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/yawdamper-2-active">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/fctl/fac2-healthy-signal eq 1
				/systems/hydraulic/yellow-psi ge 1500
				<test logic="OR">
					/systems/navigation/adr/operating-2 eq 1
					/systems/navigation/adr/operating-3 eq 1
				</test>
				/systems/failures/fctl/yaw-damper-2 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/yawdamper-active">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/fctl/yawdamper-1-active eq 1
				/systems/fctl/yawdamper-2-active eq 1
			</test>
		</switch>
		
		<switch name="hydraulics/rudder/trim-autopilot">
			<default value="0"/>
			<test logic="AND" value="/controls/flight/rudder-trim">
				/it-autoflight/output/ap1 eq 0
				/it-autoflight/output/ap2 eq 0
			</test>
		</switch>
		
		<pure_gain name="hydraulics/rudder/trim-cmd-deg">
			<input>hydraulics/rudder/trim-autopilot</input>
			<gain>20</gain>
		</pure_gain>
		
		<switch name="hydraulics/rudder/trim-rate">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					/systems/electrical/bus/dc-ess ge 25
					/systems/fctl/fac1-healthy-signal eq 1
				</test>
				<test logic="AND">
					/systems/electrical/bus/dc-2 ge 25
					/systems/fctl/fac2-healthy-signal eq 1
				</test>
			</test>
		</switch>
		
		<actuator name="hydraulics/rudder/trim-deg">
			<input>hydraulics/rudder/trim-cmd-deg</input>
			<rate_limit>hydraulics/rudder/trim-rate</rate_limit>
		</actuator>
		
		<aerosurface_scale name="hydraulics/rudder/trim-norm">
			<input>hydraulics/rudder/trim-deg</input>
			<domain>
				<min>-20</min>
				<max> 20</max>
			</domain>
			<range>
				<min>-0.8</min>
				<max>0.8</max>
			</range>
		</aerosurface_scale>
		
		<summer name="hydraulics/rudder/summer">
			<input>fbw/rudder-output</input>
			<input>hydraulics/rudder/trim-norm</input>
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
		</summer>
		
		<fcs_function name="hydraulics/rudder/swing-deg">
			<function>
				<product>
					<property>hydraulics/rudder-swing</property>
					<sin>
						<toradians><difference>
							<property>/orientation/heading-deg</property>
							<property>/environment/wind-from-heading-deg</property>
						</difference></toradians>
					</sin>
					<property>/environment/wind-speed-kt</property>
					<value>1.6666</value>
				</product>
			</function>
			<clipto>
				<min>-25.0</min>
				<max>25.0</max>
			</clipto>
		</fcs_function>
		
		<aerosurface_scale name="hydraulics/rudder/swing-norm">
			<input>hydraulics/rudder/swing-deg</input>
			<domain>
				<min>-25</min>
				<max> 25</max>
			</domain>
			<range>
				<min>-1.0</min>
				<max>1.0</max>
			</range>
		</aerosurface_scale>
		
		<switch name="hydraulics/rudder/switch">
			<default value="hydraulics/rudder/swing-norm"/>
			<test logic="AND" value="hydraulics/rudder/summer">
				hydraulics/rudder/pressure-switch-or ne 0
			</test>
			<clipto>
				<min>fbw/yaw/max-deg-scale-neg</min>
				<max>fbw/yaw/max-deg-scale</max>
			</clipto>
		</switch>
		
		<pure_gain name="hydraulics/rudder/cmd-deg">
			<input>hydraulics/rudder/switch</input>
			<gain>25</gain>
		</pure_gain>
		
		<switch name="hydraulics/rudder/rate">
			<default value="80"/>
			<test logic="OR" value="25"> <!-- returns to center from centering spring / damping / aero -->
				hydraulics/rudder/pressure-switch-or eq 0
			</test>
		</switch>
		
		<actuator name="hydraulics/rudder/final-actuator">
			<input>hydraulics/rudder/cmd-deg</input>
			<rate_limit>hydraulics/rudder/rate</rate_limit>
			<lag>25.5</lag>
			<output>hydraulics/rudder/final-deg</output>
		</actuator>
	
	</channel>
	
	<channel name="FADEC">
		
		<lag_filter name="fcs/throttle1">
			<input>/controls/engines/engine[0]/throttle-output</input>
			<c1>0.95</c1>
			<output>fcs/throttle-pos-norm[0]</output>
		</lag_filter>
		
		<lag_filter name="fcs/throttle2">
			<input>/controls/engines/engine[1]/throttle-output</input>
			<c1>0.95</c1>
			<output>fcs/throttle-pos-norm[1]</output>
		</lag_filter>
		
		<lag_filter name="fcs/n1-actual1">
			<input>/engines/engine[0]/n1</input>
			<c1>2.25</c1>
			<output>/engines/engine[0]/n1-actual</output>
			<output>/engines/engine[3]/n1</output>
		</lag_filter>
		
		<lag_filter name="fcs/n1-actual2">
			<input>/engines/engine[1]/n1</input>
			<c1>2.25</c1>
			<output>/engines/engine[1]/n1-actual</output>
			<output>/engines/engine[4]/n1</output>
		</lag_filter>
		
		<lag_filter name="fcs/n2-actual1">
			<input>/engines/engine[0]/n2</input>
			<c1>2.25</c1>
			<output>/engines/engine[0]/n2-actual</output>
			<output>/engines/engine[3]/n2</output>
		</lag_filter>
		
		<lag_filter name="fcs/n2-actual2">
			<input>/engines/engine[1]/n2</input>
			<c1>2.25</c1>
			<output>/engines/engine[1]/n2-actual</output>
			<output>/engines/engine[4]/n2</output>
		</lag_filter>
		
		<lag_filter name="fcs/throttle-lever[0]">
			<input>/controls/engines/engine[0]/throttle-lever</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/throttle-lever[1]">
			<input>/controls/engines/engine[1]/throttle-lever</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/reverse-lever[0]">
			<input>/controls/engines/engine[0]/reverser</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/reverse-lever[1]">
			<input>/controls/engines/engine[1]/reverser</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/reverse-thr-lever[0]">
			<input>/controls/engines/engine[0]/throttle-rev</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/reverse-thr-lever[1]">
			<input>/controls/engines/engine[1]/throttle-rev</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/engine-cutoff[0]">
			<input>/controls/engines/engine[0]/cutoff-switch</input>
			<c1>20</c1>
		</lag_filter>
		
		<lag_filter name="fcs/engine-cutoff[1]">
			<input>/controls/engines/engine[1]/cutoff-switch</input>
			<c1>20</c1>
		</lag_filter>
	
	</channel>
	
	<channel name="SFCC"> <!-- 40 for IAE, 35 for CFM/PW is simulated here properly, do NOT change it into seperate unless you like buggy behavior! -->
		
		<switch name="/controls/flight/flaps-input">
			<default value="0"/> <!-- 0 -->
			<test logic="AND" value="1"> <!-- 1/1+F -->
				/controls/flight/flaps ge 0.2
				/controls/flight/flaps lt 0.4
			</test>
			<test logic="AND" value="2"> <!-- 2 -->
				/controls/flight/flaps ge 0.4
				/controls/flight/flaps lt 0.6
			</test>
			<test logic="AND" value="3"> <!-- 3 -->
				/controls/flight/flaps ge 0.6
				/controls/flight/flaps lt 0.8
			</test>
			<test logic="AND" value="4"> <!-- FULL -->
				/controls/flight/flaps ge 0.8
			</test>
			<output>/controls/flight/flaps-input-out</output>
		</switch>
		
		<switch name="/controls/flight/flaps-1f-enable"> <!-- Flip flop, controls 1 vs 1+F -->
			<default value="/controls/flight/flaps-1f-enable"/>
			<test logic="OR" value="0"> <!-- Reset -->
				/controls/flight/flaps-input ne 1
				/instrumentation/airspeed-indicator/indicated-speed-kt ge 210
			</test>
			<test logic="AND" value="1"> <!-- 0 to 1 -->
				/controls/flight/flaps-input eq 1
				/controls/flight/flaps-input-last eq 0
				/instrumentation/airspeed-indicator/indicated-speed-kt le 100
			</test>
			<test logic="AND" value="1"> <!-- 2/3/FULL to 1 -->
				/controls/flight/flaps-input eq 1
				/controls/flight/flaps-input-last ge 2
				/instrumentation/airspeed-indicator/indicated-speed-kt lt 210
			</test>
		</switch>
		
		<pure_gain name="/controls/flight/flaps-input-last"> <!-- This is very important for the logic of the flipflop, do not refactor removing this -->
			<input>/controls/flight/flaps-input</input>
			<gain>1.0</gain>
		</pure_gain>
		
		<switch name="/controls/flight/flaps-pos"> <!-- Split 1 and 1+F -->
			<default value="0"/> <!-- 0 -->
			<test logic="AND" value="1"> <!-- 1 -->
				/controls/flight/flaps ge 0.2
				/controls/flight/flaps lt 0.4
				/controls/flight/flaps-1f-enable ne 1
			</test>
			<test logic="AND" value="2"> <!-- 1+F -->
				/controls/flight/flaps ge 0.2
				/controls/flight/flaps lt 0.4
				/controls/flight/flaps-1f-enable eq 1
			</test>
			<test logic="AND" value="3"> <!-- 2 -->
				/controls/flight/flaps ge 0.4
				/controls/flight/flaps lt 0.6
			</test>
			<test logic="AND" value="4"> <!-- 3 -->
				/controls/flight/flaps ge 0.6
				/controls/flight/flaps lt 0.8
			</test>
			<test logic="AND" value="5"> <!-- FULL -->
				/controls/flight/flaps ge 0.8
			</test>
			<output>/controls/flight/flaps-input-out</output>
		</switch>
		
		<switch name="/controls/flight/flaps-cmd">
			<default value="0"/>
			<test value="10"> <!-- 1+F -->
				/controls/flight/flaps-pos eq 2
			</test>
			<test value="15"> <!-- 2 -->
				/controls/flight/flaps-pos eq 3
			</test>
			<test value="20"> <!-- 3 -->
				/controls/flight/flaps-pos eq 4
			</test>
			<test value="40"> <!-- Or 35 --> <!-- FULL -->
				/controls/flight/flaps-pos eq 5
			</test>
			<clipto>
				<min>0</min>
				<max>/options/maxflap</max>
			</clipto>
		</switch>
		
		<switch name="/controls/flight/slats-cmd">
			<default value="0"/>
			<test value="27"> <!-- FULL -->
				/controls/flight/flaps-input eq 4
			</test>
			<test value="22"> <!-- 2/3 -->
				/controls/flight/flaps-input ge 2
			</test>
			<test value="18"> <!-- 1/1+F -->
				/controls/flight/flaps-input eq 1
			</test>
		</switch>
		
		<lag_filter name="fcs/flap-lever">
			<input>/controls/flight/flaps-input</input>
			<c1>20</c1>
		</lag_filter>
		
		<switch name="fcs/sfcc/unit1-avail">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/electrical/bus/dc-ess ge 25
			</test>
		</switch>
		
		<switch name="fcs/sfcc/unit2-avail">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
	
	</channel>
	
	<channel name="Flaps"> <!-- 40 for IAE, 35 for CFM/PW is simulated here properly, do NOT change it into seperate unless you like buggy behavior! -->
		
		<switch name="fcs/flap-pos-rate">
			<default value="0.0"/>
			<test value="100">
				/systems/acconfig/autoconfig-running eq 1
			</test>
			<test logic="AND" value="1.16666666">
				/systems/hydraulic/green-psi ge 1500
				/systems/hydraulic/yellow-psi ge 1500
				fcs/sfcc/unit1-avail eq 1
				fcs/sfcc/unit2-avail eq 1
			</test>
			<test logic="AND" value="0.58333333">
				/systems/hydraulic/green-psi ge 1500
				fcs/sfcc/unit1-avail eq 1
				fcs/sfcc/unit2-avail eq 0
			</test>
			<test logic="AND" value="0.58333333">
				/systems/hydraulic/yellow-psi ge 1500
				fcs/sfcc/unit1-avail eq 0
				fcs/sfcc/unit2-avail eq 1
			</test>
			<test logic="AND" value="0.58333333">
				/systems/hydraulic/green-psi ge 1500
				/systems/hydraulic/yellow-psi lt 1500
			</test>
			<test logic="AND" value="0.58333333">
				/systems/hydraulic/green-psi lt 1500
				/systems/hydraulic/yellow-psi ge 1500
			</test>
		</switch>
		
		<actuator name="rubbish/flap-pos-deg">
			<input>/controls/flight/flaps-cmd</input>
			<rate_limit>fcs/flap-pos-rate</rate_limit>
			<output>fcs/flap-pos-deg</output>
		</actuator>
		
		<aerosurface_scale name="rubbish/flap-pos-norm">
			<input>fcs/flap-pos-deg</input>
			<domain>
				<min>0</min>
				<max>40</max>
			</domain>
			<range>
				<min>0</min>
				<max>1</max>
			</range>
			<output>fcs/flap-pos-norm</output>
		</aerosurface_scale>
	
	</channel>
	
	<channel name="Slats">
		
		<switch name="fcs/slat-locked-cmd">
			<default value="0"/>
			<test logic="AND" value="1">
				fcs/slat-locked-cmd eq 1
				<test logic="OR">
					/gear/gear[1]/wow ne 1
					/velocities/airspeed-kt ge 60
				</test>
				<test logic="OR">
					aero/alpha-deg gt 7.6
					/systems/navigation/adr/output/cas-1 lt 154
				</test>
			</test>
			<test logic="AND" value="1">
				fcs/slat-locked-cmd eq 0
				/controls/flight/flaps-input ne 0
				<test logic="OR">
					/gear/gear[1]/wow ne 1
					/velocities/airspeed-kt ge 60
				</test>
				<test logic="OR">
					aero/alpha-deg gt 8.5
					/systems/navigation/adr/output/cas-1 lt 148
				</test>
			</test>
		</switch>
		
		<switch name="fcs/slat-locked">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/flight/flaps-input eq 0
				fcs/slat-pos-deg le 18.01
				fcs/slat-locked-cmd eq 1
			</test>
		</switch>
		
		<switch name="fcs/slat-pos-rate">
			<default value="0.0"/>
			<test logic="AND" value="0.0">
				/controls/flight/flaps-input eq 0
				fcs/slat-pos-deg le 18.01
				fcs/slat-locked eq 1
			</test>
			<test value="100">
				/systems/acconfig/autoconfig-running eq 1
			</test>
			<test logic="AND" value="1.35">
				/systems/hydraulic/blue-psi ge 1500
				/systems/hydraulic/green-psi ge 1500
				fcs/sfcc/unit1-avail eq 1
				fcs/sfcc/unit2-avail eq 1
			</test>
			<test logic="AND" value="0.675">
				/systems/hydraulic/blue-psi ge 1500
				fcs/sfcc/unit1-avail eq 1
				fcs/sfcc/unit2-avail eq 0
			</test>
			<test logic="AND" value="0.675">
				/systems/hydraulic/green-psi ge 1500
				fcs/sfcc/unit1-avail eq 0
				fcs/sfcc/unit2-avail eq 1
			</test>
			<test logic="AND" value="0.675">
				/systems/hydraulic/blue-psi ge 1500
				/systems/hydraulic/green-psi lt 1500
			</test>
			<test logic="AND" value="0.675">
				/systems/hydraulic/blue-psi lt 1500
				/systems/hydraulic/green-psi ge 1500
			</test>
		</switch>
		
		<actuator name="rubbish/slat-pos-deg">
			<input>/controls/flight/slats-cmd</input>
			<rate_limit>fcs/slat-pos-rate</rate_limit>
			<output>fcs/slat-pos-deg</output>
		</actuator>
		
		<aerosurface_scale name="rubbish/slat-pos-norm">
			<input>fcs/slat-pos-deg</input>
			<domain>
				<min>0</min>
				<max>27</max>
			</domain>
			<range>
				<min>0</min>
				<max>1</max>
			</range>
			<output>fcs/slat-pos-norm</output>
		</aerosurface_scale>
	
	</channel>
	
	<channel name="Landing Gear">
		
		<switch name="gear/gear-cmd-switch">
			<default value="gear/gear-cmd-norm"/>
			<test logic="OR" value="gear/gear-pos-norm">
				/systems/failures/gear eq 1
			</test>
		</switch>
		
		<kinematic name="rubbish/gear-pos-norm">
			<input>gear/gear-cmd-switch</input>
			<traverse>
				<setting>
					<position>0</position>
					<time>0</time>
				</setting>
				<setting>
					<position>1</position>
					<time>10</time>
				</setting>
			</traverse>
			<output>gear/gear-pos-norm</output>
		</kinematic>
	
	</channel>
	
	<channel name="Tiller">
		
		<switch name="/controls/gear/steering-switched">
			<default value="/controls/flight/rudder"/>
			<test value="0">
				/gear/gear[0]/wow ne 1
			</test>
			<test value="/controls/gear/steering">
				/systems/acconfig/options/seperate-tiller-axis eq 1
			</test>
			<test value="/controls/flight/aileron">
				/controls/flight/aileron-drives-tiller eq 1
			</test>
		</switch>
		
		<scheduled_gain name="fbw/tiller-handle-scheduled">
			<input>/controls/gear/steering-switched</input>
			<table>
				<independentVar lookup="row">/velocities/groundspeed-kt</independentVar>
				<independentVar lookup="column">/systems/acconfig/options/seperate-tiller-axis</independentVar>
				<tableData>
					      0  1
					 0.5  0  0
					 1.0  1  1
					20.0  1  1
					70.0  0  1
				</tableData>
			</table>
		</scheduled_gain>
		
		<lag_filter name="fbw/tiller-handle">
			<input>fbw/tiller-handle-scheduled</input>
			<c1>20</c1>
		</lag_filter>
		
		<pure_gain name="/controls/gear/steering-deg">
			<input>/controls/gear/steering</input>
			<gain>75</gain>
		</pure_gain>
		
		<pure_gain name="hydraulics/tiller/autopush-cmd-deg">
			<input>hydraulics/tiller/autopush-cmd</input>
			<gain>75</gain>
		</pure_gain>
		
		<scheduled_gain name="hydraulics/tiller/fmgc-cmd-deg">
			<input>fbw/fmgc/yaw-cmd</input>
			<table>
				<independentVar lookup="row">/velocities/groundspeed-kt</independentVar>
				<tableData>
					  0.5  0
					  1.0  6
					 40.0  6
					130.0  0
				</tableData>
			</table>
		</scheduled_gain>
		
		<switch name="hydraulics/tiller/rudder-cmd-input">
			<default value="/controls/flight/rudder"/>
			<test value="/controls/flight/aileron">
				/controls/flight/aileron-drives-tiller eq 1
			</test>
		</switch>
		
		<pure_gain name="hydraulics/tiller/rudder-cmd-input-deg">
			<input>hydraulics/tiller/rudder-cmd-input</input>
			<gain>75</gain>
		</pure_gain>
		
		<fcs_function name="hydraulics/tiller/rudder-cmd-deg"> <!-- Combines rudder and tiller into just rudder -->
			<function>
				<table>
					<independentVar lookup="row">zero</independentVar> <!-- Take advantage of the table lookup to interpolate -->
					<independentVar lookup="column">hydraulics/tiller/rudder-cmd-input-deg</independentVar>
					<independentVar lookup="table">/velocities/groundspeed-kt</independentVar>
					<tableData breakPoint="0.5">
						  -75 -66 -40 -20 -1  1  20  40  66  75
						0   0   0   0   0  0  0   0   0   0   0
						1   0   0   0   0  0  0   0   0   0   0
					</tableData>
					<tableData breakPoint="1.0">
						  -75 -66 -40 -20 -1  1  20  40  66  75
						0 -75 -45 -15  -4  0  0   4  15  45  75
						1 -75 -45 -15  -4  0  0   4  15  45  75
					</tableData>
					<tableData breakPoint="20.0">
						  -75 -66 -40 -20 -1  1  20  40  66  75
						0 -75 -45 -15  -4  0  0   4  15  45  75
						1 -75 -45 -15  -4  0  0   4  15  45  75
					</tableData>
					<tableData breakPoint="40.0">
						  -75  0  75
						0  -6  0  6
						1  -6  0  6
					</tableData>
					<tableData breakPoint="130.0">
						  -75  0  75
						0   0  0  0
						1   0  0  0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="hydraulics/tiller/tiller-cmd-deg">
			<function>
				<sum>
					<table>
						<independentVar lookup="row">/velocities/groundspeed-kt</independentVar>
						<independentVar lookup="column">/controls/gear/steering-deg</independentVar>
						<tableData>
							     -75 -66 -40 -20 -1  1  20  40  66  75
							 0.5   0   0   0   0  0  0   0   0   0   0
							 1.0 -75 -45 -15  -4  0  0   4  15  45  75
							20.0 -75 -45 -15  -4  0  0   4  15  45  75
							70.0   0   0   0   0  0  0   0   0   0   0
						</tableData>
					</table>
					<product>
						<property>hydraulics/tiller/rudder-cmd-input</property>
						<table>
							<independentVar lookup="row">/velocities/groundspeed-kt</independentVar>
							<tableData>
								  0.5  0
								  1.0  6
								 40.0  6
								130.0  0
							</tableData>
						</table>
					</product>
				</sum>
			</function>
		</fcs_function>
		
		<switch name="hydraulics/tiller/cmd-deg">
			<default value="hydraulics/tiller/rudder-cmd-deg"/>
			<test value="0">
				/gear/gear[0]/wow ne 1
			</test>
			<test value="hydraulics/tiller/autopush-cmd-deg">
				/sim/model/autopush/connected eq 1
			</test>
			<test value="hydraulics/tiller/fmgc-cmd-deg">
				fbw/fmgc/enabled eq 1
			</test>
			<test value="hydraulics/tiller/tiller-cmd-deg">
				/systems/acconfig/options/seperate-tiller-axis eq 1
			</test>
			<clipto>
				<min>-75</min>
				<max>75</max>
			</clipto>
		</switch>
		
		<switch name="hydraulics/tiller/elec-pwr">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/electrical/bus/ac-1 ge 110
				/systems/electrical/bus/ac-2 ge 110
				/systems/electrical/bus/dc-1 ge 25
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
		
		<switch name="hydraulics/tiller/hyd-pwr">
			<default value="0"/>
			<test logic="AND" value="1">
				position/wow eq 1
				hydraulics/tiller/elec-pwr eq 1
				/systems/hydraulic/yellow-psi ge 1500
				/sim/model/autopush/connected eq 0
				/controls/gear/nws-switch eq 1
				<test logic="OR">
					/engines/engine[0]/state eq 3
					/engines/engine[1]/state eq 3
				</test>
			</test>
		</switch>
		
		<switch name="fcs/steer-rate">
			<default value="0"/>
			<test logic="OR" value="75">
				/sim/model/autopush/connected eq 1
				/systems/acconfig/autoconfig-running eq 1
			</test>
			<test logic="OR" value="12">
				hydraulics/tiller/hyd-pwr eq 1
			</test>
		</switch>
		
		<actuator name="fcs/steer-deg">
			<input>hydraulics/tiller/cmd-deg</input>
			<rate_limit>fcs/steer-rate</rate_limit>
			<output>fcs/steer-pos-deg[0]</output>
		</actuator>
		
		<switch name="fcs/pushback-steer-deg">
			<default value="0"/>
			<test value="fcs/steer-deg">
				/sim/model/autopush/connected eq 1
			</test>
		</switch>
	
	</channel>
	
	<channel name="Brakes">
		
		<lag_filter name="fcs/brake-lever">
			<input>/controls/gear/brake-parking</input>
			<c1>20</c1>
		</lag_filter>
		
		<actuator name="fcs/brake-left">
			<input>/controls/gear/brake-left</input>
			<rate_limit>2</rate_limit>
		</actuator>
		
		<actuator name="fcs/brake-right">
			<input>/controls/gear/brake-right</input>
			<rate_limit>2</rate_limit>
		</actuator>
		
		<switch name="fcs/brake-avail">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/hydraulic/green-psi ge 2500
				/systems/hydraulic/yellow-psi ge 1000
				/systems/hydraulic/yellow-accumulator-psi gt 0
			</test>
			<output>fcs/brake-avail</output>
		</switch>
		
		<fcs_function name="fcs/left-brake-input">
			<function>
				<product>
					<property>fcs/brake-avail</property>
					<max>
						<property>/services/chocks/enable</property>
						<property>fcs/brake-left</property>
						<product>
							<property>/controls/autobrake/brake-left</property>
							<property>/controls/autobrake/active</property>
						</product>
						<property>/controls/gear/brake-parking</property>
					</max>
				</product>
			</function>
			<clipto>
				<min>0</min>
				<max>1</max>
			</clipto>
		</fcs_function>
		
		<actuator name="fcs/left-brake-actuator">
			<input>fcs/left-brake-input</input>
			<rate_limit>10</rate_limit>
		</actuator>
		
		<switch name="rubbish/left-brake-cmd-norm">
			<default value="fcs/left-brake-actuator"/>
			<test value="1">
				/systems/acconfig/autoconfig-running eq 1
			</test>
			<output>fcs/left-brake-cmd-norm</output>
		</switch>
		
		<fcs_function name="fcs/right-brake-input">
			<function>
				<product>
					<property>fcs/brake-avail</property>
					<max>
						<property>/services/chocks/enable</property>
						<property>fcs/brake-right</property>
						<product>
							<property>/controls/autobrake/brake-right</property>
							<property>/controls/autobrake/active</property>
						</product>
						<property>/controls/gear/brake-parking</property>
					</max>
				</product>
			</function>
			<clipto>
				<min>0</min>
				<max>1</max>
			</clipto>
		</fcs_function>
		
		<actuator name="fcs/right-brake-actuator">
			<input>fcs/right-brake-input</input>
			<rate_limit>10</rate_limit>
		</actuator>
		
		<switch name="rubbish/right-brake-cmd-norm">
			<default value="fcs/right-brake-actuator"/>
			<test value="1">
				/systems/acconfig/autoconfig-running eq 1
			</test>
			<output>fcs/right-brake-cmd-norm</output>
		</switch>
	
	</channel>
	
	<channel name="Wipers">
	
		<switch name="fcs/left-wiper-cmd">
			<default value="0"/>
			<test logic="AND" value="0">
				fcs/left-wiper-pos-norm gt 0.001
				fcs/left-wiper-has-been-1 eq 1
			</test>
			<test logic="AND" value="1">
				fcs/left-wiper-has-been-1 eq 0
				/controls/switches/wiperLspd ne 0
			</test>
		</switch>
		
		<switch name="fcs/left-wiper-has-been-1">
			<default value="0"/>
			<test value="0">
				fcs/left-wiper-pos-norm le 0.001
			</test>
			<test value="1">
				fcs/left-wiper-has-been-1 eq 1
			</test>
			<test value="1">
				fcs/left-wiper-pos-norm ge 0.999
			</test>
		</switch>
		
		<switch name="fcs/left-wiper-speed">
			<default value="0"/>
			<test logic="AND" value="fcs/left-wiper-speed">
				/controls/switches/wiperLspd eq 0
				fcs/left-wiper-pos-norm ge 0.001
				/systems/electrical/bus/dc-1 ge 25
			</test>
			<test logic="AND" value="4">
				/controls/switches/wiperLspd eq 1
				/systems/electrical/bus/dc-1 ge 25
			</test>
			<test logic="AND" value="7">
				/controls/switches/wiperLspd eq 2
				/systems/electrical/bus/dc-1 ge 25
			</test>
		</switch>
		
		<actuator name="fcs/left-wiper-pos-norm">
			<input>fcs/left-wiper-cmd</input>
			<rate_limit>fcs/left-wiper-speed</rate_limit>
		</actuator>
		
		<switch name="fcs/right-wiper-cmd">
			<default value="0"/>
			<test logic="AND" value="0">
				fcs/right-wiper-pos-norm gt 0.001
				fcs/right-wiper-has-been-1 eq 1
			</test>
			<test logic="AND" value="1">
				fcs/right-wiper-has-been-1 eq 0
				/controls/switches/wiperRspd ne 0
			</test>
		</switch>
		
		<switch name="fcs/right-wiper-has-been-1">
			<default value="0"/>
			<test value="0">
				fcs/right-wiper-pos-norm le 0.001
			</test>
			<test value="1">
				fcs/right-wiper-has-been-1 eq 1
			</test>
			<test value="1">
				fcs/right-wiper-pos-norm ge 0.999
			</test>
		</switch>
		
		<switch name="fcs/right-wiper-speed">
			<default value="0"/>
			<test logic="AND" value="fcs/right-wiper-speed">
				/controls/switches/wiperRspd eq 0
				fcs/right-wiper-pos-norm ge 0.001
				/systems/electrical/bus/dc-2 ge 25
			</test>
			<test logic="AND" value="4">
				/controls/switches/wiperRspd eq 1
				/systems/electrical/bus/dc-2 ge 25
			</test>
			<test logic="AND" value="7">
				/controls/switches/wiperRspd eq 2
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
		
		<actuator name="fcs/right-wiper-pos-norm">
			<input>fcs/right-wiper-cmd</input>
			<rate_limit>fcs/right-wiper-speed</rate_limit>
		</actuator>
		
	</channel>

</system>