Skip to content

Commit

Permalink
Get track length from XTS_Utility close #65
Browse files Browse the repository at this point in the history
  • Loading branch information
netbymatt committed Dec 11, 2024
1 parent 535306a commit 3cd8e71
Show file tree
Hide file tree
Showing 14 changed files with 425 additions and 449 deletions.
3 changes: 2 additions & 1 deletion Base Project/Main/DUTs/TrackCyclicState.TcDUT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
<DUT Name="TrackCyclicState" Id="{a3d439c8-3e7b-0821-0269-26f007c6033b}">
<Declaration><![CDATA[{attribute 'qualified_only'}
{attribute 'strict'}
Expand All @@ -9,6 +9,7 @@ TYPE TrackCyclicState :
CHECK_ZERO_CASE := 10,
CHECK_TRACK_COUNT := 20,
GET_OTCID := 30,
GET_LENGTH := 40,
SET_INITIALIZED := 100
);
END_TYPE
Expand Down
5 changes: 2 additions & 3 deletions Base Project/Main/GVLs/GVL.TcGVL
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
<GVL Name="GVL" Id="{73e6a867-4426-4dae-a583-2a717b275c1c}">
<Declaration><![CDATA[{attribute 'qualified_only'}
VAR_GLOBAL CONSTANT
TRACK_LENGTH : LREAL := 4000; // This should be set to the exact length [mm] of the track system
NUM_MOVERS : USINT := 6; // This should be set to the exact number of movers on the system
// The following should be set to a value **equal to or greater than** the number of objectives needed
Expand All @@ -25,6 +23,7 @@ VAR_GLOBAL CONSTANT
END_VAR
VAR_GLOBAL
newCallTime: LREAL;
SET_INITIALIZED: INT;
END_VAR]]></Declaration>
</GVL>
</TcPlcObject>
8 changes: 7 additions & 1 deletion Base Project/Main/ITFs/iTrack.TcIO
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
<Itf Name="iTrack" Id="{41e6f11d-1951-01da-13f4-8ac69ce6b873}">
<Declaration><![CDATA[INTERFACE iTrack
]]></Declaration>
Expand Down Expand Up @@ -38,6 +38,12 @@ END_VAR
<Declaration><![CDATA[]]></Declaration>
</Get>
</Property>
<Property Name="Length" Id="{b9318c9f-bf2d-07e7-2a22-8d470bdb0399}" FolderPath="Properties\">
<Declaration><![CDATA[PROPERTY Length : LREAL]]></Declaration>
<Get Name="Get" Id="{e0e836e5-de2f-00fe-0771-f9b8048f52bc}">
<Declaration><![CDATA[]]></Declaration>
</Get>
</Property>
<Property Name="OTCID" Id="{7742d262-0d22-0599-170c-d4a1b40d3165}" FolderPath="Properties\">
<Declaration><![CDATA[PROPERTY OTCID : OTCID]]></Declaration>
<Get Name="Get" Id="{c75f237a-f500-089c-29f9-aa12a02b9221}">
Expand Down
3 changes: 3 additions & 0 deletions Base Project/Main/POUs/MAIN.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ nextStation := 4;]]></ST>
// Add all PositionTriggers to the Mediator
FOR i := 0 TO GVL.NUM_POSITIONTRIGGERS - 1 DO
System.AddPositionTrigger( PositionTrigger[i] );
PositionTrigger[i].SetTrack(Track[1]);
END_FOR
// Add all Stations to the Mediator
FOR i := 0 TO GVL.NUM_STATIONS - 1 DO
System.AddStation( Station[i] );
Station[i].SetTrack(Track[1]);
END_FOR
// Add all Tracks to the Mediator
Expand All @@ -264,6 +266,7 @@ nextStation := 4;]]></ST>
// Add all Zones to the Mediator
FOR i := 0 TO GVL.NUM_ZONES - 1 DO
System.AddZone( Zone[i] );
Zone[i].SetTrack(Track[1]);
END_FOR]]></ST>
</Implementation>
</Action>
Expand Down
12 changes: 6 additions & 6 deletions Base Project/Main/POUs/XTS/Mover.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ FOR i := 1 TO GVL.NUM_MOVERS DO
// remain within the same lap
IF currentDifference < 0 THEN
currentDifference := currentDifference + GVL.TRACK_LENGTH;
currentDifference := currentDifference + internalTrack^.Length;
END_IF
IF currentDifference < minimumDifference THEN
Expand Down Expand Up @@ -1352,7 +1352,7 @@ FOR i := 1 TO GVL.NUM_MOVERS DO
// remain within the same lap
IF currentDifference < 0 THEN
currentDifference := currentDifference + GVL.TRACK_LENGTH;
currentDifference := currentDifference + internalTrack^.Length;
END_IF
IF currentDifference < minimumDifference THEN
Expand Down Expand Up @@ -1774,8 +1774,8 @@ ELSE // let 'er rip
syncPos := internalMasterMover.AxisReference.NcToPlc.ActPos - internalGap;
CWDistToSync := MODABS( syncPos - THIS^.AxisReference.NcToPlc.ActPos, GVL.TRACK_LENGTH );
CWDistToMaster := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - THIS^.AxisReference.NcToPlc.ActPos, GVL.TRACK_LENGTH );
CWDistToSync := MODABS( syncPos - THIS^.AxisReference.NcToPlc.ActPos, internalTrack^.Length );
CWDistToMaster := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - THIS^.AxisReference.NcToPlc.ActPos, internalTrack^.Length );
IF fbGearInPosMoverCA[0].Busy = FALSE THEN
Expand All @@ -1785,7 +1785,7 @@ ELSE // let 'er rip
fbGearInPosMoverCA[0].RatioDenumerator := 1;
fbGearInPosMoverCA[0].MasterSyncPosition := internalMasterMover.AxisReference.NcToPlc.ActPos;
fbGearInPosMoverCA[0].SlaveSyncPosition := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - internalGap, GVL.TRACK_LENGTH);
fbGearInPosMoverCA[0].SlaveSyncPosition := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - internalGap, internalTrack^.Length);
fbGearInPosMoverCA[0].SyncStrategy := mcSyncStrategyEarly;
fbGearInPosMoverCA[0].SyncMode := SEL( CWDistToSync < CWDistToMaster, mcSyncModeNegative, mcSyncModePositive );
Expand Down Expand Up @@ -1814,7 +1814,7 @@ ELSE // let 'er rip
fbGearInPosMoverCA[1].RatioDenumerator := 1;
fbGearInPosMoverCA[1].MasterSyncPosition := internalMasterMover.AxisReference.NcToPlc.ActPos;
fbGearInPosMoverCA[1].SlaveSyncPosition := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - internalGap, GVL.TRACK_LENGTH);
fbGearInPosMoverCA[1].SlaveSyncPosition := MODABS( internalMasterMover.AxisReference.NcToPlc.ActPos - internalGap, internalTrack^.Length);
fbGearInPosMoverCA[1].SyncStrategy := mcSyncStrategyEarly;
fbGearInPosMoverCA[1].SyncMode := SEL( CWDistToSync < CWDistToMaster, mcSyncModeNegative, mcSyncModePositive );
Expand Down
10 changes: 6 additions & 4 deletions Base Project/Main/POUs/XTS/MoverList.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ VAR
cycles : UDINT;
trackLength : LREAL;
END_VAR
]]></Declaration>
<Implementation>
Expand Down Expand Up @@ -258,26 +260,26 @@ WHILE allsorted = FALSE DO
IF SortedBuffer[i] <> 0 AND_THEN SortedBuffer[i]^.TrackInfo.TrackPosition <= Position THEN
directionalDistance_i := Position - SortedBuffer[i]^.TrackInfo.TrackPosition;
ELSIF SortedBuffer[i] <> 0 AND_THEN SortedBuffer[i]^.TrackInfo.TrackPosition > Position THEN
directionalDistance_i := Position + ( GVL.TRACK_LENGTH - SortedBuffer[i]^.TrackInfo.TrackPosition );
directionalDistance_i := Position + ( SortedBuffer[i]^.CurrentTrack^.Length - SortedBuffer[i]^.TrackInfo.TrackPosition );
END_IF;
// Calculate for j
IF SortedBuffer[j] <> 0 AND_THEN SortedBuffer[j]^.TrackInfo.TrackPosition <= Position THEN
directionalDistance_j := Position - SortedBuffer[j]^.TrackInfo.TrackPosition;
ELSIF SortedBuffer[j] <> 0 AND_THEN SortedBuffer[j]^.TrackInfo.TrackPosition > Position THEN
directionalDistance_j := Position + ( GVL.TRACK_LENGTH - SortedBuffer[j]^.TrackInfo.TrackPosition );
directionalDistance_j := Position + ( SortedBuffer[i]^.CurrentTrack^.Length - SortedBuffer[j]^.TrackInfo.TrackPosition );
END_IF
ELSIF Direction = MC_Negative_Direction THEN
// Calculate for i
IF SortedBuffer[i] <> 0 AND_THEN SortedBuffer[i]^.TrackInfo.TrackPosition <= Position THEN
directionalDistance_i := SortedBuffer[i]^.TrackInfo.TrackPosition + ( GVL.TRACK_LENGTH - Position );
directionalDistance_i := SortedBuffer[i]^.TrackInfo.TrackPosition + ( SortedBuffer[i]^.CurrentTrack^.Length - Position );
ELSIF SortedBuffer[i] <> 0 AND_THEN SortedBuffer[i]^.TrackInfo.TrackPosition > Position THEN
directionalDistance_i := SortedBuffer[i]^.TrackInfo.TrackPosition - Position;
END_IF
// Calculate for j
IF SortedBuffer[j] <> 0 AND_THEN SortedBuffer[j]^.TrackInfo.TrackPosition <= Position THEN
directionalDistance_j := SortedBuffer[j]^.TrackInfo.TrackPosition + ( GVL.TRACK_LENGTH - Position );
directionalDistance_j := SortedBuffer[j]^.TrackInfo.TrackPosition + ( SortedBuffer[i]^.CurrentTrack^.Length - Position );
ELSIF SortedBuffer[j] <> 0 AND_THEN SortedBuffer[j]^.TrackInfo.TrackPosition > Position THEN
directionalDistance_j := SortedBuffer[j]^.TrackInfo.TrackPosition - Position;
END_IF
Expand Down
109 changes: 18 additions & 91 deletions Base Project/Main/POUs/XTS/PositionTrigger.TcPOU
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.12">
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4026.8">
<POU Name="PositionTrigger" Id="{e261b23c-fca2-43e5-b385-fb66bc9fcaf5}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK PositionTrigger EXTENDS Objective
Expand All @@ -9,7 +9,7 @@ VAR
internalMoverPassedPosition : BOOL;
internalCurrentMover : POINTER TO Mover;
internalLastMoverPassedPosition : BOOL;
internalTrackId : DINT := 1;
internalTrack : REFERENCE TO TRACK;
moverLastPos : ARRAY[1..GVL.NUM_MOVERS] OF LREAL; // Positions of tracked movers from last cycle
moverInitialized : ARRAY [1..GVL.NUM_MOVERS] OF BOOL; // first scan-like flag to prevent erronious triggers on first scan
Expand Down Expand Up @@ -74,7 +74,7 @@ END_VAR]]></Declaration>
FOR i := 1 TO GVL.NUM_MOVERS DO
IF internalTrackedMovers[i] <> 0 AND_THEN internalTrackedMovers[i]^.IsTrackReady AND internalTrackedMovers[i]^.CurrentTrack <> 0 THEN
moverTrackId := internalTrackedMovers[i]^.CurrentTrack^.Id;
IF (moverTrackId = internalTrackId) THEN
IF (moverTrackId = internalTrack.Id) THEN
// last position is invalid on first scan, set it to the current position to avoid a false trigger on the first scan
IF NOT moverInitialized[i] THEN
Expand All @@ -83,15 +83,15 @@ FOR i := 1 TO GVL.NUM_MOVERS DO
END_IF
// Determine if a position rollover occured in the last cycle
modTrackPosition := MODABS( internalTrackedMovers[i]^.TrackInfo.TrackPosition, GVL.TRACK_LENGTH);
modTrackPosition := MODABS( internalTrackedMovers[i]^.TrackInfo.TrackPosition, internalTrackedMovers[i]^.CurrentTrack^.Length);
positionDifference := moverLastPos[i] - modTrackPosition;
rolloverOccured := ABS( positionDifference ) > ( GVL.TRACK_LENGTH / 2 );
rolloverOccured := ABS( positionDifference ) > ( internalTrackedMovers[i]^.CurrentTrack^.Length / 2 );
// and if so, modify the stored last position values to be nonmodulo to compensate
IF rolloverOccured AND positionDifference > 0 THEN
moverLastPos[i] := moverLastPos[i] - GVL.TRACK_LENGTH;
moverLastPos[i] := moverLastPos[i] - internalTrackedMovers[i]^.CurrentTrack^.Length;
ELSIF rolloverOccured AND positionDifference < 0 THEN
moverLastPos[i] := moverLastPos[i] + GVL.TRACK_LENGTH;
moverLastPos[i] := moverLastPos[i] + internalTrackedMovers[i]^.CurrentTrack^.Length;
END_IF
// Look for movers passing over the threshold this cycle and assign it to the
Expand Down Expand Up @@ -264,24 +264,26 @@ Statistics.ProcessedMoverCount := 0;
internalStatisticsReset := TRUE;]]></ST>
</Implementation>
</Method>
<Method Name="SetTrack" Id="{1692464a-54c2-0d6f-250a-480aa9560f30}" FolderPath="Methods\">
<Declaration><![CDATA[METHOD SetTrack : BOOL
VAR_INPUT
Track : REFERENCE TO TRACK;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[internalTrack REF= Track;]]></ST>
</Implementation>
</Method>
<Property Name="TrackId" Id="{dbfe845b-02ea-002a-11b5-4efaf37a2e66}" FolderPath="Properties\">
<Declaration><![CDATA[PROPERTY TrackId : DINT]]></Declaration>
<Get Name="Get" Id="{36306272-b6fe-0043-1e2d-da060775dff6}">
<Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TrackId := internalTrackId;]]></ST>
<ST><![CDATA[TrackId := internalTrack.Id;]]></ST>
</Implementation>
</Get>
<Set Name="Set" Id="{43412e6e-388b-0c48-14bf-abf9f8d26c08}">
<Declaration><![CDATA[VAR
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[internalTrackId := TrackId;]]></ST>
</Implementation>
</Set>
</Property>
<Property Name="TriggerDirection" Id="{13bb661c-6cea-4df5-a26e-19ba5cdbbe66}" FolderPath="Properties\">
<Declaration><![CDATA[{attribute 'monitoring' := 'call'}
Expand All @@ -301,80 +303,5 @@ END_VAR]]></Declaration>
</Implementation>
</Set>
</Property>
<LineIds Name="PositionTrigger">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.CurrentMover.Get">
<LineId Id="3" Count="9" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.Cyclic">
<LineId Id="86" Count="3" />
<LineId Id="160" Count="0" />
<LineId Id="90" Count="0" />
<LineId Id="197" Count="0" />
<LineId Id="199" Count="3" />
<LineId Id="198" Count="0" />
<LineId Id="92" Count="1" />
<LineId Id="185" Count="0" />
<LineId Id="172" Count="0" />
<LineId Id="170" Count="0" />
<LineId Id="94" Count="5" />
<LineId Id="104" Count="33" />
<LineId Id="139" Count="6" />
<LineId Id="242" Count="5" />
<LineId Id="241" Count="0" />
<LineId Id="146" Count="5" />
<LineId Id="2" Count="0" />
<LineId Id="250" Count="0" />
<LineId Id="249" Count="0" />
<LineId Id="248" Count="0" />
<LineId Id="74" Count="11" />
<LineId Id="203" Count="4" />
<LineId Id="91" Count="0" />
<LineId Id="208" Count="7" />
<LineId Id="100" Count="3" />
<LineId Id="216" Count="4" />
</LineIds>
<LineIds Name="PositionTrigger.MoverPassedPosition.Get">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.MuteCurrent">
<LineId Id="14" Count="6" />
<LineId Id="3" Count="2" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.Position.Get">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.Position.Set">
<LineId Id="6" Count="0" />
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.ResetStatistics">
<LineId Id="6" Count="1" />
<LineId Id="5" Count="0" />
<LineId Id="8" Count="2" />
<LineId Id="12" Count="0" />
<LineId Id="11" Count="0" />
<LineId Id="13" Count="0" />
<LineId Id="15" Count="0" />
<LineId Id="14" Count="0" />
<LineId Id="16" Count="0" />
<LineId Id="21" Count="0" />
<LineId Id="20" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.TrackId.Get">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.TrackId.Set">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.TriggerDirection.Get">
<LineId Id="2" Count="0" />
</LineIds>
<LineIds Name="PositionTrigger.TriggerDirection.Set">
<LineId Id="2" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
Loading

0 comments on commit 3cd8e71

Please sign in to comment.