There's a lot more work to do, but I've just demonstrated Block-based Automated Train Control using PyTrain. The code uses an IR Sensor Track to read the TMCC ID of the engine/train entering the block, and a couple of MRAPR relay-based block sensors connected to GPIO pins on a Pi to determine when to slow then force-stop the engine. When the block receives the "all clear" signal from the block ahead of it, it restores the engine's speed in the stopped block to what it was originally when it was told to slow down.
This approach has a couple of limitations:
- only works with Lionel engines that have IR sensors
- requires a sensor track in the block to read the engine/train TMCC ID (needed to send speed and stop commands)
- requires the block to have some "sub blocks" to signal when the train should begin slowing and another to signal when the train has to dead stop. You wouldn't absolutely need the "slow down" sub block, but it will look nicer than just bring an engine at highball speed to a dead stop.
- requires Raspberry Pi(s) and the PyTrain software
- blocks must be defined in software as well as hardware (isolated rails, etc)
Still, the approach took minimal code (about 2 hours) and leveraged PyTrain and the gpiozero library capabilities, which made it very easy to fire Legacy commands in response to the engine passing into the various sub-block.
The gpiozero Python library really made the work easy. I modeled the sub-blocks as gpiozero buttons. The library lets you bind callback that automatically are called/fired when you enter the block (think press the button) or leave the block (think release the button). You can also easily check if a button is pressed or not (think occupied or not occupied). With these core capabilities, it was easy to trigger a "slow down" command when the train entered the "slow-down" sub-block, as well as a "stop immediate" when it hit the stop threshold. Similarly, when the train ahead left the block (button-released), that block could send a signal to the block with the stopped train to tell it to resume speed.
Although this code is checked into the main PyTrain repository, it isn't quite ready for prime time yet. One of the biggest things I have to think thru is how to make this all work when you have track blocks connected to different Raspberry Pis. One of my goals for developing control panels was to minimize the wire runs between the layout and the Pi. Perhaps I can relax this for automated train control, but I'm not ready to do that yet
-- Dave