Occupied blocks based on sensors

Shdwdrgn Dec 19, 2018

  1. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I'm trying to work out how to mark a block as occupied based on simple position detectors such as reed switches and IR LEDs to denote the ends of each block. To begin with, I'm working with a test loop that has some spurs. The numbers mark the position of the sensors.
    [​IMG]

    From here I made up a table that lists the blocks from each sensor's position to the sensors surrounding it. Of course sensor 1 has the most adjacent blocks since it also connects to all the spurs.
    Code:
    1 => 2,6,13,15
    2 => 1,3
    3 => 2,4
    4 => 3,5
    5 => 4,6
    6 => 1,5
    11 => 1,12
    12 => 11
    13 => 1,14
    14 => 13
    15 => 1,16
    16 => 15
    With that information in place I built a quick web page with javascript timers to simulate a running train. The concept is that the sensors may not be consistently tripped while a train passes (for example, an LED shining between the cars as they pass) so each time a sensor is clicked it restarts a 5-second timer. When a train is actively tripping a sensor, the block on either side of it is marked as occupied (red), then after 5 seconds of inactivity those blocks are reduced to a yellow warning, and finally cleared. Here's the demo page: http://sourpuss.net/projects/trains/computer/testtrack/ (no guarantees it will work on different browsers, I only tested it under firefox, and you may see things break while I'm working on the code).

    All right, so some bits stand out at the moment... I mark my red blocks, but I should also mark the next block in either direction as yellow. And if I mark the block the loco is occupying in red, then the loco would see a red signal indicating it needs to stop.

    So I think I have a good start, but I'm still missing some critical information about getting the blocks properly marked. Can anyone offer some advice about how this sort of thing is normally handled? I'm sure most people don't have full computer systems running their occupancy detectors, so there must be a simple method to do this but I'm missing it.
     
  2. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    As a partial answer to myself, I had an idea that seems to be working better. If a train stops between sensors, the block still needs to remain marked as red until I know it is moving again. So I made a small change in that no timers are set when a block is marked red, however if the sensors on either side of this one have been recently triggered then those sensors will have a timer started on them.

    So lets say sensor 4 is triggered. Blocks 3-4 and 4-5 are marked in red showing they may be occupied. Nothing else happens until the train proceeds to trigger sensor 5, then a timer is placed on sensor 4 to drop back to yellow and clear after 5 second intervals. The block 3-4 can drop to yellow, however since sensor 5 is triggered blocks 4-5 and 5-6 are locked red until the train proceeds to sensor 6. Hard to explain, but easy to see on the demo page. This already feels more likely to work with an actual train of any length, and with trains that change directions. The one thing that would cause it to fail is if a train were physically picked up off the track and moved elsewhere, in which case the red blocks would need to be manually cleared.
     

Share This Page