-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarSync.st
339 lines (284 loc) · 15.4 KB
/
StarSync.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
FUNCTION_BLOCK slStarSync
//Check for an error on a pocket
Internal.PocketSyncError := 0;
Internal.PocketSyncErrorID := ERR_OK;
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
Internal.PocketSync[Internal.i].StarwheelPosition := StarwheelPosition;
Internal.PocketSync[Internal.i].StarwheelVelocity := StarwheelVelocity;
IF Internal.PocketSync[Internal.i].Error THEN
Internal.PocketSyncError := 1;
Internal.PocketSyncErrorID := Internal.PocketSync[Internal.i].ErrorID;
EXIT;
END_IF
END_FOR
IF Enable AND Busy THEN
// Continuously watch for calculated Track Sync Positions to overtake the Sync Threshold, and update the NextSyncTarget selector
// Also monitor for completion
FOR Internal.i := 0 TO Internal.MaxTargetIndex DO
IF Internal.PocketSync[Internal.i].TargetPosition >= Parameters.ProcessPointStartPosition + Parameters.StartOffset AND
Internal.LastTargetPosition[Internal.i] < Parameters.ProcessPointStartPosition + Parameters.StartOffset AND
Internal.PocketSync[Internal.i].TargetPosition < Parameters.SyncPar.StarCalcTarget.SectorTangentPos AND
Internal.PocketSync[Internal.i].Active AND
NOT Internal.PocketSync[Internal.i].Sync THEN
Internal.PocketDisabled := 0;
IF DisablePockets AND (Parameters.Skip.NumDisabled > 0) THEN
FOR Internal.n := 0 TO MIN(Parameters.Skip.NumDisabled - 1, slMAX_DISABLE_POCKET_IDX) DO
IF Parameters.Skip.DisabledIdx[Internal.n] = (Internal.i MOD (Parameters.SyncPar.StarCalcTarget.StarwheelPocketCount + 1)) THEN
Internal.PocketDisabled := 1;
EXIT;
END_IF
END_FOR
END_IF
IF NOT Internal.PocketDisabled THEN
Internal.NextSyncTarget := Internal.i;
Internal.NewOvertakeDetected := TRUE;
END_IF
END_IF
IF Internal.PocketSync[Internal.i].Done THEN
Internal.PocketSync[Internal.i].Sync := 0;
END_IF
END_FOR
ELSE
Internal.NextSyncTarget := 0;
Internal.NewOvertakeDetected := FALSE;
END_IF
CASE Internal.State OF
slSTAR_STATE_IDLE:
IF Enable THEN
Busy := 1;
Handle := ADR(Internal);
Internal.TypeID := slSTAR_INTERNAL_TYPE_ID;
// Calculate how many periods of starwheel rotation we should calculate track positions for,
// in order to cover the area from SyncPP TO ReleasePP
Internal.PeriodCount := 0;
FOR Internal.i := 0 TO slMAX_PERIOD_IDX DO
IF Internal.i * brmTWOPI * Parameters.SyncPar.StarCalcTarget.StarwheelRadius > (Parameters.SyncPar.StarCalcTarget.SectorTangentPos - Parameters.StartOffset) THEN
Internal.PeriodCount := UINT_TO_USINT(Internal.i + 1);
EXIT;
END_IF
END_FOR
Internal.MaxTargetIndex := Parameters.SyncPar.StarCalcTarget.StarwheelPocketCount * Internal.PeriodCount - 1;
IF Internal.MaxTargetIndex > slMAX_TARGET_IDX THEN
Error := 1;
ErrorID := slERR_MAX_TARGET_IDX;
Internal.State := slSTAR_STATE_RESET_FB;
ELSE
Internal.TrgPointEnable.ProcessPoint := ADR(ProcessPointStart);
Internal.TrgPointGetInfo.ProcessPoint := ADR(ProcessPointStart);
Internal.BarrierCommand.ProcessPoint := ADR(ProcessPointStart);
Internal.BarrierCommand.AdvancedParameters.TicketCount := 0;
Internal.BarrierCommand.Command := mcACPTRAK_BARRIER_CLOSE;
Internal.BarrierCommand.Execute := 1;
Internal.BarrierReadInfo.ProcessPoint := ADR(ProcessPointStart);
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
Internal.PocketSync[Internal.i].TargetIndex := UINT_TO_USINT(Internal.i);
Internal.PocketSync[Internal.i].PeriodCount := Internal.PeriodCount;
Internal.PocketSync[Internal.i].Parameters := ADR(Parameters.SyncPar);
Internal.PocketSync[Internal.i].Enable := (Internal.i <= Internal.MaxTargetIndex);
END_FOR
Internal.State := slSTAR_STATE_CLOSE_BARRIER;
END_IF
END_IF
slSTAR_STATE_CLOSE_BARRIER:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierCommand.Error THEN
Error := 1;
ErrorID := Internal.BarrierCommand.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierCommand.Done THEN
Internal.BarrierCommand.Execute := 0;
Internal.State := slSTAR_STATE_RECOVER;
END_IF
slSTAR_STATE_RECOVER:
Internal.RecoveryPar.ProcessPointStartPosition := Parameters.ProcessPointStartPosition;
Internal.RecoveryPar.StartOffset := Parameters.StartOffset;
Internal.RecoveryPar.ResizeStart := Parameters.SyncPar.ResizeStart;
Internal.RecoveryPar.ResizeEnd := Parameters.SyncPar.ResizeEnd;
Internal.RecoveryPar.Release.Position := Parameters.SyncPar.Release.Position;
Internal.RecoveryPar.Release.DestinationSector := Parameters.Recovery.Release.DestinationSector;
Internal.RecoveryPar.Release.Velocity := Parameters.Recovery.Release.Velocity;
Internal.RecoveryPar.Release.Acceleration := Parameters.Recovery.Release.Acceleration;
Internal.RecoveryPar.Release.Deceleration := Parameters.Recovery.Release.Deceleration;
Internal.RecoveryPar.UserData := Parameters.Recovery.UserData;
Internal.RecoveryPar.PocketErrorTolerance := Parameters.Recovery.PocketErrorTolerance;
Internal.RecoveryPar.Backup.ProcessPointStart := ProcessPointStart;
Internal.RecoveryPar.Backup.BackupTolerance := Parameters.Recovery.BackupTolerance;
Internal.RecoveryPar.Backup.MoveToBarVelocity := Parameters.Recovery.MoveToBarVelocity;
Internal.RecoveryPar.Backup.MoveToBarAcceleration := Parameters.Recovery.MoveToBarAcceleration;
Internal.RecoveryPar.Backup.MoveToBarDeceleration := Parameters.Recovery.MoveToBarDeceleration;
Internal.Recovery.Parameters := ADR(Internal.RecoveryPar);
Internal.Recovery.Sector := ADR(Sector);
Internal.Recovery.Handle := Handle;
Internal.Recovery.Assembly := ADR(Assembly);
Internal.Recovery.Enable := 1;
IF Internal.Recovery.ReadyForStart THEN
ReadyForStart := 1;
END_IF;
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.Recovery.Error THEN
Error := 1;
ErrorID := Internal.Recovery.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.Recovery.Done THEN
ReadyForStart := 1;
Internal.Recovery.Enable := 0;
Internal.TrgPointEnable.Enable := 1;
Active := 1;
Internal.State := slSTAR_STATE_WAIT_TARGET;
END_IF
slSTAR_STATE_WAIT_TARGET:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.TrgPointEnable.Error THEN
Error := 1;
ErrorID := Internal.TrgPointEnable.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.PocketSyncError THEN
Error := 1;
ErrorID := Internal.PocketSyncErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
//Check for new pocket
ELSIF Internal.NewOvertakeDetected THEN
IF SkipPockets THEN
IF Internal.SkipCount < Parameters.Skip.NumSkips THEN
Internal.NewOvertakeDetected := 0;
Internal.SkipCount := Internal.SkipCount + 1;
ELSE
Internal.BarrierReadInfo.Enable := 1;
Internal.State := slSTAR_STATE_TICKET_COUNT;
Internal.SkipCount := 0;
END_IF
ELSE
Internal.BarrierReadInfo.Enable := 1;
Internal.State := slSTAR_STATE_TICKET_COUNT;
END_IF
END_IF
slSTAR_STATE_TICKET_COUNT:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierReadInfo.Error THEN
Error := 1;
ErrorID := Internal.BarrierReadInfo.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierReadInfo.Valid THEN
Internal.BarrierReadInfo.Enable := 0;
IF Internal.BarrierReadInfo.BarrierInfo.RemainingTickets = 0 THEN
Internal.BarrierCommand.AdvancedParameters.TicketCount := 1;
Internal.BarrierCommand.Command := mcACPTRAK_BARRIER_ADD_TICKETS;
Internal.BarrierCommand.Execute := 1;
Internal.State := slSTAR_STATE_ADD_TICKET;
ELSE
Internal.State := slSTAR_STATE_WAIT_SHUTTLE;
END_IF
END_IF
slSTAR_STATE_ADD_TICKET:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierCommand.Error THEN
Error := 1;
ErrorID := Internal.BarrierCommand.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.BarrierCommand.Done THEN
Internal.BarrierCommand.Execute := 0;
Internal.State := slSTAR_STATE_WAIT_SHUTTLE;
END_IF
slSTAR_STATE_WAIT_SHUTTLE:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.TrgPointEnable.Error THEN
Error := 1;
ErrorID := Internal.TrgPointEnable.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.TrgPointEnable.Valid AND Internal.TrgPointEnable.EventCount > 0 THEN
Internal.TrgPointGetInfo.Execute := 1;
Internal.State := slSTAR_STATE_EVENT_INFO;
END_IF
slSTAR_STATE_EVENT_INFO:
IF NOT Enable THEN
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.TrgPointGetInfo.Error THEN
Error := 1;
ErrorID := Internal.TrgPointGetInfo.ErrorID;
Internal.State := slSTAR_STATE_RESET_FB;
ELSIF Internal.TrgPointGetInfo.Done THEN
Internal.TrgPointGetInfo.Execute := 0;
IF Internal.TrgPointGetInfo.TrgPointInfo.Event = mcACPTRAK_TP_PASSED_POSITIVE THEN
Internal.PocketSync[Internal.NextSyncTarget].Axis := Internal.TrgPointGetInfo.TrgPointInfo.Axis;
Internal.PocketSync[Internal.NextSyncTarget].Sync := 1;
END_IF
Internal.NewOvertakeDetected := 0;
Internal.State := slSTAR_STATE_WAIT_TARGET;
END_IF
slSTAR_STATE_RESET_FB:
Active := 0;
ReadyForStart := 0;
Internal.NextSyncTarget := 0;
Internal.NewOvertakeDetected := 0;
Internal.TrgPointEnable.Enable := 0;
Internal.TrgPointGetInfo.Execute := 0;
Internal.BarrierCommand.Execute := 0;
Internal.BarrierReadInfo.Enable := 0;
Internal.Recovery.Enable := 0;
Internal.ErrorID := ErrorID;
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
Internal.PocketSync[Internal.i].Sync := 0;
Internal.PocketSync[Internal.i].Enable := 0;
END_FOR
IF Error THEN
Internal.State := slSTAR_STATE_ERROR;
ELSE
//We only get here if the enable has been dropped
Internal.State := slSTAR_STATE_OPEN_BARRIER;
END_IF
slSTAR_STATE_OPEN_BARRIER:
//We should only open the barrier if the enable has been dropped
Internal.BarrierCommand.Command := mcACPTRAK_BARRIER_OPEN;
Internal.BarrierCommand.Execute := 1;
IF Internal.BarrierCommand.Error THEN
Internal.BarrierCommand.Execute := 0;
Error := 1;
ErrorID := Internal.BarrierCommand.ErrorID;
Internal.State := slSTAR_STATE_WAIT_NOT_BUSY;
ELSIF Internal.BarrierCommand.Done THEN
Internal.BarrierCommand.Execute := 0;
Internal.State := slSTAR_STATE_WAIT_NOT_BUSY;
END_IF
slSTAR_STATE_WAIT_NOT_BUSY:
Internal.PocketSyncBusy := 0;
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
IF Internal.PocketSync[Internal.i].Busy THEN
Internal.PocketSyncBusy := 1;
END_IF
END_FOR
IF NOT (Internal.PocketSyncBusy OR Internal.TrgPointEnable.Busy OR Internal.TrgPointGetInfo.Busy OR
Internal.BarrierCommand.Busy OR Internal.BarrierReadInfo.Busy OR Internal.Recovery.Busy) THEN
Error := 0;
ErrorID := ERR_OK;
Busy := 0;
Internal.State := slSTAR_STATE_IDLE;
END_IF
slSTAR_STATE_ERROR:
IF NOT Enable THEN
Error := 0;
ErrorID := ERR_OK;
Internal.State := slSTAR_STATE_OPEN_BARRIER;
END_IF
END_CASE
Internal.TrgPointEnable();
Internal.TrgPointGetInfo();
Internal.BarrierCommand();
Internal.BarrierReadInfo();
Internal.Recovery();
FOR Internal.i := 0 TO slMAX_TARGET_IDX DO
Internal.LastTargetPosition[Internal.i] := Internal.PocketSync[Internal.i].TargetPosition;
Internal.PocketSync[Internal.i]();
//Initialize the last target position so that the system
//does not think that targets have just passed the sync point
IF Internal.PocketSync[Internal.i].Active AND NOT Internal.LastPocketActiveState[Internal.i] THEN
Internal.LastTargetPosition[Internal.i] := Internal.PocketSync[Internal.i].TargetPosition;
END_IF
Internal.LastPocketActiveState[Internal.i] := Internal.PocketSync[Internal.i].Active;
END_FOR
END_FUNCTION_BLOCK