The RR_ExitTimeout procedure is responsible for carrying out the boxes' exit. It is essential to understand that the scheduled time does not represent a guarantee of exit, but rather the earliest physically possible moment at which the box could have left the conveyor if it had not experienced any interruptions.
The philosophy is identical to that used by RR_EntryTimeout: the event does not schedule an action; it schedules the next known reevaluation of a boundary.
Validation and Handover Mechanics:
When the event is triggered, the necessary checks are performed to determine whether the VE should terminate, be rescheduled, or transfer control of the boundary:
-
Regime Validation: The first check is whether the timeout still belongs to the current exit regime. The received value must match RR_ExitRegimeVersion.
- Movement Validation: If the box is stopped (due to a jam), the timeout becomes invalid. It will be scheduled again when the box starts moving.
- Position Validation: The current vector position is calculated. If, due to rounding or speed changes, the box has not yet crossed the boundary (RR_Length), the remaining time is calculated and a residual TIMEOUT is rescheduled.
- Exit Execution: If the box has reached the end, a WAKE is executed to physically remove it from RR_Conveyor, scheduling the exit of the next box if one exists.
Example
PROCEDURE RR_ExitTimeout
assign TOKEN,P$PARAM_A
if ( P$TOKEN != X$RR_ExitRegimeVersion)
terminate_ve
endif
assign ENTITYNUMBER,X$RR_LeavingEntity
;ASSIGN msg,{operation:"write",value:"RR_ExitTimeout : P$ENTITYNUMBER (P$PARAM_B)"}
;EXEC_MEDIA {name:logUI,in:V$msg}
; entity stopped moving, timeout loses validity
if (P$(RR_Moving,P$ENTITYNUMBER) == 0)
;ASSIGN msg,{operation:"write",value:"RR_ExitTimeout Is stopped: P$ENTITYNUMBER"}
;EXEC_MEDIA {name:logUI,in:V$msg}
TERMINATE_VE
endif
; calculate current position
assign advance, P$(RR_Position,P$ENTITYNUMBER) + (AC1$ - P$(RR_Time,P$ENTITYNUMBER)) * X$RR_Speed
; entity fully exited conveyor
IF (ceil(P$advance,X$RR_decimals) >= X$RR_Length)
wake RR_Conveyor,-1,P$ENTITYNUMBER
call setStatusDisplay
ELSE
; entity has not fully exited yet
assign remainingToExit, ceil((X$RR_Length - P$advance) / X$RR_Speed,X$RR_decimals)
savevalue RR_ExitRegimeVersion, X$RR_ExitRegimeVersion + 1
timeout RR_ExitTimeout, P$remainingToExit , X$RR_ExitRegimeVersion, 22222
terminate_ve
ENDIF
; find entity closest to conveyor exit
assign leadingEntity,P$(RR_PackRear,P$ENTITYNUMBER)
savevalue RR_LeavingEntity,P$leadingEntity
savevalue RR_EntityLeader,P$leadingEntity
;ASSIGN msg,{operation:"write",value:"RR_ExitTimeout Exit: P$ENTITYNUMBER next P$leadingEntity"}
;EXEC_MEDIA {name:logUI,in:V$msg}
; no more entities remaining
if (P$leadingEntity == 0)
savevalue RR_EntityLeader,0
savevalue RR_EntityTail,0
savevalue RR_LeavingEntity,0
terminate_ve
endif
assign RR_PackFront,0,P$leadingEntity
assign advance, P$(RR_Position,P$leadingEntity)+(AC1$ - P$(RR_Time,P$leadingEntity)) * X$RR_Speed * P$(RR_Moving,P$leadingEntity)
assign remaining, X$RR_Length - P$advance
assign time, ceil(P$remaining / X$RR_Speed , X$RR_decimals)
savevalue RR_ExitRegimeVersion, X$RR_ExitRegimeVersion + 1
timeout RR_ExitTimeout,P$time,X$RR_ExitRegimeVersion, 11111
TERMINATE_VE
ENDPROCEDURE