Dispatcher - rain9441/factorio-tls GitHub Wiki
https://github.com/rain9441/factorio-tls/blob/master/screenshots/04-dispatcher.png
The second major component of TLS is the Dispatcher. The Unloader is configured to draw resources from the train that is present and tell that train when to leave. The Dispatcher is responsible for enabling and disabling train stops based on the needs of the station. The Unloader already has done the work for determining how many items (including bots in queue, fluids, and so on) are in logistic storage, so that is passed along to the Dispatcher on one of the wires connected to the substations.
Each train stop combines the logistic storage contents of the outpost with a local constant combinator to determine if that station should dispatch the train carrying their respective components. One constant combinator allows you to configure the minimum number of resources that should be at the outpost. If this is not met, then the train stop will be enabled. A second constant combinator allows you to configure the amount of resources to pull from trains should any train arrive in the loading bay. The requested amount is connected back to the Unloader system to determine what to pull from the train.
Note that it is very important that the train stops be positioned in such a way that their single cargo wagon overlap as many stack filter inserters as possible.
When the Dispatcher wants to dispatch a train, it must wait until the loading bay is clear before enabling the train stop. To do this, we've wired a small rail signal to all of the train stop combinators. This allows us to combine the green signal with the desire to enable the train stop. The reason that we do this is because the contents of the logistic system often shuffle rapidly as a train is departing. On top of that, the stack filter inserters that are drawing items from the train may still be holding the items as the train departs. This could lead us to a situation where the train is in the process of unloading 100 laser turrets, but none of them have actually made it to the logistic storage yet. Waiting for the train to clear the loading bay is a good way to give the system a few seconds to settle in before hastily summoning another train. If we allowed the logic to dispatch trains immediately after the current train departs, it would more often than not dispatch the same train that just unloaded because it is missing just a few items that are still in the insterters.
An RS Latch has been applied to hold the enabled state of each train stop. When a train stop dispatches a train, it will enable the train stop and remain enabled until the train arrives. Without an RS latch, it's possible that the train stop could turn on only momentarily while there is a brief shortage of materials (this happens often with repair packs). If the train is already en route to the outpost and the train stop becomes disabled, it could stop in place and no-path, causing blockage in your rail system. The RS latch guarantees that once an outpost's train stop becomes enabled, it will only ever disable itself when the train arrives. In this sense, it is a TE latch (T/train number acts as reset, E/enabled acts as set).
For your convenience, a small light is attached to each train stop to show it's enabled status. An additional light is setup to show when a train is unloading at that station.