﻿<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
  <POU Name="AutoWinch" Id="{d6ecf686-81b7-4e14-9e4b-ac63998eb186}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK AutoWinch 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="AutoMode" Id="{221566c4-5d96-4d14-9474-a352cae8768b}">
      <Declaration><![CDATA[PROPERTY AutoMode : BOOL // same as in Base UW, but with added 'get']]></Declaration>
      <Set Name="Set" Id="{911e310e-fc1f-4ecf-b9bd-790440256e43}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_requestAutoMode := AutoMode;
]]></ST>
        </Implementation>
      </Set>
      <Get Name="Get" Id="{a824d9ac-bf61-41d5-b54c-49e058d97358}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[AutoMode := _requestAutoMode;
]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="AutoAvailable" Id="{23675ce6-603c-438d-9f12-395fdbc9f3ca}">
      <Declaration><![CDATA[{attribute 'monitoring' := 'call'}
{attribute 'TcRpcEnable'}
PROPERTY AutoAvailable : BOOL]]></Declaration>
      <Get Name="Get" Id="{9df50002-333b-4b69-974a-8ed441b35abf}">
        <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="WireVelocityUnfiltered" Id="{6fddb9c1-77df-089f-0d02-9d86f9313877}">
      <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="{90387bfc-3ff7-06a4-2985-bcd3fe1b5880}">
        <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>
    <Property Name="TorqueAuto" Id="{7d98df17-71f3-4b4f-8cd5-5d17a9ec0bda}">
      <Declaration><![CDATA[// 0-1 of MAX torque
PROPERTY TorqueAuto : LREAL]]></Declaration>
      <Get Name="Get" Id="{512ff792-fca1-4960-98e6-8c1d55139887}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[TorqueAuto := _torqueReferenceAuto;]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{b41433a2-091b-4cd6-b502-9400a80ab84b}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_torqueReferenceAuto := TorqueAuto;]]></ST>
        </Implementation>
      </Set>
    </Property>
    <Property Name="TorqueReference" Id="{c3c25bfb-c5c4-0b1b-2662-2f7f45f00287}">
      <Declaration><![CDATA[PROPERTY TorqueReference : LREAL]]></Declaration>
      <Get Name="Get" Id="{c5d963c8-bf88-0cc8-3f89-eb4096fba7d6}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[TorqueReference := _torqueReference;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Method Name="setOperation" Id="{c8715f28-f936-4c37-94b0-e4ffccc030af}">
      <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="VelocityReference" Id="{d8ebce17-08ad-0a95-15a7-79df54d28246}">
      <Declaration><![CDATA[PROPERTY VelocityReference : LREAL]]></Declaration>
      <Get Name="Get" Id="{19bde7f8-1145-0f58-356f-e62527a221e9}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[VelocityReference := _velocityReference;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="VelocityAuto" Id="{f1d345e3-a403-4003-9083-df219aec5378}">
      <Declaration><![CDATA[// 0-1 of maximum RPM
PROPERTY VelocityAuto : LREAL]]></Declaration>
      <Set Name="Set" Id="{25e69b3c-3cad-483d-93e7-62a0591a78cd}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[_velocityReferenceAuto := VelocityAuto; // 0-1 of MAX RPM]]></ST>
        </Implementation>
      </Set>
      <Get Name="Get" Id="{bd90fca7-c425-4547-bd86-75b883c39113}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[VelocityAuto := _velocityReferenceAuto;// 0-1 of MAX RPM]]></ST>
        </Implementation>
      </Get>
    </Property>
  </POU>
</TcPlcObject>