<?xml version="1.0"?>

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

<system name="A320: FBW">
	
	<property value="0">fbw/roll/pid</property>
	<property value="0">fbw/pitch/g-pi</property>
	<property value="0">fbw/pitch/pid</property>
	<property value="0">fbw/yaw/tc-pd</property>
	<property value="0">fbw/spoiler-output</property>
	<property value="1">fbw/mixer/sidestick-gain-feedback</property>
	
	<!-- Default gains for tuning -->
	<property value="0">fbw/roll/p-gain</property>
	<property value="0">fbw/roll/i-gain</property>
	<property value="0">fbw/roll/d-gain</property>
	<property value="0">fbw/pitch/p-gain</property>
	<property value="0">fbw/pitch/i-gain</property>
	<property value="0">fbw/pitch/d-gain</property>
	<property value="0">fbw/yaw/yd-p-gain</property>
	<property value="0">fbw/yaw/tc-p-gain</property>
	<property value="0">fbw/yaw/tc-d-gain</property>
	
	<!-- FMGC stuff -->
	<property value="0">fbw/fmgc/roll-cmd</property>
	<property value="0">fbw/fmgc/pitch-cmd</property>
	<property value="0">fbw/fmgc/yaw-cmd</property>
	
	<channel name="Libraries">
		
		<switch name="fbw/roll/gain-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				position/wow eq 1
				/it-fbw/law ne 0
			</test>
		</switch>
		
		<switch name="fbw/pitch/gain-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				position/wow eq 1
				/it-fbw/law eq 2
				/it-fbw/law eq 3
			</test>
		</switch>
		
		<switch name="fbw/yaw/gain-switch"> <!-- disable auto-trim -->
			<default value="0"/>
			<test logic="OR" value="1">
				position/wow eq 1
				<test logic="AND">
					/it-fbw/yaw-law eq 2
					/it-fbw/law ne 0
				</test>
			</test>
		</switch>
		
		<switch name="fbw/fmgc/enabled">
			<default value="0"/>
			<test logic="OR" value="1">
				/it-autoflight/output/ap1 eq 1
				/it-autoflight/output/ap2 eq 1
			</test>
		</switch>
		
		<fcs_function name="fbw/roll/p-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/roll/gain-switch</independentVar>
					<tableData>
						     0     1  
						140 -20.0  0.0
						350  -5.0  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/roll/i-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/roll/gain-switch</independentVar>
					<tableData>
						     0     1
						140 -35.0  0.0
						350 -10.0  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/roll/d-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/roll/gain-switch</independentVar>
					<tableData>
						     0    1
						140 -2.5  0.0
						350 -0.5  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/p-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/pitch/gain-switch</independentVar>
					<tableData>
						     0   1  
						140  28  0
						350  20  0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/i-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/pitch/gain-switch</independentVar>
					<tableData>
						     0   1
						140  60  0
						350  40  0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/d-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/pitch/gain-switch</independentVar>
					<tableData>
						     0    1
						140  2.0  0.0
						350  0.4  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/yaw/yd-p-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/yaw/gain-switch</independentVar>
					<tableData>
						     0    1
						140 -7.0  0.0
						350 -1.2  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/yaw/tc-p-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/yaw/gain-switch</independentVar>
					<tableData>
						     0    1
						140  3.0  0.0
						350  1.5  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/yaw/tc-d-gain">
			<function>
				<table>
					<independentVar lookup="row">velocities/vc-kts</independentVar>
					<independentVar lookup="column">fbw/yaw/gain-switch</independentVar>
					<tableData>
						     0    1
						140  6.0  0.0
						350  3.0  0.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<pid name="fbw/pitch/vc-kts-rate">
			<descripton>Use D only to calculate rate of IAS</descripton>
			<input>velocities/vc-kts</input>
			<kp>0.0</kp>
			<ki>0.0</ki>
			<kd>1.0</kd>
		</pid>
		
		<lag_filter name="fbw/pitch/vc-kts-rate-lag">
			<input>fbw/pitch/vc-kts-rate</input>
			<c1>1.0</c1>
		</lag_filter>
		
		<switch name="fbw/mixer/rate-limit">
			<default value="fbw/mixer/rate-limit"/>
			<test logic="AND" value="0.5"> <!-- 2 seconds -->
				position/wow eq 1
				fbw/mixer/sidestick-gain-feedback eq 1
			</test>
			<test logic="AND" value="100"> <!-- Unlimited -->
				position/wow eq 1
				fbw/mixer/sidestick-gain-feedback ne 1
			</test>
			<test logic="AND" value="100"> <!-- Unlimited -->
				position/wow eq 0
				fbw/mixer/sidestick-gain-feedback eq 0
			</test>
		</switch>
		
		<actuator name="fbw/mixer/sidestick-gain">
			<input>position/wow</input>
			<rate_limit>fbw/mixer/rate-limit</rate_limit>
			<output>fbw/mixer/sidestick-gain-feedback</output>
		</actuator>
		
		<fcs_function name="fbw/mixer/computer-gain">
			<function>
				<table>
					<independentVar lookup="row">fbw/mixer/sidestick-gain</independentVar>
					<tableData>
						0  1
						1  0
					</tableData>
				</table>
			</function>
		</fcs_function>
	
	</channel>
	
	<channel name="Computers">
		
		<switch name="/systems/fctl/lights/elac1-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/elac1 eq 1
				/systems/fctl/elac1 eq 0
			</test>
		</switch>
	
		<switch name="/systems/fctl/elac1">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/elac1 eq 1
				/systems/failures/fctl/elac1 eq 0
				<test logic="OR">
					/systems/electrical/bus/dc-ess ge 25
					/systems/electrical/bus/dc-hot-1 ge 25
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/elac2-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/elac2 eq 1
				/systems/fctl/elac2 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/elac2">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/elac2 eq 1
				/systems/failures/fctl/elac2 eq 0
				<test logic="OR">
					/systems/electrical/bus/dc-2 ge 25
					/systems/electrical/bus/dc-hot-2 ge 25
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/sec1-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec1 eq 1
				/systems/fctl/sec1 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/sec1">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec1 eq 1
				/systems/failures/fctl/sec1 eq 0
				<test logic="OR">
					/systems/electrical/bus/dc-ess ge 25
					/systems/electrical/bus/dc-hot-1 ge 25
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/sec2-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec2 eq 1
				/systems/fctl/sec2 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/sec2">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec2 eq 1
				/systems/failures/fctl/sec2 eq 0
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/sec3-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec3 eq 1
				/systems/fctl/sec3 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/sec3">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/sec3 eq 1
				/systems/failures/fctl/sec3 eq 0
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1-healthy">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac1 eq 1
				/systems/failures/fctl/fac1 eq 0
				<test logic="OR">
					/systems/electrical/bus/ac-ess ge 110
					/systems/electrical/bus/dc-ess-shed ge 25
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1-healthy-latch-set">
			<default value="0"/>
			<test logic="AND" value="1">
				/gear/gear[0]/wow eq 0
				/controls/fctl/switches/fac1 eq 1
				/systems/fctl/fac1-healthy eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1-healthy-latch-reset">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac1 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1-healthy-latch">
			<default value="/systems/fctl/fac1-healthy-latch"/>
			<test value="1">
				/systems/fctl/fac1-healthy-latch-set eq 1
			</test>
			<test value="0">
				/systems/fctl/fac1-healthy-latch-reset eq 1
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1-healthy-signal">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/fctl/fac1-healthy eq 1
				<test logic="OR">
					/systems/fctl/fac1-healthy-latch eq 0
					/gear/gear[0]/wow eq 1
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/fac1-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac1 eq 1
				/systems/fctl/fac1-healthy-signal eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac1">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac1 eq 1
				/systems/fctl/fac1-healthy eq 1
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-healthy">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac2 eq 1
				/systems/failures/fctl/fac2 eq 0
				<test logic="OR">
					/systems/electrical/bus/ac-2 ge 110
					/systems/electrical/bus/dc-2 ge 25
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-healthy-latch-set">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac2 eq 1
				/systems/fctl/fac2-healthy eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-healthy-latch-reset">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac2 eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-healthy-latch">
			<default value="/systems/fctl/fac2-healthy-latch"/>
			<test value="1">
				/gear/gear[0]/wow eq 0
				/systems/fctl/fac2-healthy-latch-set eq 1
			</test>
			<test value="0">
				/systems/fctl/fac2-healthy-latch-reset eq 1
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-healthy-signal">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/fctl/fac2-healthy eq 1
				<test logic="OR">
					/systems/fctl/fac2-healthy-latch eq 0
					/gear/gear[0]/wow eq 1
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/lights/fac2-fault">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac2 eq 1
				/systems/fctl/fac2-healthy-signal eq 0
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2">
			<default value="0"/>
			<test logic="AND" value="1">
				/controls/fctl/switches/fac2 eq 1
				/systems/fctl/fac2-healthy eq 1
			</test>
		</switch>
		
	</channel>
	
	<channel name="FBW: Roll">
		
		<switch name="fbw/roll/a-i-f">
			<default value="/controls/flight/aileron"/>
			<test value="0">
				fbw/fmgc/enabled eq 1
			</test>
		</switch>
		
		<kinematic name="fbw/roll/a-i-k">
			<input>fbw/roll/a-i-f</input>
			<traverse>
				<setting>
					<position>-1</position>
					<time>0</time>
				</setting>
				<setting>
					<position>1</position>
					<time>0.7</time>
				</setting>
			</traverse>
			<output>/controls/flight/aileron-input-fast</output>
		</kinematic>
		
		<fcs_function name="fbw/roll/aileron-nul">
			<function>
				<table>
					<independentVar lookup="row">/controls/flight/aileron</independentVar>
					<tableData>
						-1.00 -1
						-0.04  0
						 0.04  0
						 1.00  1
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<switch name="fbw/roll/a-i-s">
			<default value="0"/>
			<test logic="AND" value="fbw/roll/aileron-nul">
				fbw/fmgc/enabled eq 0
			</test>
			<test logic="AND" value="fbw/fmgc/roll-cmd">
				position/wow eq 0
				fbw/fmgc/enabled eq 1
			</test>
		</switch>
		
		<kinematic name="fbw/roll/a-i">
			<input>fbw/roll/a-i-s</input>
			<traverse>
				<setting>
					<position>-1</position>
					<time>0</time>
				</setting>
				<setting>
					<position>1</position>
					<time>2.0</time>
				</setting>
			</traverse>
			<output>/controls/flight/aileron-input</output>
		</kinematic>
		
		<fcs_function name="fbw/roll/r-r-33">
			<function>
				<sum>
					<product>
						<property>fbw/roll/a-i</property>
						<value>0.261799</value>
					</product>
					<table>
						<independentVar lookup="row">attitude/roll-rad</independentVar>
						<independentVar lookup="column">fbw/roll/a-i</independentVar>
						<tableData>
							          -1         0         1
							-0.575959  0.261799  0.000000  0.000000
							-0.488692  0.000000  0.000000  0.000000
							 0.488692  0.000000  0.000000  0.000000
							 0.575959  0.000000  0.000000 -0.261799
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">attitude/roll-rad</independentVar>
						<tableData>
							-0.750492  0.261799
							-0.575959  0.000000
							 0.575959  0.000000
							 0.750492 -0.261799
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/roll/r-r-67">
			<function>
				<sum>
					<product>
						<property>fbw/roll/a-i</property>
						<value>0.261799</value>
					</product>
					<table>
						<independentVar lookup="row">attitude/roll-rad</independentVar>
						<independentVar lookup="column">fbw/roll/a-i</independentVar>
						<tableData>
							          -1.0       0.0       1.0
							-1.169370  0.261799  0.000000  0.000000
							-1.082100  0.000000  0.000000  0.000000
							 1.082100  0.000000  0.000000  0.000000
							 1.169370  0.000000  0.000000 -0.261799
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">attitude/roll-rad</independentVar>
						<tableData>
							-1.343900  0.261799
							-1.169370  0.000000
							 1.169370  0.000000
							 1.343900 -0.261799
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/roll/r-r-rb-f">
			<function>
				<table>
					<independentVar lookup="row">attitude/roll-rad</independentVar>
					<tableData>
						-1.169370  0.436332
						-0.698132  0.174533
						-0.575959  0.000000
						 0.575959  0.000000
						 0.698132 -0.174533
						 1.169370 -0.436332
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<switch name="fbw/roll/r-r-rb">
			<default value="fbw/roll/r-r-rb-f"/>
			<test logic="AND" value="fbw/roll/r-r-33">
				attitude/roll-rad lt 0
				fbw/roll/r-r-33 ge fbw/roll/r-r-rb-f
			</test>
			<test logic="AND" value="fbw/roll/r-r-33">
				attitude/roll-rad gt 0
				fbw/roll/r-r-33 le fbw/roll/r-r-rb-f
			</test>
		</switch>
		
		<fcs_function name="fbw/roll/r-r-os-nrb">
			<function>
				<sum>
					<product>
						<property>fbw/roll/a-i</property>
						<value>0.261799</value>
					</product>
					<table>
						<independentVar lookup="row">attitude/roll-rad</independentVar>
						<independentVar lookup="column">fbw/roll/a-i</independentVar>
						<tableData>
							          -1         0         1
							-0.698132  0.261799  0.000000  0.000000
							-0.610865  0.000000  0.000000  0.000000
							 0.610865  0.000000  0.000000  0.000000
							 0.698132  0.000000  0.000000 -0.261799
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/roll/r-r-os-rb">
			<function>
				<table>
					<independentVar lookup="row">attitude/roll-rad</independentVar>
					<tableData>
						-0.698132  0.436332
						-0.261799  0.174533
						 0.000000  0.000000
						 0.261799 -0.174533
						 0.698132 -0.436332
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<switch name="fbw/roll/rate-demand"> <!-- 15 deg/0.261799 rad per second -->
			<default value="0"/>
			<test logic="AND" value="fbw/roll/r-r-33">
				/it-fbw/roll-lim eq 33
				/it-fbw/roll-back ne 1
				/it-fbw/protections/overspeed ne 1
			</test>
			<test logic="AND" value="fbw/roll/r-r-67">
				/it-fbw/roll-lim eq 67
				/it-fbw/protections/overspeed ne 1
			</test>
			<test logic="AND" value="fbw/roll/r-r-rb">
				/it-fbw/roll-back eq 1
				/it-fbw/protections/overspeed ne 1
			</test>
			<test logic="AND" value="fbw/roll/r-r-os-nrb">
				/it-fbw/protections/overspeed eq 1
				/it-fbw/protections/overspeed-roll-back ne 1
			</test>
			<test logic="AND" value="fbw/roll/r-r-os-rb">
				/it-fbw/protections/overspeed eq 1
				/it-fbw/protections/overspeed-roll-back eq 1
			</test>
		</switch>
		
		<lag_filter name="fbw/roll/rate-demand-lag">
			<input>fbw/roll/rate-demand</input>
			<c1>16.4</c1>
		</lag_filter>
		
		<fcs_function name="fbw/roll/p-rad_sec">
			<function>
				<toradians>
					<property>/orientation/roll-rate-degps</property>
				</toradians>
			</function>
		</fcs_function>
		
		<switch name="fbw/roll/p-r_s-s">
			<default value="fbw/roll/p-rad_sec"/>
			<test value="0">
				gear/unit[0]/WOW eq 1
			</test>
		</switch>
		
		<summer name="fbw/roll/rate-error">
			<input>fbw/roll/p-r_s-s</input>
			<input>-fbw/roll/rate-demand-lag</input>
		</summer>
		
		<switch name="fbw/roll/trigger">
			<default value="0"/>
			<test value="-1">
				fbw/roll/gain-switch gt 0
			</test>
			<test logic="OR" value="1">
				fbw/roll/pid le -0.999
				fbw/roll/pid ge 0.999
			</test>
		</switch>
		
		<pid name="fbw/roll/pid-v">
			<input>fbw/roll/rate-error</input>
			<kp>fbw/roll/p-gain</kp>
			<ki>fbw/roll/i-gain</ki>
			<kd>fbw/roll/d-gain</kd>
			<trigger>fbw/roll/trigger</trigger>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
			<output>fbw/roll/pid</output>
		</pid>
		
		<switch name="fbw/roll/gear-law-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				position/wow eq 1
				/it-fbw/law eq 1
				/it-fbw/law eq 2
			</test>
		</switch>
		
		<fcs_function name="fbw/roll/rollout-cmd">
			<function>
				<product>
					<property>/orientation/roll-deg</property>
					<value>-0.1</value>
				</product>
			</function>
		</fcs_function>
		
		<pure_gain name="fbw/mixer/roll/computer-demand">
			<input>fbw/roll/pid</input>
			<gain>fbw/mixer/computer-gain</gain>
		</pure_gain>
		
		<pure_gain name="fbw/mixer/roll/sidestick-demand">
			<input>fbw/roll/a-i-f</input>
			<gain>fbw/mixer/sidestick-gain</gain>
		</pure_gain>
		
		<summer name="fbw/mixer/roll/output">
			<input>fbw/mixer/roll/computer-demand</input>
			<input>fbw/mixer/roll/sidestick-demand</input>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</summer>
		
		<switch name="fbw/aileron-output">
			<default value="0"/>
			<test logic="AND" value="fbw/mixer/roll/output"> <!-- Mix stick and control law for transition from ground law -->
				position/wow eq 0
				/it-fbw/law eq 0
			</test>
			<test logic="AND" value="fbw/roll/a-i-f">
				fbw/fmgc/enabled eq 0
				fbw/roll/gear-law-switch eq 1
			</test>
			<test logic="AND" value="fbw/roll/rollout-cmd">
				fbw/fmgc/enabled eq 1
				position/wow eq 1
				/it-fbw/law eq 0
			</test>
			<test logic="AND" value="0">
				/it-fbw/law eq 3
			</test>
		</switch>
		
		<switch name="fbw/roll/s-i-f-i">
			<default value="0"/>
			<test logic="AND" value="fbw/roll/a-i">
				position/wow eq 0
				/it-fbw/law eq 0
			</test>
			<test value="fbw/roll/a-i-f">
				fbw/roll/gear-law-switch eq 1
			</test>
			<test logic="AND" value="0">
				/it-fbw/law eq 3
			</test>
		</switch>
		
		<fcs_function name="fbw/roll/s-i-f">
			<function>
				<product>
					<table>
						<independentVar lookup="row">fbw/roll/s-i-f-i</independentVar>
						<tableData>
							-1.0 -1.0
							-0.2  0.0
							 0.2  0.0
							 1.0  1.0
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">velocities/vc-kts</independentVar>
						<independentVar lookup="column">position/wow</independentVar>
						<tableData>
							     0    1
							140  0.5  1.0
							350  0.1  1.0
						</tableData>
					</table>
				</product>
			</function>
		</fcs_function>
		
		<switch name="fbw/roll/s-i">
			<default value="0"/>
			<test value="fbw/roll/s-i-f">
				/it-fbw/roll-back eq 0
			</test>
		</switch>
		
		<switch name="fbw/roll/s-l">
			<default value="0"/>
			<test value="fbw/roll/s-i">
				/it-fbw/law ne 3
				/systems/failures/aileron-left eq 0
			</test>
			<test value="fbw/aileron-output">
				/it-fbw/law ne 3
				/systems/failures/aileron-left eq 1
			</test>
		</switch>
		
		<switch name="fbw/roll/s-r">
			<default value="0"/>
			<test value="fbw/roll/s-i">
				/it-fbw/law ne 3
				/systems/failures/aileron-right eq 0
			</test>
			<test value="fbw/aileron-output">
				/it-fbw/law ne 3
				/systems/failures/aileron-right eq 1
			</test>
		</switch>
		
		<lag_filter name="fbw/aileron-sidestick">
			<input>/controls/flight/aileron</input>
			<c1>20</c1>
		</lag_filter>
	
	</channel>
	
	<channel name="FBW: Pitch">
		
		<switch name="fbw/pitch/elevator-max"> <!-- Prevent pitch down -->
			<default value="1"/>
			<test logic="AND" value="0">
				/it-fbw/law eq 0
				/it-fbw/protections/overspeed eq 1
			</test>
		</switch>
		
		<switch name="fbw/pitch/e-i-f">
			<default value="/controls/flight/elevator"/>
			<test value="0">
				fbw/fmgc/enabled eq 1
			</test>
			<clipto>
				<min>-1.0</min>
				<max>fbw/pitch/elevator-max</max>
			</clipto>
		</switch>
		
		<kinematic name="fbw/pitch/e-i-k">
			<input>fbw/pitch/e-i-f</input>
			<traverse>
				<setting>
					<position>-1</position>
					<time>0</time>
				</setting>
				<setting>
					<position>1</position>
					<time>0.7</time>
				</setting>
			</traverse>
			<output>/controls/flight/elevator-input-fast</output>
		</kinematic>
		
		<fcs_function name="fbw/pitch/elevator-nul">
			<function>
				<table>
					<independentVar lookup="row">/controls/flight/elevator</independentVar>
					<tableData>
						-1.00 -1
						-0.04  0
						 0.04  0
						 1.00  1
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/e-f-air">
			<function>
				<sum>
					<property>fbw/pitch/elevator-nul</property>
					<table>
						<independentVar lookup="row">/position/gear-agl-ft</independentVar>
						<tableData>
							 5  0.2
							30  0.1
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/e-f-wow">
			<function>
				<sum>
					<property>fbw/pitch/elevator-nul</property>
					<value>-0.15</value>
				</sum>
			</function>
		</fcs_function>
		
		<switch name="fbw/pitch/flare-gear-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				gear/unit[1]/WOW eq 1
				gear/unit[2]/WOW eq 1
			</test>
		</switch>
		
		<switch name="fbw/pitch/e-i-s">
			<default value="fbw/pitch/elevator-nul"/>
			<test logic="AND" value="fbw/pitch/e-f-air">
				fbw/fmgc/enabled eq 0
				/position/gear-agl-ft le 30
				/controls/flight/flaps-pos ge 4
				/controls/engines/engine[0]/throttle lt 0.65
				/controls/engines/engine[1]/throttle lt 0.65
				/FMGC/internal/to-state eq 0
				/it-fbw/law eq 0
				position/wow eq 0
			</test>
			<test logic="AND" value="fbw/pitch/e-f-wow">
				fbw/fmgc/enabled eq 0
				/position/gear-agl-ft le 30
				/controls/flight/flaps-pos ge 4
				/controls/engines/engine[0]/throttle lt 0.65
				/controls/engines/engine[1]/throttle lt 0.65
				/FMGC/internal/to-state eq 0
				/it-fbw/law eq 0
				gear/unit[0]/WOW eq 0
				fbw/pitch/flare-gear-switch eq 1
			</test>
			<test logic="AND" value="fbw/fmgc/pitch-cmd">
				fbw/fmgc/enabled eq 1
				position/wow eq 0
			</test>
			<test logic="AND" value="0">
				fbw/fmgc/enabled eq 1
				position/wow eq 1
			</test>
			<clipto>
				<min>-1.0</min>
				<max>fbw/pitch/elevator-max</max>
			</clipto>
		</switch>
		
		<kinematic name="fbw/pitch/e-i">
			<input>fbw/pitch/e-i-s</input>
			<traverse>
				<setting>
					<position>-1</position>
					<time>0</time>
				</setting>
				<setting>
					<position>1</position>
					<time>2.0</time>
				</setting>
			</traverse>
			<output>/controls/flight/elevator-input</output>
		</kinematic>
		
		<switch name="fbw/pitch/g-min">
			<default value="-1.0"/>
			<test value="0.0">
				/controls/flight/flaps-pos ne 0
			</test>
		</switch>
		
		<switch name="fbw/pitch/g-max">
			<default value="2.5"/>
			<test value="2.0">
				/controls/flight/flaps-pos ne 0
			</test>
		</switch>
		
		<fcs_function name="fbw/pitch/g-demand">
			<function>
				<table>
					<independentVar lookup="row">fbw/pitch/e-i</independentVar>
					<tableData>
						-1.0  2.5
						 0.0  1.0
						 1.0 -0.5
					</tableData>
				</table>
			</function>
			<clipto>
				<min>fbw/pitch/g-min</min>
				<max>fbw/pitch/g-max</max>
			</clipto>
		</fcs_function>
		
		<pure_gain name="fbw/pitch/g-instrumented">
			<input>/accelerations/pilot-g</input>
			<gain>1.0</gain>
		</pure_gain>
		
		<fcs_function name="fbw/pitch/g-computed">
			<function>
				<sum>
					<property>fbw/pitch/g-instrumented</property>
					<quotient>
						<value>-1</value>
						<cos>
							<property>attitude/roll-rad</property>
						</cos>
					</quotient>
					<value>1</value>
				</sum>
			</function>
		</fcs_function>
		
		<summer name="fbw/pitch/g-error">
			<input>fbw/pitch/g-computed</input>
			<input>-fbw/pitch/g-demand</input>
		</summer>
		
		<!-- Goes to Systems/fbw-pitch.xml then back as fbw/pitch/g-pi -->
		
		<pure_gain name="fbw/pitch/g-pi-inv">
			<input>fbw/pitch/g-pi</input>
			<gain>-1.0</gain>
		</pure_gain>
		
		<switch name="fbw/pitch/g-pi-switched">
			<default value="fbw/pitch/g-pi"/>
			<test logic="OR" value="fbw/pitch/g-pi-inv">
				attitude/roll-rad lt -1.5708
				attitude/roll-rad gt 1.5708
			</test>
		</switch>
		
		<!--pure_gain name="fbw/pitch/g-pi-switched">
			<input>fbw/pitch/e-i</input>
			<gain>1.0</gain>
		</pure_gain--> <!-- Tuning G Bypass -->
		
		<fcs_function name="fbw/pitch/p-r-norm">
			<function>
				<sum>
					<product>
						<property>fbw/pitch/g-pi-switched</property>
						<value>-0.087266</value>
					</product>
					<table>
						<independentVar lookup="row">attitude/pitch-rad</independentVar>
						<independentVar lookup="column">fbw/pitch/g-pi-switched</independentVar>
						<tableData>
							          -1         0         1
							-0.261799  0.000000  0.000000  0.087266
							-0.174533  0.000000  0.000000  0.000000
							 0.436332  0.000000  0.000000  0.000000
							 0.523599 -0.087266  0.000000  0.000000
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">attitude/pitch-rad</independentVar>
						<tableData>
							-0.436332  0.087266
							-0.261799  0.000000
							 0.523599  0.000000
							 0.698132 -0.087266
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<pure_gain name="fbw/pitch/p-r-altn">
			<input>fbw/pitch/g-pi-switched</input>
			<gain>-0.087266</gain>
		</pure_gain>
		
		<fcs_function name="fbw/pitch/p-r-norm-os">
			<function>
				<sum>
					<table>
						<independentVar lookup="row">fbw/pitch/g-pi-switched</independentVar>
						<independentVar lookup="column">fbw/pitch/vc-kts-rate-lag</independentVar>
						<tableData>
							     -2        -1
							-1.0  0.087266  0.087266
							 0.0  0.000000  0.026180
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">attitude/pitch-rad</independentVar>
						<independentVar lookup="column">fbw/pitch/g-pi-switched</independentVar>
						<tableData>
							          -1         0
							 0.436332 -0.026180  0.000000
							 0.523599 -0.087266  0.000000
						</tableData>
					</table>
					<table>
						<independentVar lookup="row">attitude/pitch-rad</independentVar>
						<tableData>
							 0.523599  0.000000
							 0.698132 -0.087266
						</tableData>
					</table>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/pitch/p-r-altn-os">
			<function>
				<table>
					<independentVar lookup="row">fbw/pitch/g-pi-switched</independentVar>
					<independentVar lookup="column">fbw/pitch/vc-kts-rate-lag</independentVar>
					<tableData>
						     -2        -1
						-1.0  0.087266  0.087266
						 0.0  0.000000  0.026180
						 1.0 -0.061086 -0.087266
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<switch name="fbw/pitch/rate-demand"> <!-- 5 deg/0.087266 rad per second -->
			<default value="0"/>
			<test logic="AND" value="fbw/pitch/p-r-norm">
				/it-fbw/law eq 0
				/it-fbw/protections/overspeed ne 1
			</test>
			<test logic="AND" value="fbw/pitch/p-r-altn">
				/it-fbw/law ne 0
				/it-fbw/protections/overspeed ne 1
			</test>
			<test logic="AND" value="fbw/pitch/p-r-norm-os">
				/it-fbw/law eq 0
				/it-fbw/protections/overspeed eq 1
			</test>
			<test logic="AND" value="fbw/pitch/p-r-altn-os">
				/it-fbw/law ne 0
				/it-fbw/protections/overspeed eq 1
			</test>
		</switch>
		
		<lag_filter name="fbw/pitch/rate-demand-lag">
			<input>fbw/pitch/rate-demand</input>
			<c1>10.1</c1>
		</lag_filter>
		
		<fcs_function name="fbw/pitch/thetadot-rad_sec">
			<function>
				<toradians>
					<property>/orientation/pitch-rate-degps</property>
				</toradians>
			</function>
		</fcs_function>
		
		<switch name="fbw/pitch/t-r_s-s">
			<default value="fbw/pitch/thetadot-rad_sec"/>
			<test value="0">
				gear/unit[0]/WOW eq 1
			</test>
		</switch>
		
		<summer name="fbw/pitch/rate-error">
			<input>fbw/pitch/t-r_s-s</input>
			<input>-fbw/pitch/rate-demand-lag</input>
		</summer>
		
		<switch name="fbw/pitch/trigger">
			<default value="0"/>
			<test value="-1">
				fbw/pitch/gain-switch gt 0
			</test>
			<test logic="OR" value="1">
				fbw/pitch/pid le -0.999
				fbw/pitch/pid ge 0.999
			</test>
		</switch>
		
		<pid name="fbw/pitch/pid-v">
			<input>fbw/pitch/rate-error</input>
			<kp>fbw/pitch/p-gain</kp>
			<ki>fbw/pitch/i-gain</ki>
			<kd>fbw/pitch/d-gain</kd>
			<trigger>fbw/pitch/trigger</trigger>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
			<output>fbw/pitch/pid</output>
		</pid>
		
		<pure_gain name="fbw/pitch/pid-inv">
			<input>fbw/pitch/pid</input>
			<gain>-1.0</gain>
		</pure_gain>
		
		<switch name="fbw/pitch/pid-switched">
			<default value="fbw/pitch/pid"/>
			<test logic="OR" value="fbw/pitch/pid-inv">
				attitude/roll-rad lt -1.5708
				attitude/roll-rad gt 1.5708
			</test>
		</switch>
		
		<switch name="fbw/pitch/law-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				/it-fbw/law eq 0
				/it-fbw/law eq 1
			</test>
		</switch>
		
		<switch name="fbw/pitch/law-gear-switch">
			<default value="0"/>
			<test logic="OR" value="1">
				gear/unit[1]/WOW eq 1
				gear/unit[2]/WOW eq 1
				/it-fbw/law eq 2
			</test>
		</switch>
		
		<pure_gain name="fbw/mixer/pitch/computer-demand">
			<input>fbw/pitch/pid-switched</input>
			<gain>fbw/mixer/computer-gain</gain>
		</pure_gain>
		
		<pure_gain name="fbw/mixer/pitch/sidestick-demand">
			<input>fbw/pitch/e-i-f</input>
			<gain>fbw/mixer/sidestick-gain</gain>
		</pure_gain>
		
		<summer name="fbw/mixer/pitch/output">
			<input>fbw/mixer/pitch/computer-demand</input>
			<input>fbw/mixer/pitch/sidestick-demand</input>
			<clipto>
				<min>-1.0</min>
				<max>1.0</max>
			</clipto>
		</summer>
		
		<switch name="fbw/elevator-output">
			<default value="0"/>
			<test logic="AND" value="fbw/mixer/pitch/output"> <!-- Mix stick and control law for transition from ground law -->
				position/wow eq 0
				fbw/pitch/law-switch eq 1
			</test>
			<test logic="AND" value="fbw/pitch/e-i-f">
				fbw/fmgc/enabled eq 0
				fbw/pitch/law-gear-switch eq 1
			</test>
			<test logic="AND" value="0.1">
				fbw/fmgc/enabled eq 1
				position/wow eq 1
				gear/unit[0]/WOW eq 0
			</test>
			<test logic="AND" value="0.05">
				fbw/fmgc/enabled eq 1
				position/wow eq 1
			</test>
			<test logic="AND" value="0">
				/it-fbw/law eq 3
			</test>
		</switch>
		
		<lag_filter name="fbw/elevator-sidestick">
			<input>/controls/flight/elevator</input>
			<c1>20</c1>
		</lag_filter>
		
		<switch name="fbw/pitch/autotrim-height">
			<default value="50"/>
			<test logic="AND" value="100">
				fbw/fmgc/enabled eq 1
			</test>
		</switch>
		
		<switch name="fbw/pitch/autotrim-switch">
			<default value="0"/>
			<test logic="AND" value="1">
				fbw/pitch/gain-switch eq 0
				/position/gear-agl-ft ge fbw/pitch/autotrim-height
				attitude/roll-rad lt 0.628319
				attitude/roll-rad gt -0.628319
				fbw/pitch/pid-switched ge 0.01
				fbw/pitch/g-instrumented ge 0.5
				/it-fbw/protections/overspeed ne 1
				/controls/flight/elevator-trim le 0.32
				position/wow eq 0
			</test>
			<test logic="AND" value="2">
				fbw/pitch/gain-switch eq 0
				/position/gear-agl-ft ge fbw/pitch/autotrim-height
				attitude/roll-rad lt 0.628319
				attitude/roll-rad gt -0.628319
				fbw/pitch/pid-switched le -0.01
				fbw/pitch/g-instrumented ge 0.5
				/it-fbw/protections/overspeed ne 1
				/controls/flight/elevator-trim ge -1.0
				position/wow eq 0
			</test>
		</switch>
		
		<fcs_function name="fbw/pitch/autotrim-offset">
			<function>
				<sum>
					<ifthen>
						<eq>
							<property>fbw/pitch/autotrim-switch</property>
							<value>1</value>
						</eq>
						<table>
							<independentVar lookup="row">fbw/pitch/pid-switched</independentVar>
							<tableData>
								0.05  0.00001
								0.30  0.00015
							</tableData>
						</table>
						<value>0.0</value>
					</ifthen>
					<ifthen>
						<eq>
							<property>fbw/pitch/autotrim-switch</property>
							<value>2</value>
						</eq>
						<table>
							<independentVar lookup="row">fbw/pitch/pid-switched</independentVar>
							<tableData>
								-0.30 -0.00015
								-0.05 -0.00001
							</tableData>
						</table>
						<value>0.0</value>
					</ifthen>
				</sum>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/elevator-trim-output">
			<function>
				<sum>
					<property>/controls/flight/elevator-trim</property>
					<property>fbw/pitch/autotrim-offset</property>
				</sum>
			</function>
			<clipto>
				<min>-1.0</min>
				<max>0.32</max>
			</clipto>
			<output>/controls/flight/elevator-trim</output>
		</fcs_function>
	
	</channel>
	
	<channel name="FBW: Yaw">
		
		<fcs_function name="fbw/yaw/max-deg-fac-1">
			<function>
				<table>
					<independentVar lookup="row">/systems/fmgc/active-airspeed-1</independentVar>
					<tableData>
						160  25.0
						410   3.5
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/yaw/max-deg-fac-2">
			<function>
				<table>
					<independentVar lookup="row">/systems/fmgc/active-airspeed-2</independentVar>
					<tableData>
						160  25.0
						410   3.5
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<switch name="/systems/fctl/fac1-rtlu-avail">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/failures/fctl/rtlu-1 eq 0
				/systems/electrical/bus/dc-ess ge 25
				/systems/fctl/fac1-healthy-signal eq 1
				<test logic="OR">
					<test logic="AND">
						/systems/fmgc/cas-compare/cas-reject-1 eq 0
						/systems/navigation/adr/operating-1 eq 1
					</test>
					<test logic="AND">
						/systems/fmgc/cas-compare/cas-reject-3 eq 0
						/systems/navigation/adr/operating-3 eq 1
					</test>
				</test>
			</test>
		</switch>
		
		<switch name="/systems/fctl/fac2-rtlu-avail">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/failures/fctl/rtlu-2 eq 0
				/systems/electrical/bus/dc-2 ge 25
				/systems/fctl/fac2-healthy-signal eq 1
				<test logic="OR">
					<test logic="AND">
						/systems/fmgc/cas-compare/cas-reject-2 eq 0
						/systems/navigation/adr/operating-2 eq 1
					</test>
					<test logic="AND">
						/systems/fmgc/cas-compare/cas-reject-3 eq 0
						/systems/navigation/adr/operating-3 eq 1
					</test>
				</test>
			</test>
		</switch>
		
		<switch name="fbw/yaw/rtlu-emergency">
			<default value="0"/>
			<test logic="AND" value="1">
				/systems/fctl/fac1-rtlu-avail eq 0
				/systems/fctl/fac2-rtlu-avail eq 0
				fcs/slat-pos-deg ne 0
			</test>
		</switch>
		
		<switch name="fbw/yaw/max-deg-switch-cmd">
			<default value="25"/>
			<test logic="AND" value="fbw/yaw/max-deg-switch"> <!-- RTLU frozen with FAC 1 / 2 failure -->
				/systems/fctl/fac1-rtlu-avail eq 0
				/systems/fctl/fac2-rtlu-avail eq 0
				fcs/slat-pos-deg eq 0
			</test>
			<test logic="AND" value="25"> <!-- Return to low speed control with slats extended -->
				fbw/yaw/rtlu-emergency eq 1
			</test>
			<test logic="AND" value="fbw/yaw/max-deg-fac-1"> <!-- Side 1 has priority -->
				/systems/fctl/fac1-rtlu-avail eq 1
			</test>
			<test logic="AND" value="fbw/yaw/max-deg-fac-2">
				/systems/fctl/fac2-rtlu-avail eq 1
			</test>
		</switch>
		
		<switch name="fbw/yaw/rtlu-power">
			<default value="0"/>
			<test logic="AND" value="25"> <!-- Main motor control -->
				<test logic="OR">
					/systems/electrical/bus/dc-ess-shed ge 25
					/systems/electrical/bus/dc-2 ge 25
				</test>
				fbw/yaw/rtlu-emergency ne 1
			</test>
			<test logic="AND" value="3"> <!-- Emergency motor is slower -->
				/systems/electrical/bus/ac-ess-26v ge 24.8
				/systems/fctl/fac1-rtlu-avail eq 0
				/systems/fctl/fac2-rtlu-avail eq 0
				fcs/slat-pos-deg ne 0
				fbw/yaw/max-deg-switch ne fbw/yaw/max-deg-switch-cmd
			</test>
		</switch>
		
		<actuator name="rubbish/rudder-travel-limiter">
			<input>fbw/yaw/max-deg-switch-cmd</input>
			<rate_limit>fbw/yaw/rtlu-power</rate_limit>
			<output>fbw/yaw/max-deg-switch</output>
		</actuator>
		
		<aerosurface_scale name="fbw/yaw/max-deg-scale">
			<input>fbw/yaw/max-deg-switch</input>
			<domain>
				<min>-25</min>
				<max>25</max>
			</domain>
			<range>
				<min>-1</min>
				<max>1</max>
			</range>
		</aerosurface_scale>
		
		<pure_gain name="fbw/yaw/max-deg-scale-neg">
			<input>fbw/yaw/max-deg-scale</input>
			<gain>-1.0</gain>
		</pure_gain>
		
		<fcs_function name="fbw/yaw/rudder-nul">
			<function>
				<table>
					<independentVar lookup="row">/controls/flight/rudder</independentVar>
					<independentVar lookup="column">fbw/fmgc/enabled</independentVar>
					<tableData>
						       0  1
						-1.00 -1  0
						-0.04  0  0
						 0.04  0  0
						 1.00  1  0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<fcs_function name="fbw/yaw/rudder-nul-scheduled">
			<function>
				<quotient>
					<product>
						<property>fbw/yaw/rudder-nul</property>
						<property>fbw/yaw/max-deg-switch</property>
					</product>
					<value>25.0</value>
				</quotient>
			</function>
		</fcs_function>
		
		<switch name="fbw/yaw/autoland-switch">
			<default value="0"/>
			<test logic="AND" value="1">
				fbw/fmgc/enabled eq 1
				/it-autoflight/output/lat eq 4
			</test>
		</switch>
		
		<washout_filter name="fbw/yaw/r-washout">
			<input>velocities/r-rad_sec</input>
			<c1>0.5</c1>
		</washout_filter>
		
		<switch name="fbw/yaw/r-r_s-s">
			<default value="fbw/yaw/r-washout"/>
			<test logic="OR" value="0">
				position/wow eq 1
				/position/gear-agl-ft lt 50
				fbw/yaw/autoland-switch eq 1
			</test>
		</switch>
		
		<pure_gain name="fbw/yaw/yd-f">
			<input>fbw/yaw/r-r_s-s</input>
			<gain>fbw/yaw/yd-p-gain</gain>
			<clipto>
				<min>-0.5</min>
				<max>0.5</max>
			</clipto>
		</pure_gain>
		
		<switch name="fbw/yaw/slip-skid">
			<default value="aero/beta-rad"/>
			<test logic="OR" value="0">
				position/wow eq 1
				fbw/yaw/rudder-nul gt 0
				fbw/yaw/rudder-nul lt 0
			</test>
		</switch>
		
		<pid name="fbw/yaw/tc-pd-v">
			<input>fbw/yaw/slip-skid</input>
			<kp>fbw/yaw/tc-p-gain</kp>
			<ki>0.0</ki>
			<kd>fbw/yaw/tc-d-gain</kd>
			<clipto>
				<min>-0.4</min>
				<max>0.4</max>
			</clipto>
			<output>fbw/yaw/tc-pd</output>
		</pid>
		
		<switch name="fbw/yaw/tc-pd-s">
			<default value="fbw/yaw/tc-pd"/>
			<test logic="OR" value="0">
				position/wow eq 1
				fbw/yaw/rudder-nul gt 0
				fbw/yaw/rudder-nul lt 0
			</test>
		</switch>
		
		<switch name="fbw/yaw/fmgc-cmd">
			<default value="0"/>
			<test value="fbw/fmgc/yaw-cmd">
				fbw/yaw/autoland-switch eq 1
			</test>
		</switch>
		
		<summer name="fbw/yaw/output-sum">
			<input>fbw/yaw/yd-f</input>
			<input>fbw/yaw/tc-pd-s</input>
			<input>fbw/yaw/fmgc-cmd</input>
		</summer>
		
		<switch name="fbw/yaw/law-switch"> <!-- Is the yaw damper active or not? -->
			<default value="0"/>
			<test logic="AND" value="1">
				/it-fbw/law ne 3
				<test logic="OR">
					/it-fbw/yaw-law eq 0
					/it-fbw/yaw-law eq 1
				</test>
			</test>
		</switch>
		
		<switch name="fbw/rudder-output">
			<default value="fbw/yaw/rudder-nul-scheduled"/>
			<test logic="AND" value="fbw/yaw/output-sum">
				fbw/yaw/law-switch eq 1
				fbw/yaw/rudder-nul eq 0
			</test>
			<output>/controls/flight/rudder-fbw</output>
		</switch>
		
		<lag_filter name="fbw/rudder-pedal">
			<input>/controls/flight/rudder</input>
			<c1>20</c1>
		</lag_filter>
	
	</channel>

</system>