The Software - Missions

A mission is a definition of a task a Train should follow.

Here's an example mission:

  • Go to Top Station
  • When done, Wait 10 seconds, then go to Bottom Station
Pretty simple really.   This mission can then be applied to one or more trains.  When you start a mission this is what happens:
  1. The train starts it's engine and turns on it's lights
  2. It waits a set amount of time for the engine to settle ready to pull away
  3. It plans a route to the destination.
    • It basically looks for the shortest route
    • However if there is an available route that's no more than 100cm longer it will chose that instead.  Available means completely unlocked from end-to-end.
    • Going through a set of points which are not set straight has a "price" of 20cm, making the route appear longer and not be preferred
    • If the destination has multiple platforms it will bias towards a free platform
  4. It plays the pull away sounds (guards whistle, closing doors, etc)
  5. With the planned route in hand, it "looks ahead" to lock track and set points in the correct direction.  Once track is locked, it's coloured the same colour as the train on the map and cannot be used by any other train.
  6. As it looks ahead it gathers all possible speed limits that might apply.  A speed limit could be a limitation on a set of points, or it could be the fact it's run up against a locked piece of track which therefore has a speed limit of zero.
  7. It looks at the speed limits, and the distance they are in front, and works out whether it can stop in time.  It runs an algorithm to work out the "best speed" so that the stopping distance isn't exceeded.
  8. If it realises the stopping distance will be exceeded, for example the train suddenly jumps ahead of where the software expected and it can't stop in time, it applies an emergency stop.
  9. If the train comes to a complete stop, some special stuff happens:
    1. It runs another route calculation to see if there's a better route, or one that's "More Available" than the current one.  If so, it changes routes.
    2. It unlocks everything that's locked up ahead to give other trains a chance to use it.  This solves some head-to-head deadlocks that would otherwise occur.
    3. If it's stopped on a special piece with a waiting list (the entrance blocks into stations) it will apply a special prioritisation logic which will always prioritise arrivals into the station, and after that it's first come-first served rather than random.
  10. This whole process just cycles around infinitely until the train reaches it's destination.

Comments