<?xml version="1.0" encoding="UTF-8"?>

<ExportedUserProgram
    Version="1.0.0">
   <VariableTable>
   <Variable
       Offset="40"
       TagName="GainsTimeRequested"
       Format="REAL"
       Units="s"
       DefaultValue="1"
       Description="Set to the desired ramp time."/>
   <Variable
       Offset="41"
       TagName="GainsTimeCurrent"
       Format="REAL"
       Units="s"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="42"
       TagName="GainsTimeRatio"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="43"
       TagName="Gains_Init_P"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="44"
       TagName="Gains_Init_I"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="45"
       TagName="Gains_Init_D"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="46"
       TagName="Gains_Init_VFFP"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="47"
       TagName="Gains_Init_VFFN"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="48"
       TagName="Gains_Init_AFF"
       Format="REAL"
       DefaultValue="0"
       Description="Do not edit. Set by the user program."/>
   <Variable
       Offset="51"
       TagName="Gains_Final_P"
       Format="REAL"
       DefaultValue="100"
       Description="Set to the desired gains."/>
   <Variable
       Offset="52"
       TagName="Gains_Final_I"
       Format="REAL"
       DefaultValue="200"
       Description="Set to the desired gains."/>
   <Variable
       Offset="53"
       TagName="Gains_Final_D"
       Format="REAL"
       DefaultValue="2"
       Description="Set to the desired gains."/>
   <Variable
       Offset="54"
       TagName="Gains_Final_VFFP"
       Format="REAL"
       DefaultValue="2.2"
       Description="Set to the desired gains."/>
   <Variable
       Offset="55"
       TagName="Gains_Final_VFFN"
       Format="REAL"
       DefaultValue="2.4"
       Description="Set to the desired gains."/>
   <Variable
       Offset="56"
       TagName="Gains_Final_AFF"
       Format="REAL"
       DefaultValue="0.06"
       Description="Set to the desired gains."/>
</VariableTable>
   <DiscreteIO/>
   <UserProgram
    Name="RampToNewGains"
    Type="STEP"
    Number="4"
    Desc="Ramps gains to new gains linearly over time. This is to prevent problems from abruptly applying gains to an axis that is currently moving.&#13;&#10;&#13;&#10;The user must set the following variables:&#13;&#10;&#13;&#10;1. GainsTimeRequested. This is the length of the ramp.&#13;&#10;2. The requested gains:&#13;&#10; &#32;&#32;&#32;Gains_Final_P&#13;&#10; &#32;&#32;&#32;Gains_Final_I&#13;&#10; &#32;&#32;&#32;Gains_Final_D&#13;&#10; &#32;&#32;&#32;Gains_Final_VFFP&#13;&#10; &#32;&#32;&#32;Gains_Final_VFFN&#13;&#10; &#32;&#32;&#32;Gains_Final_AFF&#13;&#10;"
    SingleInstance="True"
    TaskMask="32767">
   <ProgramBlock
       Type="STEP">
      <Comment
          Comment="Initialize values."/>
      <Step>
         <Expression
             Src="//zero the variable that keeps track of the ramping time.&#13;&#10;GainsTimeCurrent := 0.0;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#13;&#10;&#13;&#10;//Store the current gains in variables.&#13;&#10;Gains_Init_P := _Axis[0].PropGain;&#13;&#10;Gains_Init_I := _Axis[0].IntGain;&#13;&#10;Gains_Init_D := _Axis[0].DiffGain;&#13;&#10;Gains_Init_VFFP := _Axis[0].VelFFwdP;&#13;&#10;Gains_Init_VFFN := _Axis[0].VelFFwdN;&#13;&#10;Gains_Init_AFF := _Axis[0].AccFFwd;"/>
      </Step>
      <Transition>
         <Jump
             Type="NEXT"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP">
      <Comment
          Comment="Calculate the gains for the current moment in the ramp. Repeats until the ramp is complete."/>
      <Step>
         <Expression
             Src="//Update the time variable.&#13;&#10;GainsTimeCurrent := GainsTimeCurrent + _LoopTime;&#13;&#10;&#13;&#10;//Calculate the current location in the ramp&#13;&#10;GainsTimeRatio := &#32;GainsTimeCurrent / GainsTimeRequested;&#13;&#10;&#13;&#10;//Interpolate the gain values and apply to the gains.&#13;&#10;_Axis[0].PropGain := Gains_Init_P + (Gains_Final_P - Gains_Init_P) * GainsTimeRatio;&#13;&#10;_Axis[0].IntGain := Gains_Init_I + (Gains_Final_I - Gains_Init_I) * GainsTimeRatio;&#13;&#10;_Axis[0].DiffGain := Gains_Init_D + (Gains_Final_D - Gains_Init_D) * GainsTimeRatio;&#13;&#10;_Axis[0].VelFFwdP := Gains_Init_VFFP + (Gains_Final_VFFP - Gains_Init_VFFP) * GainsTimeRatio;&#13;&#10;_Axis[0].VelFFwdN := Gains_Init_VFFN + (Gains_Final_VFFN - Gains_Init_VFFN) * GainsTimeRatio;&#13;&#10;_Axis[0].AccFFwd := Gains_Init_AFF + (Gains_Final_AFF - Gains_Init_AFF) * GainsTimeRatio;&#13;&#10;"/>
      </Step>
      <Transition>
         <CheckCondition
             Type="CASE-ELSE"
             Condition="GainsTimeCurrent &gt;= GainsTimeRequested"
             True="Next"
             False="Repeat"/>
      </Transition>
   </ProgramBlock>
   <ProgramBlock
       Type="STEP">
      <Step/>
      <Transition>
         <End/>
      </Transition>
   </ProgramBlock>
</UserProgram>
</ExportedUserProgram>
