<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
  <POU Name="FB_Axis" Id="{487c77f0-5c2e-429e-aba8-36468454093c}" SpecialFunc="None">
    <Declaration><![CDATA[FUNCTION_BLOCK FB_Axis
VAR_OUTPUT
	// =============== State variables ========================
	bError							: BOOL;					// Error signal
	nErrorID						: UDINT;				// Error ID
	bMoves							: BOOL;					// Status of moving
END_VAR
VAR	
	// =============== Done signals of Halt and Reset =========
	bResetDone						: BOOL;					// Status of function block MC_Reset
	bHaltDone						: BOOL;					// Status of function block MC_Halt

	// =============== State variables ========================
	bStatusEnable					: BOOL;					// Enable feedback
	
	// =============== Velocity, override =====================
	fVelocity						: LREAL;				// Target velocity
	fOverride 						: LREAL := 100.0;		// Override 100%
	
	// =============== Trigger function blocks ================
	fbTriggerHalt					: R_TRIG;				// Trigger to recognize rising edge of halt input
	fbTriggerReset					: R_TRIG;				// Trigger to recognize rising edge of reset input
	
	// =============== Axis reference =========================
	AxisRef							: AXIS_REF;				// Axis reference (process data plc/nc)
	
	// =============== Motion function blocks =================
	fbMcPower 						: MC_Power;				// FB for enable and override
	fbMcReset 						: MC_Reset;				// FB to reset axis
	fbMcStop 						: MC_Stop;				// FB to stop axis
	fbMcHalt						: MC_Halt;				// FB to halt axis
	fbMcMove						: MC_MoveVelocity;		// FB to move axis (velocity movement)	

END_VAR]]></Declaration>
    <Implementation>
      <ST><![CDATA[// =========================================================
;
// =========================================================]]></ST>
    </Implementation>
    <Property Name="bState_Enable" Id="{ad3e7b1c-40c4-43ba-8bb9-edf146edbdff}">
      <Declaration><![CDATA[PROPERTY bState_Enable : BOOL]]></Declaration>
      <Get Name="Get" Id="{69f0ee73-b6e2-418c-bf6f-8142845a3c2d}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[bState_Enable := bStatusEnable;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="bState_HaltDone" Id="{1a756cd2-ba77-499a-b8bc-2b83846c1594}">
      <Declaration><![CDATA[PROPERTY bState_HaltDone : BOOL]]></Declaration>
      <Get Name="Get" Id="{2d34dbba-a910-4d4f-9a8e-58d834d456a9}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[bState_HaltDone := bHaltDone;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Property Name="bState_ResetDone" Id="{adc14582-72d9-4c66-8bea-86b47517a65e}">
      <Declaration><![CDATA[PROPERTY bState_ResetDone : BOOL]]></Declaration>
      <Get Name="Get" Id="{593dfef6-5aee-4ede-9af7-e6b13fa3650d}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[bState_ResetDone := bResetDone;]]></ST>
        </Implementation>
      </Get>
    </Property>
    <Method Name="CylicCheck" Id="{638b0465-2d3e-4be8-974d-05f957a15a4f}">
      <Declaration><![CDATA[METHOD PUBLIC CylicCheck
VAR_INPUT
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[AxisRef.ReadStatus();

]]></ST>
      </Implementation>
    </Method>
    <Method Name="Enable" Id="{4320b286-c423-486d-91c3-66bef24ad7e9}">
      <Declaration><![CDATA[METHOD Enable
VAR_INPUT
	bEnable		: BOOL;
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[// =========================================================

fbMCPower(	Enable 			:= bEnable, 
			Enable_Positive	:= bEnable, 
			Enable_Negative	:= bEnable, 
			Override		:= fOverride,
			Axis			:= AxisRef,
			Status			=> bStatusEnable,
            Error           => bError,
            ErrorID         => nErrorID);
			




bMoves := AxisRef.Status.Moving;

// =========================================================]]></ST>
      </Implementation>
    </Method>
    <Property Name="fTargetVelocity" Id="{81b56e8e-d906-4214-86c5-1b29ad1f0f9f}">
      <Declaration><![CDATA[PROPERTY fTargetVelocity : LREAL]]></Declaration>
      <Get Name="Get" Id="{1027e315-605e-40a9-a731-7ef3f9a1435d}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[fTargetVelocity := fVelocity;]]></ST>
        </Implementation>
      </Get>
      <Set Name="Set" Id="{2912d097-35fb-4fae-80b6-3ce4bfaf9f7f}">
        <Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
        <Implementation>
          <ST><![CDATA[fVelocity := fTargetVelocity;]]></ST>
        </Implementation>
      </Set>
    </Property>
    <Method Name="Halt" Id="{5c7c2e1d-26ff-4148-b22f-92843852e81c}">
      <Declaration><![CDATA[METHOD Halt
VAR_INPUT
	bDriveHalt		: BOOL;					// Request stop
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[// =========================================================


IF bDriveHalt THEN
	fbMCMove(	Execute	:= FALSE,  Axis := AxisRef);
	fbMcHalt(	Execute	:= TRUE, 
                Axis 	:= AxisRef,
                Error   => bError,
				Done    => bHaltDone,
                ErrorID => nErrorID);
ELSIF fbMcHalt.Done OR fbMcHalt.Error OR fbMcHalt.CommandAborted THEN
	fbMcHalt(	Execute	:= FALSE,
				Axis 	:= AxisRef);
END_IF

bHaltDone:= fbMcHalt.Done AND  bDriveHalt;




// =========================================================]]></ST>
      </Implementation>
    </Method>
    <Method Name="MoveBw" Id="{8e4015e5-b08c-4b4d-bf13-2ec9685ead94}">
      <Declaration><![CDATA[METHOD MoveBw
VAR_INPUT
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[// =========================================================



// Not error
IF NOT (fbMcMove.Error AND fbMCMove.CommandAborted) THEN
	fbMCMove(	Execute 	:= TRUE,
				Velocity 	:= fVelocity,
				Direction 	:= MC_Negative_Direction,
				Axis 		:= AxisRef,
                Error       => bError,
                ErrorID     => nErrorID );
ELSE
		fbMCMove(	Execute	:= FALSE,
				Axis 	:= AxisRef);
END_IF



// =========================================================]]></ST>
      </Implementation>
    </Method>
    <Method Name="MoveFw" Id="{eb86a4d0-b9ce-4106-a5a1-d5cdba70d11f}">
      <Declaration><![CDATA[METHOD MoveFw
VAR_INPUT
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[// =========================================================

// Not error
IF NOT (fbMcMove.Error AND fbMCMove.CommandAborted) THEN
	fbMCMove(	Execute 	:= TRUE,
				Velocity 	:= fVelocity,
				Direction 	:= MC_Positive_Direction,
				Axis 		:= AxisRef,
                Error       => bError,
                ErrorID     => nErrorID );
ELSE
		fbMCMove(	Execute	:= FALSE,
				Axis 	:= AxisRef);
END_IF

// =========================================================]]></ST>
      </Implementation>
    </Method>
    <Method Name="Reset" Id="{cd6b141a-cee7-444d-8db8-35db8f8a1558}">
      <Declaration><![CDATA[METHOD Reset
VAR_INPUT
	bDriveReset		: BOOL;					// Request reset
END_VAR
]]></Declaration>
      <Implementation>
        <ST><![CDATA[// =========================================================
IF bDriveReset THEN
	fbMcReset(	Execute	:= TRUE, 
                Axis 	:= AxisRef,
                Error   => bError,
                ErrorID => nErrorID);
ELSIF fbMcReset.Done OR fbMcReset.Error  THEN
	fbMcReset(	Execute	:= FALSE,
				Axis 	:= AxisRef);
END_IF

bResetDone:= fbMcReset.Done AND bDriveReset;

// =========================================================]]></ST>
      </Implementation>
    </Method>
    <LineIds Name="FB_Axis">
      <LineId Id="3" Count="1" />
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.bState_Enable.Get">
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.bState_HaltDone.Get">
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.bState_ResetDone.Get">
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.CylicCheck">
      <LineId Id="77" Count="1" />
      <LineId Id="6" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.Enable">
      <LineId Id="3" Count="7" />
      <LineId Id="25" Count="1" />
      <LineId Id="11" Count="0" />
      <LineId Id="15" Count="5" />
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.fTargetVelocity.Get">
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.fTargetVelocity.Set">
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.Halt">
      <LineId Id="3" Count="0" />
      <LineId Id="56" Count="0" />
      <LineId Id="4" Count="1" />
      <LineId Id="7" Count="0" />
      <LineId Id="51" Count="3" />
      <LineId Id="50" Count="0" />
      <LineId Id="9" Count="0" />
      <LineId Id="11" Count="0" />
      <LineId Id="55" Count="0" />
      <LineId Id="12" Count="0" />
      <LineId Id="58" Count="0" />
      <LineId Id="57" Count="0" />
      <LineId Id="13" Count="0" />
      <LineId Id="22" Count="1" />
      <LineId Id="36" Count="0" />
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.MoveBw">
      <LineId Id="3" Count="0" />
      <LineId Id="27" Count="1" />
      <LineId Id="4" Count="6" />
      <LineId Id="29" Count="4" />
      <LineId Id="11" Count="1" />
      <LineId Id="22" Count="1" />
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.MoveFw">
      <LineId Id="3" Count="2" />
      <LineId Id="27" Count="9" />
      <LineId Id="22" Count="1" />
      <LineId Id="2" Count="0" />
    </LineIds>
    <LineIds Name="FB_Axis.Reset">
      <LineId Id="3" Count="0" />
      <LineId Id="34" Count="0" />
      <LineId Id="36" Count="8" />
      <LineId Id="4" Count="0" />
      <LineId Id="29" Count="0" />
      <LineId Id="2" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>