Change GVL to follow our coding standards and update all the references in the FB's

This commit is contained in:
Federico Rojas
2020-03-17 14:52:19 +01:00
parent 56929e3be1
commit c99efebb07
4 changed files with 67 additions and 68 deletions

View File

@@ -42,7 +42,7 @@ AXES();]]></ST>
<Action Name="AXES" Id="{7eb32732-9b53-4934-8cd9-20ba971dd8ff}">
<Implementation>
<ST><![CDATA[FOR GVL.iAxis := 1 TO gvl_app.nAxisNum DO
aFbAxes[GVL.iAxis](stAxisStruct := gvl.axes[GVL.iAxis]);
aFbAxes[GVL.iAxis](stAxisStruct := gvl.aAxes[GVL.iAxis]);
END_FOR]]></ST>
</Implementation>
</Action>
@@ -83,7 +83,7 @@ END_IF]]></ST>
// This ACT will restore the position of an incremental axis on startup with the act position it read before losing power.
// It checks the type of axis, 0=incremental, and that the axis was stationary at shut down.
// Because 0 equates to incremental we also need to check that the data is valid, otherwise by default it would restore all axes.
// By default an axis will not restore the position unless it is set to opt-in, i.e. gvl.axes[GVL.iAxis].config.eRestorePosition is non-zero.
// By default an axis will not restore the position unless it is set to opt-in, i.e. gvl.aAxes[GVL.iAxis].config.eRestorePosition is non-zero.
// This needs to be initialised somewhere in TwinCAT code otherwise it will not be available at start up.
// A restore will only be performed on a loss of power, this code shouldn't make any changes on a reset cold, a rest origin or a download.
// There is a enum to allow for different types of restore modes, currently only one is implemented.
@@ -104,7 +104,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// Result stored in Value, 0=Inc 1=Abs, execute set during the case statement
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aFbReadEncRefSys[GVL.iAxis](
Axis := gvl.axes[GVL.iAxis].Axis,
Axis := gvl.aAxes[GVL.iAxis].Axis,
Enable := bExecuteReadEncRefSys,
ParameterNumber := MC_AxisParameter.AxisEncoderReferenceSystem,
Value=>,
@@ -114,7 +114,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// Cycle through set position function blocks for each axis
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
aFbRestorePosition[GVL.iAxis](
Axis := gvl.axes[GVL.iAxis].Axis,
Axis := gvl.aAxes[GVL.iAxis].Axis,
Execute := ,
Position := axesPersistent[GVL.iAxis].iPositionAtShutdown);
END_FOR
@@ -159,7 +159,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// Execute position restore by setting aFbRestorePosition.execute = TRUE
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[GVL.iAxis].Valid = TRUE AND aFbReadEncRefSys[GVL.iAxis].Value = 0 AND NOT(axesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
IF GVL.axes[GVL.iAxis].config.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
IF GVL.aAxes[GVL.iAxis].config.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
aFbRestorePosition[GVL.iAxis].Execute := TRUE;
END_IF
END_IF
@@ -172,7 +172,7 @@ IF bRestoreExecute AND NOT bPositionRestoreDone THEN
// bPositionRestoreDone will never get set to TRUE and will take up cycle time
FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
IF aFbReadEncRefSys[GVL.iAxis].Valid = TRUE AND aFbReadEncRefSys[GVL.iAxis].Value = 0 AND NOT(axesPersistent[GVL.iAxis].bMovingAtShutdown) THEN
IF GVL.axes[GVL.iAxis].config.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
IF GVL.aAxes[GVL.iAxis].config.eRestorePosition = E_RestorePosition.RestoreWithoutHome THEN
IF NOT aFbRestorePosition[GVL.iAxis].Done THEN
RETURN;
END_IF
@@ -195,13 +195,13 @@ END_IF]]></ST>
<Action Name="STORE_PERSISTENT" Id="{cb5c9254-2e5f-47b1-9baa-10e728a961b0}" FolderPath="POSITION_RECOVERY\">
<Implementation>
<ST><![CDATA[FOR GVL.iAxis:= 1 TO gvl_app.nAxisNum DO
axesPersistent[GVL.iAxis].iPositionAtShutdown := gvl.axes[GVL.iAxis].Axis.NcToPlc.ActPos;
IF gvl.axes[GVL.iAxis].Axis.NcToPlc.ActVelo <> 0 THEN
axesPersistent[GVL.iAxis].iPositionAtShutdown := gvl.aAxes[GVL.iAxis].Axis.NcToPlc.ActPos;
IF gvl.aAxes[GVL.iAxis].Axis.NcToPlc.ActVelo <> 0 THEN
axesPersistent[GVL.iAxis].bMovingAtShutdown := TRUE;
ELSE
axesPersistent[GVL.iAxis].bMovingAtShutdown := FALSE;
END_IF
axesPersistent[GVL.iAxis].bMovingAtShutdown := axesPersistent[GVL.iAxis].bMovingAtShutdown OR gvl.axes[GVL.iAxis].Axis.Status.Moving;
axesPersistent[GVL.iAxis].bMovingAtShutdown := axesPersistent[GVL.iAxis].bMovingAtShutdown OR gvl.aAxes[GVL.iAxis].Axis.Status.Moving;
END_FOR]]></ST>
</Implementation>
</Action>

