﻿<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
  <POU Name="TRWAutoWinch" Id="{aa72b193-2d29-01b1-2333-23bb7c7afbcc}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK TRWAutoWinch EXTENDS LocalBaseUserWinch IMPLEMENTS IAutoWinch, IBaseUserWinch
VAR_INPUT
	sheaveSensor : REFERENCE TO fb_SheaveMesurements;
	//LoadcellTensionWarningLimit : LREAL;
END_VAR
VAR
    signalJoystickInCenter 	: BOOL; 
	_winchAvailableForAuto : BOOL;
	{attribute 'hide'} 
	loadcellTensionWarning				: p6com.AlarmDigital(TC_Events.LocalEvents.LOADCELL_TENSION_WARNING);
END_VAR
VAR PERSISTENT
	LoadcellTensionWarningLimit : LREAL; // in Kg.
END_VAR

]]></Declaration>
    <Implementation>
      <ST><![CDATA[SUPER^();

_winchAvailableForAuto := signalJoystickInCenter AND winch.IsSpeedNull AND winch.OpState = p7type.P6OpState.RUN ;

IF _controlUnitInControl<>0 THEN
	signalJoystickInCenter := _controlUnitInControl.JoystickInCentre;
ELSE
	signalJoystickInCenter := FALSE;
END_IF

IF __ISVALIDREF(sheaveSensor) AND LoadcellTensionWarningLimit > 1 THEN
	loadcellTensionWarning(ID := DINT_TO_UDINT( winch.ID) , IDName :=  THIS^.Winch.IDname, value := sheaveSensor.Tension > LoadcellTensionWarningLimit, Timespan := T#0.1S);
END_IF

]]></ST>
    </Implementation>
    <Property Name="VelocityReference" Id="{613cabbc-0e20-04f2-3996-b9e746ea5edc}">
      <Declaration><![CDATA[PROPERTY VelocityReference : LREAL]]></Declaration>
      <Get Name="Get" Id="{66b71e48-5d2b-00e9-28a8-d0912ca78de7}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[VelocityReference := _velocityReference;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="TorqueReference" Id="{861b57be-bcdb-0f45-2848-0a4c1aab7afe}">
      <Declaration><![CDATA[PROPERTY TorqueReference : LREAL]]></Declaration>
      <Get Name="Get" Id="{da7b47ef-8cfc-0f5f-26b4-48433804a892}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[TorqueReference := _torqueReference;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="TorqueAuto" Id="{97e25826-f06e-0091-021d-c4887d27ceae}">
      <Declaration><![CDATA[// 0-1 of MAX torque
PROPERTY TorqueAuto : LREAL]]></Declaration>
      <Get Name="Get" Id="{7d2ba5af-7146-02a3-2129-b175ab4f7f5d}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[TorqueAuto := _torqueReferenceAuto;]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{e38562b5-b23d-01c2-018d-5fe8c09e4d6d}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_torqueReferenceAuto := TorqueAuto;]]></ST>
        </Implementation>
      </Set>
    </Property>
    <Property Name="AutoAvailable" Id="{98cb4d98-019a-0740-3c9c-4c08f2032aba}">
      <Declaration><![CDATA[{attribute 'monitoring' := 'call'}
{attribute 'TcRpcEnable'}
PROPERTY AutoAvailable : BOOL]]></Declaration>
      <Get Name="Get" Id="{f6a85591-a95c-03d7-1de3-f4b105917ed6}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[AutoAvailable := signalJoystickInCenter AND winch.IsSpeedNull AND winch.OpState = p7type.P6OpState.RUN;

]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="AutoMode" Id="{a18684be-8bfc-045f-0e29-2a32551bbef9}">
      <Declaration><![CDATA[PROPERTY AutoMode : BOOL // same as in Base UW, but with added 'get']]></Declaration>
      <Get Name="Get" Id="{45fa3a47-de4f-0d45-063d-57ebd0b49c39}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[AutoMode := _requestAutoMode;
]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{56ab4549-ab1a-09a7-067d-c05aaa563b43}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_requestAutoMode := AutoMode;
]]></ST>
        </Implementation>
      </Set>
    </Property>
    <Property Name="VelocityAuto" Id="{afd52648-8f34-0976-1480-c8982ed1593b}">
      <Declaration><![CDATA[// 0-1 of maximum RPM
PROPERTY VelocityAuto : LREAL]]></Declaration>
      <Get Name="Get" Id="{0284ab7c-0228-024d-29c5-7cf7b7a1f198}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[VelocityAuto := _velocityReferenceAuto;// 0-1 of MAX RPM]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{9609df41-3d02-0bfe-17db-13fa349f17bd}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_velocityReferenceAuto := VelocityAuto; // 0-1 of MAX RPM]]></ST>
        </Implementation>
      </Set>
    </Property>
    <Method Name="setOperation" Id="{c4172d6b-c313-00f3-1639-57b5aff67264}">
      <Declaration><![CDATA[{attribute 'monitoring':='call'}
{attribute 'TcRpcEnable'}
// do not use this method!!!!!!
METHOD setOperation : BOOL
VAR_INPUT
	CMD : p7type.TrawlWinchCMD;
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[]]></ST>
      </Implementation>
    </Method>
    <Property Name="WireVelocityUnfiltered" Id="{fc259e41-2655-0341-11c6-2d91be8cc956}">
      <Declaration><![CDATA[{attribute 'monitoring' := 'call'}
{attribute 'TcRpcEnable'}
// wire speed in m/s
PROPERTY PUBLIC WireVelocityUnfiltered : LREAL // Wire speed in m/s, unfiltered]]></Declaration>
      <Get Name="Get" Id="{607f6bff-ee20-0c85-2e9c-51c1363cdb41}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[WireVelocityUnfiltered := THIS^.Speed * winch.Radius * math.PI2 / 60;

//_requestedDrumRPM := ( _TRWvelocityVector * 60 ) / (SDR_ewinch.Radius * math.PI2 ) ;


]]></ST>
        </Implementation>
      </Get>
    </Property>
  </POU>
</TcPlcObject>