Basic design
We compose our railway controller from several train controllers, combined with controllers for mutual exclusion.
Mutual Exclusion
Normal segments
For each block we generate one mutex controller, similar to the following pattern.
For each controlled train one state and the corresponding transitions are added.
For a free track the *_perm variable is set to -1 and all tracks, apart from starting positions, are initialised with -1. For the starting positions the *_perm variables are set to the corresponding train number and the *_req variable for the train is set to true.
A train must not enter a segment without holding the lock for the segment. No exceptions from this rule are allowed.
Kicking Horse Pass
To prevent collisions on the track, a special controller manages the right to enter the Kicking Horse Pass.
The controller splits the pass into two parts, left and right, corresponding to the track layout chart. (Simplified track layout)
We allow two trains in one direction