<?xml version="1.0"?>


<system name="Landing Gear">


    <property value="1">systems/gear/gear-constant-value-coeff-rain</property>
    <property value="1">systems/gear/gear-constant-value-coeff-snow</property>
   

    <channel name="Gear">

        <!--process which include the terrain under: water or solid-->
        <!--the conatct point processing (can be up ) and the gear animation processing ( can be down) are not sync, which simulate the aircraft behaviour on water when gear down-->

       
	    
	    <switch name="Gear Switch">
                <default value="systems/gear/gear-cmd-norm"/>
                <test  logic="AND" value="0">
                    systems/crash-detect/crashed-sw  == 1
                </test>
                <test  logic="AND" value="0">
                    simulation/terrain_sw == 0
                </test>
                <output>gear/gear-cp-cmd-norm</output>
            </switch>
            

            <kinematic name="Cp Gear Control">
                <input>gear/gear-cp-cmd-norm</input>
                <traverse>
                    <setting>
                        <position>0</position>
                        <time>0</time>
                    </setting>
                    <setting>
                        <position>1</position>
                        <time>5</time>
                    </setting>
                </traverse>
                <output>gear/unit[0]/pos-norm</output>
                <output>gear/unit[1]/pos-norm</output>
                <output>gear/unit[2]/pos-norm</output>
            </kinematic>


             <kinematic name="Gear Surface Position">
                <input>systems/gear/gear-cmd-norm</input>
                <traverse>
                    <setting>
                        <position>0</position>
                        <time>0</time>
                    </setting>
                    <setting>
                        <position>1</position>
                        <time>5</time>
                    </setting>
                </traverse>
                <output>systems/gear/gear-pos-norm</output>
            </kinematic>
	    
	    
	    
	    

            <switch name="fcs/drag-terrain-factor-switch">
                <default value="0"/>
                <test  logic="AND" value="1">
                    systems/crash-detect/crashed == 1
                </test>
                <test  logic="AND" value="1">
                    environment/terrain-solid  == 1
                    position/h-agl-ft lt 7
                   systems/gear/gear-pos-norm == 0
                </test>
            </switch>

            <switch name="fcs/drag-gear-in-water-switch">
                <default value="0"/>
                <test  logic="AND" value="1">
                    systems/crash-detect/crashed == 1
                </test>
                <test  logic="AND" value="1">
                    environment/terrain-solid  == 0
                    position/h-agl-ft lt 8
                   systems/gear/gear-pos-norm == 1
                </test>
            </switch>

    <!--<documentation>Only for 3D model animation</documentation>-->
            <switch  name="Wheel Rotation Factor" >
                <default value="0"/>
                <test  logic="AND" value="1">
                    position/h-agl-ft lt 11
                   systems/gear/gear-pos-norm == 1
                </test>
            </switch>

    <!--<documentation>Only for 3D model animation</documentation>-->
            <pure_gain name="Wheel Rotation">
                <input>velocities/u-fps</input>
                <gain>fcs/wheel-rotation-factor</gain>
            </pure_gain>

            <pure_gain name="Center Anchor Control">
		<input>fcs/brake-parking-cmd-norm</input>
                <gain>1</gain>
                <output>fcs/center-brake-cmd-norm</output>
            </pure_gain>   

        </channel>
	
	 <channel name="Main Gear Steering">
          <!-- steering efficeincy-->
	   <scheduled_gain name="systems/NWS/steer-cmd">
                <input>fcs/rudder-cmd-norm</input>
                <table>
                    <independentVar lookup="row">gear/NWS/engaged</independentVar>
                    <tableData>
                        0     -0.01
                        1     -1.0
                    </tableData>
                </table>
                <output>fcs/steer-pos-norm</output>
            </scheduled_gain>

            <scheduled_gain name="Scheduled Steer Cmd Deg">
                <input>fcs/steer-pos-norm</input>
                <table>
                    <independentVar lookup="column">gear/NWS/engaged</independentVar>
                    <independentVar lookup="row" >gear/unit[0]/wheel-speed-fps</independentVar>
                    <tableData>
                                        0       1
                        30.0       15      55
                        40.0        5       35
                        45.0        2       25
                    </tableData>
                </table>
                <output>fcs/steer-pos-deg</output>
            </scheduled_gain>
	    
            <!--<scheduled_gain name="Scheduled Steer Cmd Deg">
                <input>fcs/steer-cmd-norm</input>
                <table>
                    <independentVar>velocities/vg-fps</independentVar>
                    <tableData>
                        10.0000	80.0000
                        50.0000	15.0000
                        150.0000	2.0000
                    </tableData>
                </table>
                <output>fcs/steer-pos-deg</output>
            </scheduled_gain>-->
        </channel>

        <!--These values given with a suppose to be perfect terrain ==> with terrain-friction-factor = 1-->
        <property value="0.7">systems/gear/gear[0]/static-friction-coeff-base</property>
        <property value="0.8">systems/gear/gear[1]/static-friction-coeff-base</property>
        <property value="0.8">systems/gear/gear[2]/static-friction-coeff-base</property>

        <channel name="Additionnal Static Friction duetoTerrain">

            <!--rain and snow static coeff are only a guess-->
            <scheduled_gain name="systems/gear/terrain-static-friction-coeff-rain">
                <input>systems/gear/gear-pos-norm</input>
                <table>
                    <independentVar>/environment/metar/rain-norm</independentVar>
                    <tableData>
                        0.0000	1.0000
                        1.0000	0.40000
                    </tableData>
                </table>
            </scheduled_gain>

            <scheduled_gain name="systems/gear/terrain-static-friction-coeff-snow">
                <input>systems/gear/gear-pos-norm</input>
                <table>
                    <independentVar>/environment/metar/snow-norm</independentVar>
                    <tableData>
                        0.0000	1.0000
                        1.0000	0.20000
                    </tableData>
                </table>
            </scheduled_gain>

            <fcs_function name="fcs/gear-n-static_friction_coeff">
                <function>
                    <product>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/gear[0]/static-friction-coeff-base</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[0]/static_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-l-static_friction_coeff">
                <function>
                    <product>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/gear[1]/static-friction-coeff-base</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[1]/static_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-r-static_friction_coeff">
                <function>
                    <product>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/gear[2]/static-friction-coeff-base</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[2]/static_friction_coeff</output>
            </fcs_function>
        </channel>
        <!--These values given with a supposed to be perfect terrain ==> with terrain-friction-factor = 1-->
        <property value="0.5">systems/gear/gear[0]/dynamic-friction-coeff-base</property>
        <property value="0.3">systems/gear/gear[1]/dynamic-friction-coeff-base</property>
        <property value="0.3">systems/gear/gear[2]/dynamic-friction-coeff-base</property>

        <channel name="Additionnal Dynamic Friction duetoTerrain">

            <fcs_function name="fcs/gear-n-dynamic_friction_coeff">
                <function>
                    <product>
                        <property>systems/gear/gear[0]/dynamic-friction-coeff-base</property>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[0]/dynamic_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-l-dynamic_friction_coeff">
                <function>
                    <product>
                        <property>systems/gear/gear[1]/dynamic-friction-coeff-base</property>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[1]/dynamic_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-r-dynamic_friction_coeff">
                <function>
                    <product>
                        <property>systems/gear/gear[2]/dynamic-friction-coeff-base</property>
                        <property>environment/terrain-friction-factor</property>
                        <property>systems/gear/terrain-static-friction-coeff-rain</property>
                        <property>systems/gear/terrain-static-friction-coeff-snow</property>
                    </product>
                </function>
                <output>gear/unit[2]/dynamic_friction_coeff</output>
            </fcs_function>
        </channel>
        <!--These values given with a supposed to be perfect terrain ==> with terrain-rolling-friction = 0 -->
        <property value="0.02">systems/gear/gear[0]/rolling-friction-coeff-base</property>
        <property value="0.02">systems/gear/gear[1]/rolling-friction-coeff-base</property>
        <property value="0.02">systems/gear/gear[2]/rolling-friction-coeff-base</property>

        <channel name="Additionnal Rolling Friction duetoTerrain">
            <scheduled_gain name="systems/gear/terrain-rolling-friction-coeff-rain">
                <input>systems/gear/gear-pos-norm</input>
                <table>
                    <independentVar>/environment/metar/rain-norm</independentVar>
                    <tableData>
                        0.0000	1.0000
                        1.0000	1.0000
                    </tableData>
                </table>
            </scheduled_gain>

            <scheduled_gain name="systems/gear/terrain-rolling-friction-coeff-snow">
                <input>systems/gear/gear-pos-norm</input>
                <table>
                    <independentVar>/environment/metar/snow-norm</independentVar>
                    <tableData>
                        0.0000	1.0000
                        1.0000	1.2000
                    </tableData>
                </table>
            </scheduled_gain>
            <!--here a guess , we take in account the gear rolling-friction modified by the terrain rolling-friction-->
            <fcs_function name="fcs/gear-n-rolling_friction_coeff">
                <function>
                    <sum>
                        <product>
                            <property>environment/terrain-rolling-friction</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-rain</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-snow</property>
                        </product>
                        <property>systems/gear/gear[0]/rolling-friction-coeff-base</property>
                    </sum>
                </function>
                <output>gear/unit[0]/rolling_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-l-rolling_friction_coeff">
                <function>
                    <sum>
                        <product>
                            <property>environment/terrain-rolling-friction</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-rain</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-snow</property>
                        </product>
                        <property>systems/gear/gear[1]/rolling-friction-coeff-base</property>
                    </sum>
                </function>
                <output>gear/unit[1]/rolling_friction_coeff</output>
            </fcs_function>

            <fcs_function name="fcs/gear-r-rolling_friction_coeff">
                <function>
                    <sum>
                        <product>
                            <property>environment/terrain-rolling-friction</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-rain</property>
                            <property>systems/gear/terrain-rolling-friction-coeff-snow</property>
                        </product>
                        <property>systems/gear/gear[2]/rolling-friction-coeff-base</property>
                    </sum>
                </function>
                <output>gear/unit[2]/rolling_friction_coeff</output>
            </fcs_function>

        </channel>

        <channel name="Additionnal bmpiness  duetoTerrain">
            <!-- NOTE that channel is not realistic only for animation-->


            <!-- <scheduled_gain name="systems/gear/gear[0]/z-position-coeff">
                <input>gear/unit[0]/pos-norm</input>
                <table>
                    <independentVar>environment/terrain-load-resistance</independentVar>
                    <tableData>
                        100000	1.0000
                        100 	0.6
                    </tableData>
                </table>
            </scheduled_gain>-->

           <!-- <scheduled_gain name="systems/gear/gear[0]/bump-coeff">
                <input>gear/unit[0]/pos-norm</input>
                <table>
                    <independentVar>environment/terrain-bumpiness</independentVar>
                    <tableData>
                        0.1	0
                        1       0.2
                    </tableData>
                </table>
            </scheduled_gain>

            <scheduled_gain name="systems/gear/gear[1]/bump-coeff">
                <input>gear/unit[1]/pos-norm</input>
                <table>
                    <independentVar>environment/terrain-bumpiness</independentVar>
                    <tableData>
                        0.1	0
                        1       0.15
                    </tableData>
                </table>
            </scheduled_gain>

            <scheduled_gain name="systems/gear/gear[2]/bump-coeff">
                <input>gear/unit[2]/pos-norm</input>
                <table>
                    <independentVar>environment/terrain-bumpiness</independentVar>
                    <tableData>
                        0.1	0
                        1       0.15
                    </tableData>
                </table>
            </scheduled_gain>-->


            <!--<fcs_function name="gear-n-terrain-bump-Z">
                <function>
                    <product>
                        <property>gear/unit[0]/compression-ft</property>
                        <property>forces/fbz-gear-lbs</property>
                        <property>systems/gear/gear[0]/bump-coeff</property>
                        <property>fcs/gear-n-rolling</property>
                    </product>
                </function>
                <output>external_reactions/nose-gear-bump/magnitude</output>
            </fcs_function>

            <fcs_function name="gear-l-terrain-bump-Z">
                <function>
                    <product>
                        <property>gear/unit[1]/compression-ft</property>
                        <property>forces/fbz-gear-lbs</property>
                        <property>systems/gear/gear[1]/bump-coeff</property>
                        <property>fcs/gear-l-rolling</property>
                    </product>
                </function>
                <output>external_reactions/left-gear-bump/magnitude</output>
            </fcs_function>

            <fcs_function name="gear-r-terrain-bump-Z">
                <function>
                    <product>
                        <property>gear/unit[2]/compression-ft</property>
                        <property>forces/fbz-gear-lbs</property>
                        <property>systems/gear/gear[2]/bump-coeff</property>
                        <property>fcs/gear-r-rolling</property>
                    </product>
                </function>
                <output>external_reactions/right-gear-bump/magnitude</output>
            </fcs_function>-->
    </channel>




</system>
