<?xml version="1.0"?>
<!--	Dornier DO228(-212 NG) RSD (Reference Speed Deviation) and Stall Warning System	-->
<!--	Benedikt Wolf (D-ECHO)	-->

<!--
	Reference: ref.[1] p.7-127ff.
		Description
			* Vs is calculated based on:
				Lift Computer output
				Flap position
				Lift Tranducer (heated along with Pitot LH)
			* Stall warning is activated about 5-12 knots above Vs
			* Push-to-test: When Stall warning light is pushed:
				* RSD needle moves into SLOW range
				* Stall warning is activated
		
		
-->

<system name="Dornier DO228: RSD and Stall Warning System">
	
	<channel name="Electrical Power">
		<switch name="instrumentation/rsd/powered">
			<default value="0"/>
			<test value="1">
				/systems/electrical/outputs/stall-warn gt 15
			</test>
		</switch>
	</channel>
	
	<channel name="Lift Computer">
		<!--	Calculate Stall speed based on ref. [1], p.5-12	-->
		<pure_gain>
			<input>inertia/weight-lbs</input>
			<gain>0.45359237</gain>	<!-- lbs to kg	-->
			<output>instrumentation/rsd/input/weight-kg</output>
		</pure_gain>
		<fcs_function name="instrumentation/rsd/stall-speed/step-1">
			<function>
				<table>
					<independentVar lookup="row">instrumentation/rsd/input/weight-kg</independentVar>
					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
					<tableData>
							0	5	20	30
						40	68	63	56	52.7
						45	74	68	61.8	58.4
						50	77	72	65	62
						55	80.5	75.5	68	65
						60	83.5	78	70.5	67.3
						65	86.6	81	73	69.8
					</tableData>
				</table>
			</function>
		</fcs_function>
		<fcs_function name="instrumentation/rsd/stall-speed/calculated-stall-speed-kias">
			<function>
				<table>
					<independentVar lookup="row">/accelerations/pilot-g</independentVar>
					<independentVar lookup="column">instrumentation/rsd/stall-speed/step-1</independentVar>
					<tableData>
							50	85
						1.0	50	85
						1.1	52.2	89
						1.2	54.7	93
						1.3	57	97
						1.4	59	101
						1.5	61	104.2
						1.6	63	108
						1.7	65.3	111
						1.8	67	114.2
						1.9	69	117.3
						2.0	71	120.1
					</tableData>
				</table>
			</function>
		</fcs_function>
		<pure_gain>
			<input>instrumentation/rsd/stall-speed/calculated-stall-speed-kias</input>
			<gain>1.3</gain>
			<output>instrumentation/rsd/stall-speed/calculated-stall-speed-kias-1_3</output>
		</pure_gain>
		<fcs_function name="instrumentation/rsd/rsd-deviation-kts">
			<function>
				<difference>
					<property>velocities/vc-kts</property>
					<property>instrumentation/rsd/stall-speed/calculated-stall-speed-kias-1_3</property>
				</difference>
			</function>
		</fcs_function>
	</channel>
	
	<property value="0.0">instrumentation/rsd/needle-raw</property>
	
	<!--	Needle Deflections:
			maximum: 42 deg
			range beginning: 20.5 deg
			neutral: 0 deg
	-->
	<channel name="Indication">
		<fcs_function>
			<function>
				<table>
					<independentVar>instrumentation/rsd/rsd-deviation-kts</independentVar>
					<tableData>
						-23	-1.0
						23	1.0
					</tableData>
				</table>
			</function>
			<output>instrumentation/rsd/needle-calculated-norm</output>
		</fcs_function>
		<actuator>
			<input>instrumentation/rsd/powered</input>
			<rate_limit>4.0</rate_limit>
			<output>/instrumentation/rsd/off-flag</output>
		</actuator>
		<switch>
			<default value="0.0"/>
			<test value="instrumentation/rsd/needle-calculated-norm" logic="AND">
				/instrumentation/rsd/stall-warning/pushed ne 1
				fcs/gear-no-wow eq 1
			</test>
			<test value="-1.0">
				/instrumentation/rsd/stall-warning/pushed eq 1
			</test>
			<output>instrumentation/rsd/needle-raw</output>
		</switch>
		<actuator>
			<input>instrumentation/rsd/needle-raw</input>
			<rate_limit>1.0</rate_limit>
			<output>/instrumentation/rsd/rsd-needle</output>
		</actuator>
		<switch>
			<default value="0"/>
			<test value="instrumentation/rsd/powered">
				/instrumentation/rsd/rsd-needle lt -0.488
			</test>
			<output>/instrumentation/rsd/stall-warning/active</output>
		</switch>
	</channel>
</system>
