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

<!-- ########################################

# DR400-120  by PAF team
# Oct 2012 : Modified by PAF team
# http://equipe-flightgear.forumactif.com

##########################################-->

<system name="crash-detect">
	
	
	<channel name="Over-G">
		
		<!--
		According to the AFM g limits are:
		at 910kg (2006lbs)	+4.4
		-2.2
		at 1000kg (2205lbs)	+3.8
		-1.9
		Assuming a safety margin of 1.5 (guess based on https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20140011147.pdf)
		resulting wing loadings:
		positive: 	+8379lbs
		negative:	-4190lbs
		-->
		
		<switch name="systems/crash-detect/over-g-damaged">
			<test value="1">
				forces/fbz-aero-lbs lt -8379
			</test>
			<test value="1">
				forces/fbz-aero-lbs gt 4190
			</test>
		</switch>
		
		<switch name="systems/crash-detect/over-g-crashed">
			<test value="1">
				forces/fbz-aero-lbs lt -12220
			</test>
			<test value="1">
				forces/fbz-aero-lbs gt 6110
			</test>
		</switch>  
		
	</channel>
	
	
	
	
	<channel name="gear-impact">
		
		<!-- Detect gear loads that exceed limits (5 Gs) -->
		
		<switch name="systems/crash-detect/gear-damaged">
			<test value="1">
				forces/fbz-gear-lbs lt -9920
			</test>
		</switch>
		
		<switch name="systems/crash-detect/gear-destroyed">
			<test value="1">
				forces/fbz-gear-lbs lt -13890
			</test>
		</switch>
		
	</channel>
	
	
	<channel name="ground-impact">
		
		<!-- Detect severe ground impact crash (about 10 Gs) -->
		
		<switch name="systems/crash-detect/total-crash">
			<test value="1">
				accelerations/udot-ft_sec2 lt -333
			</test>
		</switch>
		
	</channel>
	
	<channel name="damaged">
		
		<!-- to display a message by nasal if the aircraft is damaged -->
		
		<switch name="/sim/damaged">
			<test value="1">
				systems/crash-detect/over-g-damaged == 1
			</test>
			<test value="1">
				systems/crash-detect/gear-damaged == 1
			</test>
		</switch>
		
	</channel>
	
	<channel name="crashed">
		
		<!-- to end the sim by nasal if the aircraft is crashed -->
		
		<switch name="/sim/crashed">
			<test value="1">
				systems/crash-detect/over-g-crashed == 1
			</test>
			<test value="1">
				systems/crash-detect/gear-destroyed == 1
			</test>
			<test value="1">
				systems/crash-detect/total-crash == 1
			</test>
		</switch>
		
	</channel>
	
	
</system>
