The DataBeaver's Domain

Model railway - Software

Designing and operating a large model railway setup would be near impossible without some sort of help to see how the track geometry fits together and where each turnout is. There are different tools available for these tasks, including track stencils, miniature mock-up track pieces, switching panels and software products, both commercial and free. However, I had my own plans.

Being a programmer of the do-it-yourself variety, the natural choice was to write my own software suite. I had this crazy distant goal of being able to play an adaptation of Railroad Tycoon on my model railway. In fact, that's still a vision I hope to achieve one day.

At the core of my software suite is a set of libraries implementing a virtual layout and trains, 3D view of them and remote control over TCP/IP. There are two main programs: planning ("designer") and operation ("engineer"). In addition there are smaller utilities, including a program for generating shopping lists based on a layout file and current inventory, and some remote control clients.

The designer allows planning a layout with an unlimited supply of tracks. Various tools like cloning entire sections of tracks and snapping them into free endpoints speed up building complex layouts. A background object can be specified to aid in staying within the limits of available table space. Turnout and sensor IDs of tracks can be indicated for operating the layout. Routes can be defined for automatic operation.

[Image] [Image]

The engineer is used to run trains on a layout made with the designer. There are three main modes of operation. Trains can be run freely, taking whatever path turnouts are set to. A route (as specified in the designer) can be selected for the train to follow; if the train is not on the route it will find its way to it. And finally, there's a simple scripting language for fully automatic operation, including timed station stops and reversal at terminus stations. Any of these may be selected on a per-train basis. In all cases, traffic control makes sure that trains won't collide. Priorities can also be specified, and a higher priority train may take blocks a lower-priority one had reserved.

A 3D reproduction of the layout takes up the majority of the screen. Turnouts can be clicked to change their setting. Trains are also displayed and move at correct speeds.

On the left is a stack of panels for controlling the trains. A slider is provided for speed (in km/h) and toggles for reverse and additional decoder functions. Cars can be added to the train, and there's even a window for viewing the scene from the locomotive. Since the panels take up quite a bit of space, they can be collapsed so that only the speed and reverse controls are visible.

[Image]

The underlying library features a driver interface for supporting different command stations. At the moment the only supported device is the Intellibox. Märklin Central Station support is coming soon. A dummy driver also exists to facilitate simulation without a real layout.

Collectively this set of software is called R²C², for RailRoad Computer Control. When referring to just the libraries, it can also mean RailRoad Control Core.

Traffic control

The traffic control system follows that of real railways and uses absolute block signaling. The layout is automatically split into blocks based on sensor tracks. Turnouts can't have sensors, so the system has to deal with sensorless runs of track as well.

When a train is active, it tries to reserve blocks in front of it up to three sensor blocks. A minimum reservation distance is also observed in order to keep moving at the set speed. A simple AI monitors the amount of reserved track and adjusts speed accordingly; the train must always be able to stop within the reserved length of track. If the reserved blocks are running out, speed is first decreased and finally the train is stopped to wait for more blocks to become available. The reservation procedure is invoked again every time the train triggers a sensor and on some other occasions.

With sensorless blocks, the system has to rely to estimates. As soon as a train enters a sensor block, all reserved sensorless blocks ahead of it are also marked as current. Behind the train, sensorless blocks are freed when the last car has advanced a sufficient distance into the next block.

If a sensor is triggered in an unexpected way or if a train does not trigger a sensor it's supposed to, the system will immediately halt all trains as a safety measure.

Train speed and position

In addition to traffic control, sensors are also used for determining the actual speed of the trains. When a train triggers a sensor, the time is noted, and when it triggers the next sensor, its speed is calculated. The results for each speed step are stored separately, and each is accompanied by a weight value for refining the speed as new data is gathered. If the train's speed setting changes in between the sensors, the measurement is suppressed, as the result would be representative of neither the old nor the new speed.

When a new train is introduced, the system won't have any speed data for it. Since the control interface is based on real speeds, it will refuse to run the train at a speed step too far above the highest known one. Running the train around a loop a few times at the desired top speed is enough for the system to learn the necessary speed steps for correct operation.

The knowledge of actual speeds corresponding to speed steps can be used for accurate positioning of the virtual trains. When the train triggers a sensor, it is immediately moved to that position. Between sensors, it is advanced based on the gathered speed data.

3D models

All the 3D models of locomotives and cars are made by me, using both the scale models and photographs of their real counterparts as reference. There are two generations of models, the older ones having around 300-1500 faces and a single color per model, while the newer ones have 5000-10000 faces and proper materials. I plan to eventually redo all old models with the new level of detail.

[Image] [Image]

Source code

All of the software is open source under the GNU Public License. SVN access is available at http://svn.tdb.fi/r2c2. There are no official releases at the moment, nor are any planned.