View File

@@ -15,7 +15,7 @@ VAR_INPUT
iAxisIndex: INT; // The idex of the axis to action the method on.
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[GVL.axes[iAxisIndex].control.bEnable := TRUE;]]></ST>
<ST><![CDATA[GVL.aAxes[iAxisIndex].control.bEnable := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="mExecute" Id="{010bd927-5568-40db-a7c5-fcfe995a5cb1}">
@@ -24,7 +24,7 @@ VAR_INPUT
iAxisIndex: INT; // The idex of the axis to action the method on.
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[GVL.axes[iAxisIndex].control.bExecute := TRUE;]]></ST>
<ST><![CDATA[GVL.aAxes[iAxisIndex].control.bExecute := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="mPrepareDefaultMove" Id="{c23244d5-896c-49ad-8d8a-19390856e4dc}">
@@ -36,17 +36,17 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Prepare an axis so it is ready to action a move using target defaults when executed.
GVL.axes[iAxisIndex].control.bEnable := TRUE;
GVL.axes[iAxisIndex].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.aAxes[iAxisIndex].control.bEnable := TRUE;
GVL.aAxes[iAxisIndex].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.axes[iAxisIndex].inputs.bLimitBwd := TRUE;
GVL.axes[iAxisIndex].inputs.bLimitFwd := TRUE;
GVL.aAxes[iAxisIndex].inputs.bLimitBwd := TRUE;
GVL.aAxes[iAxisIndex].inputs.bLimitFwd := TRUE;
GVL.axes[iAxisIndex].config.fVelocity := tcUNIT_GVL.fDEFAULT_TARGET_VELOCITY;
GVL.axes[iAxisIndex].config.fAcceleration := tcUNIT_GVL.fDEFAULT_TARGET_ACCELERATION;
GVL.axes[iAxisIndex].config.fDeceleration := tcUNIT_GVL.fDEFAULT_TARGET_DECCELERATION;
GVL.axes[iAxisIndex].config.fOverride := tcUNIT_GVL.fDEFAULT_TARGET_OVERRIDE;
GVL.axes[iAxisIndex].config.fPosition := tcUNIT_GVL.fDEFAULT_POSITION;]]></ST>
GVL.aAxes[iAxisIndex].config.fVelocity := tcUNIT_GVL.fDEFAULT_TARGET_VELOCITY;
GVL.aAxes[iAxisIndex].config.fAcceleration := tcUNIT_GVL.fDEFAULT_TARGET_ACCELERATION;
GVL.aAxes[iAxisIndex].config.fDeceleration := tcUNIT_GVL.fDEFAULT_TARGET_DECCELERATION;
GVL.aAxes[iAxisIndex].config.fOverride := tcUNIT_GVL.fDEFAULT_TARGET_OVERRIDE;
GVL.aAxes[iAxisIndex].config.fPosition := tcUNIT_GVL.fDEFAULT_POSITION;]]></ST>
</Implementation>
</Method>
<Method Name="mPrepareMove" Id="{97bd5417-d0a1-4d32-8732-16310a863fcc}">
@@ -63,16 +63,16 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Prepare the axis so it is ready to action a move when executed for a given motion strategy.
GVL.axes[iAxisIndex].control.bEnable := FALSE;
GVL.axes[iAxisIndex].control.eCommand := eMotionStrategy;
GVL.aAxes[iAxisIndex].control.bEnable := FALSE;
GVL.aAxes[iAxisIndex].control.eCommand := eMotionStrategy;
GVL.axes[iAxisIndex].inputs.bLimitBwd := TRUE;
GVL.axes[iAxisIndex].inputs.bLimitFwd := TRUE;
GVL.aAxes[iAxisIndex].inputs.bLimitBwd := TRUE;
GVL.aAxes[iAxisIndex].inputs.bLimitFwd := TRUE;
GVL.axes[iAxisIndex].config.fVelocity := fTargetVelocity;
GVL.axes[iAxisIndex].config.fAcceleration := fTargetAcceleration;
GVL.axes[iAxisIndex].config.fDeceleration := fTargetDeceleration;
GVL.axes[iAxisIndex].config.fPosition := fTargetPosition;]]></ST>
GVL.aAxes[iAxisIndex].config.fVelocity := fTargetVelocity;
GVL.aAxes[iAxisIndex].config.fAcceleration := fTargetAcceleration;
GVL.aAxes[iAxisIndex].config.fDeceleration := fTargetDeceleration;
GVL.aAxes[iAxisIndex].config.fPosition := fTargetPosition;]]></ST>
</Implementation>
</Method>
<Method Name="mSetAxisDefaults" Id="{5b9336be-4414-4858-a614-0fdb2847e171}">
@@ -84,35 +84,34 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Set PLC default values for the axis. Note: Status values can take multiple cycles to updated. This is not an instant reset.
IF GVL.axes[iAxisIndex].status.bBusy THEN
GVL.axes[iAxisIndex].control.bStop := TRUE;
IF GVL.aAxes[iAxisIndex].status.bBusy THEN
GVL.aAxes[iAxisIndex].control.bStop := TRUE;
END_IF
IF GVL.axes[iAxisIndex].status.bError THEN
GVL.axes[iAxisIndex].control.bReset := TRUE;
IF GVL.aAxes[iAxisIndex].status.bError THEN
GVL.aAxes[iAxisIndex].control.bReset := TRUE;
END_IF
IF NOT GVL.axes[iAxisIndex].control.bEnable AND GVL.axes[iAxisIndex].control.bStop THEN
GVL.axes[iAxisIndex].control.bStop := FALSE;
IF NOT GVL.aAxes[iAxisIndex].control.bEnable AND GVL.aAxes[iAxisIndex].control.bStop THEN
GVL.aAxes[iAxisIndex].control.bStop := FALSE;
END_IF
GVL.axes[iAxisIndex].control.bEnable := FALSE;
GVL.axes[iAxisIndex].control.bExecute := FALSE;
GVL.axes[iAxisIndex].control.bReset := FALSE;
GVL.axes[iAxisIndex].control.bJogFwd := FALSE;
GVL.axes[iAxisIndex].control.bJogBwd := FALSE;
GVL.axes[iAxisIndex].control.bStop := FALSE;
GVL.axes[iAxisIndex].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.aAxes[iAxisIndex].control.bEnable := FALSE;
GVL.aAxes[iAxisIndex].control.bExecute := FALSE;
GVL.aAxes[iAxisIndex].control.bReset := FALSE;
GVL.aAxes[iAxisIndex].control.bJogFwd := FALSE;
GVL.aAxes[iAxisIndex].control.bJogBwd := FALSE;
GVL.aAxes[iAxisIndex].control.bStop := FALSE;
GVL.aAxes[iAxisIndex].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.axes[iAxisIndex].config.fVelocity := 0.0;
GVL.axes[iAxisIndex].config.fAcceleration := 0.0;
GVL.axes[iAxisIndex].config.fDeceleration := 0.0;
GVL.axes[iAxisIndex].config.fPosition := 0;
GVL.axes[iAxisIndex].config.fOverride := 0.0;
GVL.axes[iAxisIndex].config.nHomeSeq := 0;
GVL.aAxes[iAxisIndex].config.fVelocity := 0.0;
GVL.aAxes[iAxisIndex].config.fAcceleration := 0.0;
GVL.aAxes[iAxisIndex].config.fDeceleration := 0.0;
GVL.aAxes[iAxisIndex].config.fPosition := 0;
GVL.aAxes[iAxisIndex].config.fOverride := 0.0;
GVL.aAxes[iAxisIndex].config.nHomeSeq := 0;
GVL.axes[iAxisIndex].inputs.bLimitBwd := FALSE;
GVL.axes[iAxisIndex].inputs.bLimitFwd := FALSE;
GVL.axes[iAxisIndex].inputs.bEncLAtch := FALSE;
GVL.axes[iAxisIndex].inputs.bHomeSensor := FALSE;]]></ST>
GVL.aAxes[iAxisIndex].inputs.bLimitBwd := FALSE;
GVL.aAxes[iAxisIndex].inputs.bLimitFwd := FALSE;
GVL.aAxes[iAxisIndex].inputs.bHomeSensor := FALSE;]]></ST>
</Implementation>
</Method>
<LineIds Name="FB_tcUNIT_common">
@@ -132,7 +131,7 @@ GVL.axes[iAxisIndex].inputs.bHomeSensor := FALSE;]]></ST>
<LineId Id="17" Count="11" />
</LineIds>
<LineIds Name="FB_tcUNIT_common.mSetAxisDefaults">
<LineId Id="50" Count="29" />
<LineId Id="50" Count="28" />
<LineId Id="26" Count="0" />
</LineIds>
</POU>

