Train Detection in 0.14: First, some science
Posted: Mon Sep 19, 2016 8:03 pm
Although in 0.13 we can now wire train signals to the circuit network, vanilla factorio has not (yet?) provided a documented means by which we can detect via circuit conditions whether or not a train parked at a given train station just "happened" to be there or is making a scheduled delivery. We can detect a train has turned a signal red, but the fact that it turned red could just mean a train was zipping by or was manually parked there or waiting for a train in front of it to get out of the way. This makes it quite difficult to orchestrate a plurality of nonstandard things we might want to automate at train stops
However, after playing with signals in various positions I noticed a few anomalies which I thought might be exploitable for distinguishing between a train that happens to be in front of a station "incidentally" and a train that is there as part of a scheduled delivery.
I set up a test rig to look into it these more rigorously; this post will document my findings.
First, I made a nice, slow 1-14-1 train that slowly ambles between four stations like so:
I then laid down some signals like so:
I have provisioned each of the stations with three signals: two as close as I could place them just before the station, and one as close as I could place it just after the station. Finally, I made a big oscilloscope to allow myself to visualize the pattern of data coming from the signals with tick-level granularity (this was inspired by Madzuri's recent twitch stream). Here's what the whole thing looks like:
Here is the scope showing the train approaching and docking at Demonstration Station:
First, it is notable that the frontmost signal always stays green (this also makes perfect sense and could be achieved by manual control of the train). But I'm not sure this is the best thing to rely on to detect a scheduled train stop, because, if another train were leaving the station right in front of us, it could still cause that signal to be red.
Second, it is quite striking that just as the scheduled train docks at its scheduled stop, the middle signal transitions immediately from yellow to green. I think I have struck paydirt here. It may be possible to make this happen without a scheduled train-stop, but it would appear to be a pretty unlikely occurrence. Perhaps you'd need blow the train up, take a sudden manual turn, change the schedule, or remove a piece of track -- I have not tried super-carefully to rule out the possibility of false positives. By contrast, when the train blows past skippy, the middle signal behaves just like the other two, going from green to yellow to red.
Third, when the train leaves, the middle signal turns yellow for one tick, and then red. I've tested with a 2-0-2 train and the exact same thing happens.
So there you have it. In my next post, I'll show how these findings can be translated into a fairly straightforward combinator contraption which exploits these quirks to quite reliably detect whether or not a train is making a scheduled stop at a vanilla train station.
However, after playing with signals in various positions I noticed a few anomalies which I thought might be exploitable for distinguishing between a train that happens to be in front of a station "incidentally" and a train that is there as part of a scheduled delivery.
I set up a test rig to look into it these more rigorously; this post will document my findings.
First, I made a nice, slow 1-14-1 train that slowly ambles between four stations like so:
Station Map
The train's route instructions are:
- go to the East Wye terminus and wait zero seconds
- proceed to Demonstration Station and wait for five seconds
- go to West Wye, wait zero seconds
I then laid down some signals like so:
Test Signal Layout
Demonstration Station, to be clear, is the one on top; Skippy is the one on the bottom.I have provisioned each of the stations with three signals: two as close as I could place them just before the station, and one as close as I could place it just after the station. Finally, I made a big oscilloscope to allow myself to visualize the pattern of data coming from the signals with tick-level granularity (this was inspired by Madzuri's recent twitch stream). Here's what the whole thing looks like:
Image of complete test rig
And here's a blueprint (nb: I am using test-mode mod but I have endeavoured to leave any non-vanilla items out of the blueprint):Blueprint String of Test Rig
So without further ado, here are the results. I'll start with the visualizations and save any tldr prose for after the pretty pictures. Note that these are pretty damn huge animated gifs and may take a while to load in your browser. Also the forum may squish them if it thinks your screen is too small, so if you right click them in your browser and say "open image in a new tab" or something like that, you may or may not get a better light show.Here is the scope showing the train approaching and docking at Demonstration Station:
Station Approach Visualization
Here is the train just barely leaving the same:Station Depart Visualization
Finally, here is the train "blowing" (as you'll see, not the right word -- "creeping" more like) past Skippy on the way back:Station Passby Visualization
What have we learned? Well, nothing super definitive, but in all my experiments, there were some identifiable patterns that occurred when a train docks at a scheduled stop which were not evident in other circumstances.First, it is notable that the frontmost signal always stays green (this also makes perfect sense and could be achieved by manual control of the train). But I'm not sure this is the best thing to rely on to detect a scheduled train stop, because, if another train were leaving the station right in front of us, it could still cause that signal to be red.
Second, it is quite striking that just as the scheduled train docks at its scheduled stop, the middle signal transitions immediately from yellow to green. I think I have struck paydirt here. It may be possible to make this happen without a scheduled train-stop, but it would appear to be a pretty unlikely occurrence. Perhaps you'd need blow the train up, take a sudden manual turn, change the schedule, or remove a piece of track -- I have not tried super-carefully to rule out the possibility of false positives. By contrast, when the train blows past skippy, the middle signal behaves just like the other two, going from green to yellow to red.
Third, when the train leaves, the middle signal turns yellow for one tick, and then red. I've tested with a 2-0-2 train and the exact same thing happens.
So there you have it. In my next post, I'll show how these findings can be translated into a fairly straightforward combinator contraption which exploits these quirks to quite reliably detect whether or not a train is making a scheduled stop at a vanilla train station.