<?xml version="1.0"?>
<!-- 

  
-->
<system name="NoseWheelSteering">

  <property>fcs/tiller-cmd-norm</property>
  <!--property value="0">fcs/realism/tiller-enabled</property-->
  <property value="0.0083333333333333">fcs/steering/sim-time-deltat</property>
  <property value="1000">fcs/steering/strut-moi-z</property>

  <channel name="Steering">

  <!-- Calculated sim-time delta t -->

    <!-- <fcs_function name="fcs/steering/sim-time-deltat">
      <function>
        <difference>
          <property>sim-time-sec</property>
          <property>sim-time-sec-old</property>
        </difference>
      </function>
    </fcs_function>

    <pure_gain name="sim-time-sec-old">
      <input>sim-time-sec</input>
      <gain>1</gain>
      <output>sim-time-sec-old</output>
    </pure_gain> -->
          
  <!-- Calculation of castered section -->

    <switch name="fcs/steering/speed-not-zero">
      <default value="1"/>
      <test value="0">
        gear/unit[0]/wheel-speed-fps LE 0.1
        gear/unit[0]/wheel-speed-fps GE -0.1
      </test>
    </switch>

  <!-- Calculating side force, generated by tyre -->

    <fcs_function name="fcs/steering/tyre-side-force-lbs">
      <function>
        <product>
          <property>gear/unit[0]/side_friction_coeff</property>
          <property>gear/unit[0]/compression-ft</property>
          <value>15000</value> <!-- 15000 lbs/ft (nosewheel spring stiffness) -->
          <property>fcs/steering/speed-not-zero</property>
        </product>
      </function>
    </fcs_function>

  <!-- Calculating torque, generated by tyre -->

    <fcs_function name="fcs/steering/tyre-torque-lbsft">
      <function>
        <product>
          <property>fcs/steering/tyre-side-force-lbs</property>
          <value>0.264</value> <!-- arm from axis of rotation to tyre contact point -->
        </product>
      </function>
    </fcs_function>

  <!-- Calculating angular acceleration from tyre and centering -->

    <fcs_function name="fcs/steering/angular-accel-radsec2">
      <function>
        <quotient>
          <sum>
            <property>fcs/steering/tyre-torque-lbsft</property>
            <property>fcs/steering/centering-torque-lbsft</property>
          </sum>
          <property>fcs/steering/strut-moi-z</property>
        </quotient>
      </function>
    </fcs_function>

  <!-- Calculating angular speed after tyre and centering torque -->

    <fcs_function name="fcs/steering/angular-velocity-before-damping-degsec">
      <function>
        <sum>
          <product>
            <property>fcs/steering/angular-accel-radsec2</property>
            <property>fcs/steering/sim-time-deltat</property>
            <value>57.295779513</value> <!-- radtodeg-->
          </product>
          <property>fcs/steering/angular-velocity-real-degsec</property>
        </sum>
      </function>
    </fcs_function>

  <!-- Calculating damping torque -->

    <scheduled_gain>
      <input>-fcs/steering/angular-velocity-before-damping-degsec</input>
        <table>
          <independentVar> gear/unit[0]/wheel-speed-fps </independentVar>
          <tableData>
             0           2000
             2           2000
             5            200
          </tableData>
        </table>
      <output>fcs/steering/damping-torque-lbsft</output>
    </scheduled_gain>

  <!-- Calculating angular acceleration from damping -->

    <fcs_function name="fcs/steering/angular-accel-damping-radsec2">
      <function>
        <quotient>
          <property>fcs/steering/damping-torque-lbsft</property>
          <property>fcs/steering/strut-moi-z</property>
        </quotient>
      </function>
    </fcs_function>

  <!-- Calculating angular speed after tyre and centering torque -->

    <fcs_function name="fcs/steering/angular-velocity-degsec">
      <function>
        <sum>
          <product>
            <property>fcs/steering/angular-accel-damping-radsec2</property>
            <property>fcs/steering/sim-time-deltat</property>
            <value>57.295779513</value> <!-- radtodeg-->
          </product>
          <property>fcs/steering/angular-velocity-before-damping-degsec</property>
        </sum>
      </function>
    </fcs_function>

  <!-- Calculating amount of movement after all forces -->

    <pure_gain name="fcs/steering/angle-shift-deg">
      <input>fcs/steering/angular-velocity-degsec</input>
      <gain>fcs/steering/sim-time-deltat</gain>
    </pure_gain>

    <summer name="fcs/steering/steer-cmd-deg-castered">
      <input>fcs/steering/steer-pos-deg</input>
      <input>fcs/steering/angle-shift-deg</input>
      <clipto>
        <min>-45</min>
        <max>45</max>
      </clipto>
    </summer>

    <pure_gain name="fcs/steering/steer-cmd-norm-castered">
      <input>fcs/steering/steer-cmd-deg-castered</input>
      <gain>0.0222222222</gain>
    </pure_gain>

  <!-- Calculation of steerable section -->
         
    <scheduled_gain name="fcs/steering/steer-cmd-norm">
      <input>fcs/steer-cmd-norm</input>
      <table>
        <independentVar> gear/steering </independentVar>
        <tableData>
          10            0.2222222
          45            1.0
        </tableData>
      </table>
    </scheduled_gain>  

    <switch name="fcs/steering/steer-cmd-norm-realism">
      <default value="fcs/steering/steer-cmd-norm"/>
      <test value="fcs/tiller-cmd-norm">
        fcs/realism/tiller-enabled == 1
        gear/steering == 45
      </test>
    </switch>   

    <switch name="fcs/steering/steer-cmd-norm-overall">
      <default value="fcs/steering/steer-cmd-norm-final"/>
      <test value="fcs/steering/steer-cmd-norm-realism">
        gear/nose-wheel-steering == 1
        gear/unit[0]/WOW == 1
      </test>
    </switch>

    <kinematic name="fcs/steering/steer-cmd-norm-switched-kinematic">
      <input>fcs/steering/steer-cmd-norm-overall</input>
        <traverse>
          <setting>
            <position>-1</position>
            <time>0</time>
          </setting>
          <setting>
            <position>1</position>
            <time>8</time>
          </setting>
        </traverse>
    </kinematic>
	  
  <!-- Calculation of summed deflection -->

    <switch name="fcs/steering/steer-cmd-norm-final">
      <default value="fcs/steering/steer-cmd-norm-castered"/>
      <test value="fcs/steering/steer-cmd-norm-switched-kinematic">
        gear/nose-wheel-steering == 1
        gear/unit[0]/WOW == 1
      </test>
    </switch>

    <pure_gain name="fcs/steering/steer-pos-deg-old">
      <input>fcs/steering/steer-pos-deg</input>
      <gain>1</gain>
    </pure_gain>

    <pure_gain name="fcs/steering/steer-pos-deg">
      <input>fcs/steering/steer-cmd-norm-final</input>
      <gain>45</gain>
      <output>fcs/steer-pos-deg</output>
    </pure_gain>

    <fcs_function name="fcs/steering/angular-velocity-real-degsec">
      <function>
        <quotient>
          <difference>
            <property>fcs/steering/steer-pos-deg</property>
            <property>fcs/steering/steer-pos-deg-old</property>
          </difference>
            <property>fcs/steering/sim-time-deltat</property>
        </quotient>
      </function>
    </fcs_function>

  <!-- Calculating centering torque for centering wheel after take-off -->

    <fcs_function name="fcs/steering/centering-torque-lbsft">
      <function>
        <product>
          <table>
            <independentVar>fcs/steering/steer-pos-deg</independentVar>
            <tableData>
             -25        0
             -22.5      0.08
             -20        0.12
             -17.5      0.2
             -15        0.31
             -12.5      0.38
             -10        0.42
             -7.5       0.55
             -5         0.6
             -2.5       0.77
             0          0
             2.5        -0.77
             5          -0.6
             7.5        -0.55
             10         -0.42
             12.5       -0.38
             15         -0.31
             17.5       -0.2
             20         -0.12
             22.5       -0.08
             25         0    
            </tableData>
          </table>
          <value>100</value> <!-- max moment for centering, just guess -->
        </product>
      </function>
    </fcs_function>

  </channel>

</system>