View File

@@ -6,7 +6,7 @@
FUNCTION_BLOCK FB_Axis_TEST EXTENDS tcUnit.FB_TestSuite
VAR
fbCommon: FB_tcUNIT_common;
iTargetAxis: INT := 1; // The <index> of the axis within GVL.axes[<index>] to test against.
iTargetAxis: INT := 1; // The <index> of the axis within GVL.aAxes[<index>] to test against.
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Declare methods defined in the FB_Axis_TEST POU to be included (executed) in the test suite
@@ -34,7 +34,7 @@ ExpectedResult := TRUE;
fbCommon.mPrepareDefaultMove(iTargetAxis);
fbCommon.mExecute(iTargetAxis);
Result := GVL.axes[iTargetAxis].status.bBusy;
Result := GVL.aAxes[iTargetAxis].status.bBusy;
IF nCycle > nMaxCycles OR ExpectedResult = Result THEN
AssertEquals(Expected := ExpectedResult,
@@ -62,14 +62,14 @@ END_VAR]]></Declaration>
// a previous test. Therefore if we execute a move we should just check it's moved
// from the initial location not some initial default.
InitialValue := GVL.axes[iTargetAxis].config.fPosition;
InitialValue := GVL.aAxes[iTargetAxis].config.fPosition;
ExpectedResult := InitialValue + 10;
GVL.axes[iTargetAxis].config.fPosition := ExpectedResult;
GVL.aAxes[iTargetAxis].config.fPosition := ExpectedResult;
GVL.axes[iTargetAxis].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.axes[iTargetAxis].control.bExecute := TRUE;
GVL.aAxes[iTargetAxis].control.eCommand := E_MotionFunctions.MoveAbsolute;
GVL.aAxes[iTargetAxis].control.bExecute := TRUE;
Result := GVL.axes[iTargetAxis].status.fActPosition;
Result := GVL.aAxes[iTargetAxis].status.fActPosition;
IF nCycle > nCycleMax OR ExpectedResult = Result THEN
AssertEquals(Expected := ExpectedResult,
@@ -96,7 +96,7 @@ END_VAR]]></Declaration>
ExpectedResult := tcUNIT_gvl.fDEFAULT_TARGET_ACCELERATION;
fbCommon.mPrepareDefaultMove(iTargetAxis);
Result := GVL.axes[1].config.fAcceleration;
Result := GVL.aAxes[1].config.fAcceleration;
AssertEquals(Expected := ExpectedResult,
Actual := Result,
@@ -119,9 +119,9 @@ END_VAR]]></Declaration>
// example of test that requires multiple cycles to complete. Due to stateful behaviour of the axis structure.
ExpectedResult := TRUE;
GVL.axes[1].control.bEnable := ExpectedResult;
GVL.aAxes[1].control.bEnable := ExpectedResult;
Result := GVL.axes[iTargetAxis].status.bEnabled;
Result := GVL.aAxes[iTargetAxis].status.bEnabled;
IF nCycle > nMaxCycles OR ExpectedResult = Result THEN
AssertEquals(Expected := ExpectedResult,
@@ -148,11 +148,11 @@ END_VAR]]></Declaration>
// Example of using a tcUNIT assert for a specific type (in this case LREAL).
InitialValue := GVL.axes[iTargetAxis].config.fVelocity;
InitialValue := GVL.aAxes[iTargetAxis].config.fVelocity;
ExpectedResult := InitialValue + 0.5;
GVL.Axes[iTargetAxis].config.fVelocity := ExpectedResult;
GVL.aAxes[iTargetAxis].config.fVelocity := ExpectedResult;
Result := GVL.axes[iTargetAxis].config.fVelocity;
Result := GVL.aAxes[iTargetAxis].config.fVelocity;
AssertEquals_LREAL(Expected := ExpectedResult,
Actual := Result,
@@ -176,9 +176,9 @@ END_VAR]]></Declaration>
ExpectedResult := TRUE;
GVL.axes[iTargetAxis].inputs.bLimitFwd := TRUE;
GVL.aAxes[iTargetAxis].inputs.bLimitFwd := TRUE;
Result := GVL.axes[iTargetAxis].status.bFwEnabled;
Result := GVL.aAxes[iTargetAxis].status.bFwEnabled;
IF nCycle > nMaxCycles OR ExpectedResult = Result THEN
AssertEquals(Expected := ExpectedResult,