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

<!--
 cap10b-set.xml  - Cap10B by PAF team  - http://equipe-flightgear.forumactif.com

 Written by Flavien BLANC
 Modified by PAF team  - April 2012

 Copyright (C) 2011-2012  Flavien BLANC  - http://equipe-flightgear.forumactif.com/u56
 Copyright (C) 2012  Clément DE L'HAMAIDE  - http://equipe-flightgear.forumactif.com/u115


 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
 published by the Free Software Foundation; either version 2 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not see <http://www.gnu.org/licenses/>.
-->

<system name="crash-detect">

 <!-- <property value="0">systems/crash-detect/crashed</property>-->

  <channel name="Over-G">

     <fcs_function name="wing-load">
       <function>
          <product>
             <property>accelerations/Nz</property>
             <property>inertia/weight-lbs</property>
          </product>
       </function>
       <output>systems/crash-detect/wing-load</output>
     </fcs_function>

     <!--
          Detect wing loads that exceed limits.
          Operational limits are +64,000 lbs and
          -32,000lbs.  IE. +8 or -4 Gs at 8,000 lbs
          gross weight  This allows for a 40% engineering
          margin of safety before actual structural
          failure.   At higher gross weights the wing
          structure will fail at lower G loadings.
          -->
     <switch name="over-g-failure">
          <test value="1">
                systems/crash-detect/wing-load gt 11500
          </test>
          <test value="1">
                systems/crash-detect/wing-load lt -7500
          </test>
          <output>systems/crash-detect/crashed</output>
          <output> systems/crash-detect/over-g-failure </output>
     </switch>

     <switch name="over-g">
          <test value="1">
                systems/crash-detect/wing-load gt 10000
          </test>
          <test value="1">
                systems/crash-detect/wing-load lt -6000
          </test>
          <output> systems/crash-detect/over-g </output>
     </switch>

  </channel>

  <channel name="crashed">

     <!-- end the sim if the aircraft is crashed -->
     <!--<switch name="systems/crash-detect/FG">
        <test value="1">
           systems/crash-detect/crashed == 1
        </test>
        <output>/sim/freeze/clock</output>
        <output>/sim/freeze/main</output>
        <output>/controls/engines/engine[0]/cutoff</output>
        <output>/sim/crashed</output>
     </switch>-->
  
  </channel>

  <channel name="impact-ground">

     <switch name="impact">
          <test logic="AND" value="1">
                position/h-agl-ft lt 1.0
                simulation/sim-time-sec gt 1.0
          </test>
          <output>systems/crash-detect/crashed</output>
          <output> systems/crash-detect/impact </output>
     </switch>

  </channel>

</system>
