RR_StopTimeout: Jam and Accumulation Management

Updated: 2026-05-29

The RR_StopTimeout procedure manages the stopping of entities when they encounter a constraint on the conveyor (the "plug"). By default, the stop limit (RR_StopLimit) is outside the conveyor (-RR_Length), but when a jam occurs, the system initiates a chain of events.

The philosophy is identical to that used by RR_EntryTimeout and RR_ExitTimeout: the event does not schedule a stop; it schedules the next known reevaluation of the accumulation boundary.

Propagation Mechanics (Backpressure)

After verifying that the regime is correct, the orchestrator operates under two scenarios, depending on the situation of the only box that can reach the boundary at that moment (the leader or the one immediately behind the last stopped box):

Scenario A: Immediate Collision If the box is currently crossing the stop limit (its body intersects the plug coordinate):

  1. Kinematic Freeze: The box stops (moving: 0), and its exact position and time at that instant are recorded (AC1$).

  2. Boundary Mutability: The RR_StopLimit is automatically updated to the physical tail of the box that has just collided.

  3. Instant Propagation: RR_StopTimeout is called again at time 0 to check whether the next box is already touching the one that has just stopped.

Scenario B: Future Collision If the box is not touching the current boundary, the time at which it would reach it is calculated so that the timeout can be rescheduled.

Domino Effect: This algorithm allows accumulation to occur naturally. The boxes keep moving until they "fill" the empty space, optimizing conveyor occupancy without unnecessary iterations.

Example

PROCEDURE RR_StopTimeout

    ; stop system disabled
    if (X$RR_StopLimit == X$RR_Length * -1)
        terminate_ve
    endif

    ; PARAM_A = requested stop limit
    ;savevalue RR_StopLimit,P$PARAM_A

    if ( P$TOKEN != X$RR_SotpRegimeVersion)
        terminate_ve
    endif   
    ;-------------------------------------------------
    ; 
    ; Find entity currently invading stop limit
    ; else 
    ; when invading
    ; 
    ;-------------------------------------------------

    assign entityNumber,0

    if (X$RR_LastStopedEntity == 0)
        assign entityNumber,X$RR_EntityLeader
    else
        assign entityNumber,P$(RR_PackRear,X$RR_LastStopedEntity)
    endif

    if (P$entityNumber==0)
        terminate_ve
    endif



    assign currentHalf, P$(RR_Length,P$entityNumber) * 0.5
    assign currentPosition, P$(RR_Position,P$entityNumber) +  (AC1$ - P$(RR_Time,P$entityNumber)) * X$RR_Speed

    assign currentFront, P$currentPosition + P$currentHalf
    assign currentTail,  P$currentPosition - P$currentHalf

    ; entity intersects stop limit
    if ( P$currentFront >= (X$RR_Length - X$RR_StopLimit) && P$currentTail <= (X$RR_Length - X$RR_StopLimit) && P$(RR_Moving,P$entityNumber) == 1)

        ;ASSIGN msg,{operation:"write",value:"RR_StopTimeout Stop in P$entityNumber"}
        ;EXEC_MEDIA {name:logUI,in:V$msg}

        ; freeze entity state
        assign RR_Position, P$currentPosition, P$entityNumber
        assign RR_Time,  AC1$, P$entityNumber
        assign RR_Moving,  0,  P$entityNumber
        savevalue RR_LastStopedEntity, P$entityNumber
        ; propagate stop limit backward

        savevalue RR_StopLimit,(X$RR_Length - P$currentTail)
        savevalue RR_StopRegimeVersion, X$RR_StopRegimeVersion + 1
        timeout RR_StopTimeout,  0, X$RR_StopRegimeVersion
        call setStatusDisplay
        terminate_ve

    else


        assign target,(X$RR_Length - X$RR_StopLimit)
        assign remaining, P$target - P$currentFront
        assign requiredTime, P$remaining / X$RR_Speed

        ;ASSIGN msg,{operation:"write",value:"RR_StopTimeout future stop de P$entityNumber en P$requiredTime"}
        ;EXEC_MEDIA {name:logUI,in:V$msg}


        savevalue RR_StopRegimeVersion, X$RR_StopRegimeVersion + 1
        timeout RR_StopTimeout, ceil(P$requiredTime,X$RR_decimals), X$RR_StopRegimeVersion
    endif


    TERMINATE_VE

ENDPROCEDURE