<?xml version='1.0' encoding='UTF-8' ?>
<system name="pushback">
  <!-- copied from http://wiki.flightgear.org/Howto:Implement_pushback -->
  <property>sim/model/pushback/target-speed-fps</property>

  <channel name="pushback connected">
    <switch name="systems/pushback/linked">
      <default value="-1"/>
      <test value="0">
        /sim/model/pushback/position-norm gt 0.95
        /gear/gear/wow == 1
        gear/unit[0]/wheel-speed-fps lt 50
      </test>
    </switch>
  </channel>
    
  <channel name="nose wheel steering">
    <switch name="fcs/steer-max-deg">
      <default value="58.5"/>   <!-- pushback disconnected -->
      <test    value="70.0">    <!-- pushback connected -->
        systems/pushback/linked == 0
      </test>
    </switch>

    <pure_gain name="fcs/steer-pos-deg[0]">
      <input>fcs/steer-cmd-norm</input>
      <gain>fcs/steer-max-deg</gain>
      <output>fcs/steer-pos-deg[0]</output>
    </pure_gain>
  </channel>

  <channel name="Pushback">
    
    <summer name="systems/pushback/speed-error">
      <input>/sim/model/pushback/target-speed-fps</input>
      <input>-gear/unit[0]/wheel-speed-fps</input>
    </summer>
    
    <pid name="systems/pushback/force">
      <input>systems/pushback/speed-error</input>
      <kp>/sim/model/pushback/kp</kp>
      <ki>/sim/model/pushback/ki</ki>
      <kd>/sim/model/pushback/kd</kd>
      <trigger>systems/pushback/linked</trigger>
      <output>/sim/model/pushback/force</output>
    </pid>
    
    <switch name="systems/pushback/force-output">
      <default value="0"/>
      <test value="systems/pushback/force">
        systems/pushback/linked == 0
      </test>
      <output>external_reactions/pushback/magnitude</output>
    </switch>
    
    <fcs_function name="Pushback Force X">
      <function>
        <cos>
          <toradians><property>fcs/steer-pos-deg[0]</property></toradians>
        </cos>
      </function>
      <output>external_reactions/pushback/x</output>
    </fcs_function>
    
    <fcs_function name="Pushback Force Y">
      <function>
        <sin>
          <toradians><property>fcs/steer-pos-deg[0]</property></toradians>
        </sin>
      </function>
      <output>external_reactions/pushback/y</output>
    </fcs_function>
    
  </channel>

</system>
