Controller - Scheduler 

Page / - last modified by aas2 on 2025/01/30 12:17 

Scheduler 
last modified by aas2
on 2025/01/30 12:17

Table of Contents
Relevant Scheduler Outputs

The Scheduler is used to route between segments with contact. Each train is scheduled individually without looking at the other trains. Other trains may only influence the schedule through the inputs route and train_on_track. Following inputs are used to achieve this:
initial_position	Send to controller as input, only used in first tick and never after. Determines the starting position of a train and has to be a segment.	
final_station	Send to controller as input. This may be influenced by the deadlock avoidance if necessary (forces a destination on blocking trains that do not have a destination).	
current_position	Send by hardware abstraction to determine the current segment.	
reached	Send by hardware abstraction to signal, that the segment specified by 
next_segment
 was reached.	
route	May be 0 or 1. From every station it is possible to take two different routes to a different station. If 
route
 is 0 the normal "shortest" (the path that passes less stations) is used. 1 is used to signal that an alternative route should be used. It is set by the deadlock prevention	
train_on_track	Send by hardware abstraction to check if some tracks are blocked. Only relevant for driving to an alternative platform if current platform is in use.	
lock_XX	Set by deadlock prevention to lock specific segment transition in KH and to KIO	

Relevant Scheduler Outputs
Describes the outputs that are relevant for other parts of the controller. This is a deeper explanation of why a train drives in a specific way.
(pre_)next_segment	Used by hardware abstraction to determine what tracks need to be to reserved and what tracks need to be powered. Its is also used by deadlock prevention to set 
route
 or set 
final_station	
moving	Boolean that signals whether a train intends to move. May be true for trains that are not moving physically if they are blocked in any way (either by hardware abstraction or one of 
lock_XX
).	

The Scheduler uses the following internal variables to determine the location and state of each train.
station (output)	The 
final_station
 the train is currently heading to. Only updated if the train reached a station. A train may not change station while not being in at least a substation of its route.	
taken_route	The 
route
 the train is currently using. Only updated if the train reached a station. A train may not change station while not being in a station.	
still_moving	Boolean used to signal that regardless whether next_segment == NO_DESTINATION, a train still has a destination he is heading to.	
not_in_station	Only set in first tick, if 
initial_position
 is no platform. Used to handle the special cases that can happen. Only used untill a station is reached.	
only_passing_by	Signals that a train does not want to enter a specific platform in a station. Mostly used if a train has to pass a station to reach his final station.	
station_position (output)	The last station a train has visited. Is set to a possible previous station if 
initial_position
 is no platform.	
substation (output)	Indicates next platform/ station a train should head to. If 
substation
 is not equal to station the station is used instead of a specific platform.	

The station_position, station and taken_route (and not_in_station until first station is reached) to determine the next substation. The variables current_position and substation (and lock_XX, only_passing_by) are used  to determine the next_segment.