<?xml version="1.0" encoding="UTF-8"?>

<flight_control name="FCS: DR400-135cdi">
	<!--	Control Surface Deflection: (ref. [7], p. 1.17)
						(deg)
					up			down
			Elevator	9.5 +- 0.5		12 +- 0.5
			Ailerons	15 +- 1			10 +- 1
					left			right
			Rudder			25 -0 +3
	-->
	<property value="0.0">fcs/elevator-position</property>
	<channel name="Elevator">
		<fcs_function name="trim-effect">
			<function>
				<table>
					<independentVar>aero/qbar-psf</independentVar>
					<tableData>
						0	0
						10	1
					</tableData>
				</table>
			</function>
		</fcs_function>
		<fcs_function name="trim-deflection"> <!--mechanical linkage between elevator and trim-->
			<function>
				<table>
					<independentVar lookup="row">fcs/elevator-position</independentVar>
					<independentVar lookup="column">fcs/pitch-trim-cmd-norm</independentVar>
					<tableData>
							-1	1
						-1	 0	0.7
						 1	-0.7	0
					</tableData>
				</table>
			</function>
		</fcs_function>
		<fcs_function name="stick-and-trim">
			<function>
				<table>
					<independentVar lookup="row">fcs/elevator-cmd-norm</independentVar>
					<independentVar lookup="column">fcs/trim-deflection</independentVar>
					<tableData>
							-0.7	-0.5	0.5	0.7
						-1	-1	-1	-1	-1
						0	-1	-1	1	1
						1	1	1	1	1
						
					</tableData>
				</table>
			</function>
		</fcs_function>
		<fcs_function name="drop-gravity">
			<function>
				<table>
					<independentVar lookup="row">fcs/elevator-cmd-norm</independentVar>
					<independentVar lookup="column">aero/qbar-psf</independentVar>
					<tableData>
							0	0.5	5
						-1	0	0	0
						0	1	1	0
					</tableData>
				</table>
			</function>
		</fcs_function>
		<summer name="Elevator Position">
			<input>fcs/stick-and-trim</input>
			<input>fcs/drop-gravity</input>
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
			<output>fcs/elevator-pos-norm</output>
		</summer> 			
		<aerosurface_scale name="Elevator Control">
			<input>fcs/elevator-pos-norm</input>
			<range>
				<min> -0.2094 </min>	<!-- 12 deg -->
				<max>  0.1658 </max>	<!-- 9.5 deg -->
			</range>
			<output>fcs/elevator-pos-rad</output>
		</aerosurface_scale>
		<aerosurface_scale>
			<input>fcs/elevator-pos-rad</input>
			<domain>
				<min> -0.2094 </min>
				<max>  0.2094 </max>
			</domain>
			<range>
				<min> -1.0 </min>
				<max>  1.0 </max>
			</range>
			<output>fcs/elevator-pos-norm</output>
		</aerosurface_scale>
	</channel>
	<property value="0.1395">fcs/roll-trim-offset</property>
	<channel name="Roll">
		
		<summer name="Roll Trim Sum">
			<input>fcs/aileron-cmd-norm</input>
			<input>fcs/roll-trim-cmd-norm</input>
			<input>fcs/roll-trim-offset</input>
			<clipto>
				<min> -1 </min>
				<max>  1 </max>
			</clipto>
		</summer>
		<aerosurface_scale name="Left Aileron Control">
			<input>fcs/roll-trim-sum</input>
			<range>
				<min> -0.2618 </min>	<!-- 15 deg -->
				<max>  0.1745 </max>	<!-- 10 deg -->
			</range>
			<output>fcs/left-aileron-pos-rad</output>
		</aerosurface_scale>
		<aerosurface_scale name="Right Aileron Control">
			<input>-fcs/roll-trim-sum</input>
			<range>
				<min> -0.2618 </min>	<!-- 15 deg -->
				<max>  0.1745 </max>	<!-- 10 deg -->
			</range>
			<output>fcs/right-aileron-pos-rad</output>
		</aerosurface_scale>
		<aerosurface_scale>
			<input>fcs/left-aileron-pos-rad</input>
			<domain>
				<min> -0.2618 </min>
				<max>  0.2618 </max>
			</domain>
			<range>
				<min> -1.0 </min>
				<max>  1.0 </max>
			</range>
			<output>fcs/left-aileron-pos-norm</output>
		</aerosurface_scale>
		<aerosurface_scale>
			<input>fcs/right-aileron-pos-rad</input>
			<domain>
				<min> -0.2618 </min>
				<max>  0.2618 </max>
			</domain>
			<range>
				<min> -1.0 </min>
				<max>  1.0 </max>
			</range>
			<output>fcs/right-aileron-pos-norm</output>
		</aerosurface_scale>
	</channel>
	<property value="0.025">fcs/yaw-trim-offset</property>
	<channel name="Yaw">
		<summer name="Rudder Command Sum">
			<input>fcs/rudder-cmd-norm</input>
			<input>fcs/yaw-trim-cmd-norm</input>
			<input>fcs/yaw-trim-offset</input>
		</summer>
		<aerosurface_scale name="Rudder Control">
			<input>fcs/rudder-command-sum</input>
			<range>
				<min> -0.4363 </min>	<!-- -25 deg -->
				<max>  0.4363 </max>	<!--  25 deg -->
			</range>
			<output>fcs/rudder-pos-rad</output>
		</aerosurface_scale>
		<aerosurface_scale>
			<input>fcs/rudder-pos-rad</input>
			<domain>
				<min> -0.4363 </min>
				<max>  0.4363 </max>
			</domain>
			<range>
				<min> -1.0 </min>
				<max>  1.0 </max>
			</range>
			<output>fcs/rudder-pos-norm</output>
		</aerosurface_scale>
	</channel>
	<channel name="Flaps">
		<lag_filter name="Flaps Control">
			<input>fcs/flap-cmd-norm</input>
			<c1>2</c1>
			<output>fcs/flap-pos-int-norm</output>
		</lag_filter>
		<fcs_function>
			<function>
				<table>
					<independentVar>fcs/flap-pos-int-norm</independentVar>
					<tableData>
						0	0
						0.01	0
						0.24	0.25
						0.26	0.25
						0.99	1
						1	1
					</tableData>
				</table>
			</function>
			<output>fcs/flap-pos-norm</output>
		</fcs_function>
		<aerosurface_scale name="Flap Position degree">
			<input>fcs/flap-pos-norm</input>
			<range>
				<min>0</min>
				<max>60</max>
			</range>
			<output>fcs/flap-pos-deg</output>
		</aerosurface_scale>
	</channel>
	<channel name="Mixture">
		<fcs_function>
			<function>
				<table>
					<independentVar>atmosphere/pressure-altitude</independentVar>
					<tableData>
						0	1
						30000	0.36
					</tableData>
				</table>
			</function>
			<output>fcs/mixture-cmd-norm</output>
			<output>fcs/mixture-pos-norm</output>
		</fcs_function>
	</channel>
</flight_control>
