<?xml version="1.0"?>


<!--ideas from the Dave Culp Hangar  models -->

<system name="crash-detect">

    <property value="0">/fdm/simulation/wrg-ver</property>

  <channel name="Over-G">
     <switch name="systems/crash-detect/over-g">
         <test logic="AND" value="1">
             accelerations/Nz gt 9.0
             systems/hook/tailhook-pos-norm != 1
         </test>
         <test logic="AND" value="1">
             accelerations/Nz lt -8.0
             systems/hook/tailhook-pos-norm != 1
         </test>
         <test logic="AND" value="1">
             accelerations/Nz gt 15.0
             systems/hook/tailhook-pos-norm == 1
         </test>
     </switch>
  </channel>

  <channel name="impact-ground">
     <switch name="systems/crash-detect/impact">
         <default value="0"/>
          <test logic="AND" value="1">
              systems/crash-detect/over-g == 1
              gear/unit[1]/WOW != 1
              gear/unit[2]/WOW != 1
              simulation/sim-time-sec gt 2.0
              /environment/terrain-solid != 0
              position/h-agl-ft lt 10
          </test>
          <test logic="AND" value="1">
              gear/unit[1]/compression-ft  gt 5
              simulation/sim-time-sec gt 2.0
              /environment/terrain-solid != 0
              position/h-agl-ft lt 10
          </test>
          <test logic="AND" value="1">
              gear/unit[2]/compression-ft  gt 5
              simulation/sim-time-sec gt 2.0
              /environment/terrain-solid != 0
              position/h-agl-ft lt 10
          </test>
          <test logic="AND" value="1">
              systems/crash-detect/over-g == 1
              simulation/sim-time-sec gt 2.0
              /environment/terrain-solid == 0
              position/h-agl-ft lt 10
              velocities/vc-fps gt 50
          </test>
          <output>systems/crash-detect/crashed-on</output>
     </switch>
  </channel>




  <channel name="freeze">
      <switch name="systems/crash-detect/crashed-sw">
          <default value="systems/crash-detect/crashed-cmd"/>
          <test logic="AND" value="1">
              systems/crash-detect/crashed-on == 1
          </test>
          <test logic="AND" value="0">
              simulation/sim-time-sec lt 1.0
          </test>
          <output>systems/crash-detect/crashed-cmd</output>
     </switch>


      <kinematic name="systems/crash-detect/crashed">
          <input>systems/crash-detect/crashed-cmd</input>
          <traverse>
              <setting>
                  <position> 0 </position>
                  <time>  0 </time>
              </setting>
              <setting>
                  <position> 1 </position>
                  <time>5</time>
              </setting>
          </traverse>
      </kinematic>


      <fcs_function name="animation/crash-handling-main">
          <function>
              <product>
                  <property>systems/crash-detect/crashed</property>
                  <property>inertia/weight-lbs</property>
                  <value>20</value>
              </product>
          </function>
          <output>external_reactions/crash-force/magnitude</output>
        </fcs_function>

        <fcs_function name="animation/crash-handling-side">
            <function>
                <product>
                    <property>systems/crash-detect/crashed</property>
                    <property>inertia/weight-lbs</property>
                    <value>2</value>
                </product>
            </function>
            <output>external_reactions/crash-force-y/magnitude</output>
            <output>external_reactions/crash-force-x/magnitude</output>
        </fcs_function>

        <kinematic name="systems/crash-detect/crashed-freeze">
            <input>systems/crash-detect/crashed-cmd</input>
            <traverse>
                <setting>
                    <position> 0 </position>
                    <time>  0 </time>
                </setting>
                <setting>
                    <position> 1 </position>
                    <time>10</time>
                </setting>
            </traverse>
      </kinematic>



    <switch name="systems/crash-detect/switch1">
          <default value="simulation/integrator/position/rotational"/>
          <test value="0">
              systems/crash-detect/crashed-freeze == 1
          </test>
          <output>simulation/integrator/position/rotational</output>
    </switch>

    <switch name="systems/crash-detect/switch3">
          <default value="simulation/integrator/rate/rotational"/>
          <test value="0">
              systems/crash-detect/crashed-freeze == 1
          </test>
          <output>simulation/integrator/rate/rotational</output>
    </switch>

  </channel>


</system>
