Monday, September 01, 2014

Automated Layout Control


Way back when I even wanted to automate my fathers layout...

6 years ago I wrote a post about digital breaking sections and how to improve dumb decoder behavior with computer control. 5 years ago, after starting to actually build the Welztalbahn (it had no name at the time), I tried out srcpd and spdrs60 and found quite a few bugs without even trying that hard.

Over the last couple years I build computer control of the Welztalbahn on top of JMRI, mostly using Logix. Last year this effort reached new heights when I had computer control of sensors, signals and turnouts on the whole layout, including automatic reset of signals to Red when a train passes by.

Tonight, I took the next step and wrote a little script to automate control of a train so that it obeys the actual signals in Talheim and Emsingen, as well as the JMRI internal signals that control hidden staging. This is written in Jython and uses JMRIs Automaton code. This is pretty simple code for now, but it was a lot of fun to have two trains chasing each other on a loop route, driven by the computer, stop at signals controlled by the custom built hard panels, just the way I imagined 6 years ago.

Things left to do before this is really useful:
  • Add failure detection. The script monitors sensors and waits for the train to trigger the sensor in the next block. If the train gets stuck on dirty track, derails, or happens to take the wrong leg of a turnout, the script doesn't care. I need to fix the code, so that the current blocks of the train route are monitored and when the train "disappears" stop everything.
  • Add more exact stopping. This requires measuring out stopping distances as well as calibrate locomotives. I don't think this needs to be super exact. Just good enough for a train to pull up to the signal.
  • Add a simple dispatcher module. For now a human needs to set signals to Green so that trains can proceed. The next step is for another thread to figure out if the next section is free, assign it to a train and set the signals accordingly, so that the locomotive threads can control their trains.
  • Integrate with my hard panels. A human operator switching cars in Emsingen or Talheim needs the ability to prevent the dispatcher module from assigning tracks inside the station. I already have a switching mode in each station that's used to line turnouts without affecting signals, so I'll likely use that.
  • Add ability for different routes. The layout easily supports 3 trains chasing each other on a loop, and that tends to keep casual visitors entertained. However, when operating by myself I want trains to use different routes on occasion to make it a bit more interesting.
  • And finally, add some UI on my main computer panel, so I can tell what's going on without having to look at a scrolling log file.
Nevertheless, this is really exciting and it got way too late today.

No comments: