﻿<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
  <POU Name="MRU_RampUpDown" Id="{b56c156d-e02d-4821-902d-ca28e7eb25f6}" SpecialFunc="None">
    <Declaration><![CDATA[// Ramps MRU data up/down from zero when activated/deavtivated
FUNCTION_BLOCK MRU_RampUpDown
VAR_INPUT
    Active : BOOL;
    AHCPosition : LREAL;
    AHCVelocity : LREAL;
    AHCAcceleration : LREAL;
END_VAR
VAR
    PositionOut : LREAL;
    VelocityOut : LREAL;
    AcclerationOut : LREAL;    
    timefactor : LREAL;
	time_value	: LREAL;
    _ready : BOOL;
END_VAR
VAR CONSTANT 
    MIX_TIME : LREAL := 5; // 5s
    SCANTIME : LREAL := 0.002;	//This value needs to be adjusted manually to (PLC scan time / MIX_TIME)
END_VAR]]></Declaration>
    <Implementation>
      <ST><![CDATA[//{warning 'AHCMixer: Check that SCANTIME corresponds with the actual task time for this part of the code'}

//Ramp up/down timefactor in MIX_TIME seconds
IF Active THEN
    time_value := LIMIT(0, (time_value + SCANTIME), MIX_TIME);
ELSE
    time_value := LIMIT(0, (time_value - SCANTIME), MIX_TIME);
END_IF
timefactor := time_value / MIX_TIME ;

PositionOut := timefactor * AHCPosition;
VelocityOut := timefactor * AHCVelocity;
AcclerationOut := timefactor * AHCAcceleration;


_ready := Active AND timefactor > 0.99;


]]></ST>
    </Implementation>
    <Property Name="Velocity" Id="{35e834ae-cbb9-4a03-81c5-b229e5e13f83}">
      <Declaration><![CDATA[PROPERTY Velocity : LREAL]]></Declaration>
      <Get Name="Get" Id="{44a3631d-b05a-472b-a6f6-c65bdb7958cc}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[Velocity := VelocityOut;

]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="Acceleration" Id="{a4589675-565e-404c-851a-9025f059c0b8}">
      <Declaration><![CDATA[PROPERTY Acceleration : LREAL]]></Declaration>
      <Get Name="Get" Id="{578a8ac0-739d-4887-bdff-3eb4bd680092}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[Acceleration := AcclerationOut;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="Ready" Id="{b1d3fae4-bd5b-4508-8689-d80781986427}">
      <Declaration><![CDATA[PROPERTY Ready : BOOL]]></Declaration>
      <Get Name="Get" Id="{3690f9b1-0b76-4e49-b0b3-4a7ff503c498}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[Ready := _ready;

]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="Position" Id="{b5aa5a3a-8e18-487c-bfda-74130b23e6cf}">
      <Declaration><![CDATA[PROPERTY Position : LREAL]]></Declaration>
      <Get Name="Get" Id="{256e5811-81e7-4b5f-b66e-fd0a48ee9eff}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[Position := PositionOut;


]]></ST>
        </Implementation>
      </Get>
    </Property>
  </POU>
</TcPlcObject>