Test Track Project


“Train-Brain” software from CTI Electronics controlled the test track. The software was configured on a 2.8GHz Toshiba laptop computer and communicated with the CTI hardware via a USB-to-serial-port adapter.

User Interface

The CTI software allows the user to build virtual control panels that display all of the layout functions including block signals, block occupancy, train direction, operating scenery, control panel buttons, etc. Some elements on the test track panel were static, while others responded to train location and direction, programmed events, mouse activity, etc. The control panel for the test track is shown below.

The following notes apply to the test track's control panel:

  • Turnouts (a.k.a., Track Switches) TSa and TSb are shown in the branch position, which allows the train to switch from one loop of track to the other loop of track. Turnouts TSc and TSd are in the mainline position, which allows the train to remain on the outer or inner loop.

  • Turnouts are controlled in pairs. The color of the TRACK SW buttons (bottom center of panel) will change to match the color of the arrows that indicate turnout direction. The buttons are toggles; each mouse click changing the direction of the appropriate pair of turnouts.

  • Track section 5 (S5) is colored red, which indicates that the section (block) is presently occupied by a train. The engine sprite indicates that the train is westbound; i.e., traveling counterclockwise. If the EAST/WEST button (lower left on the panel) is pressed (mouse click), the button will change to red, indicating that the train is eastbound. At the same time, the engine sprite will automatically change to eastbound; i.e., it will face in the opposite direction. Oh yes, and the train will come to a smooth stop and then reverse direction.

  • The shapes in the center of the layout represent the scenery lights. Squares are buildings, circles are street lights, and triangles are emergency vehicle flashing lights. Dark colors indicate that lights are off, while light colors indicate that the lights are on. The L1, L2, etc., buttons, which are toggles, are also dark or light to indicate whether the lights are illuminated. The FL1 button controls the emergency vehicles' flashing lights.

  • The red MANUAL button indicates that the layout is presently operating in manual mode. In manual mode, the program step number (lower left) will always be “0”. In fixed program mode, the program step number will increment by 1 each time the train passes by the left end of the layout. In random program mode, the program step number will change to a randomly selected number each time the train passes the left end of the layout.

Program Design Objectives

There were basically two objectives for the test track's program design:

  • The first objective was to provide the ability to run the layout either manually or automatically. For the test track that involved implementing a manual mode of operation and 2 program modes (described below).

  • The second objective was to prevent accidental train derailments. In particular, it must not be possible—in ANY mode of operation—to change the position of a turnout while the train is passing over it, and it must not be possible to run the train over a turnout that is thrown the wrong way. It also must not be possible to rear-end train equipment that has accidentally uncoupled from the engine.

Program Overview

The figure below shows the general flow of the test track program.

Operating Modes

As shown in the diagram, the Train-Brain software was configured to allow the layout to be operated in any of the following modes:

  • Manual Mode

    On-screen controls are used to manually operate all of the layout's functions.

  • Fixed Program Mode

    A sequence of “n” predefined program steps is automatically executed as the train travels around the layout. The step number (“n”) is incremented by 1 every time the train reaches the left end of the layout.

    Each step causes some event or combination of events to be executed. The overall sequence of events automatically repeats itself for as long as the program is allowed to run. The number of steps (“n”) and the event or events executed by each step are determined by the programmer.

  • Random Program Mode

    Fixed program mode is basically the same as random program mode, except for the code that drives the counter. In one case it is an incrementer, and in the other case it is a random number generator.

    In random program mode, a random sequence of events is automatically executed as the train travels around the layout. The random events continue for as long as the program is allowed to run.

    The same “n” program steps used for fixed program mode are used for random program mode. Additional program steps can be defined for random program mode if it turns out that certain events should occur more often to make random program mode operations more interesting.

Manual & Program Action Requests

A manual action request occurs when someone clicks on a control panel button while the layout is operating in manual mode. A program action request occurs when the program steps to a new count while the layout is operating in either of the program modes. The software doesn't care where a request comes from; i.e., the same block of code will be executed regardless of of whether the request came from a control panel button or the program counter.

Before a manual or program action request is executed, the status of the layout is determined. Action requests will be executed immediately only if they can be executed without causing operational problems. Otherwise, the action will be delayed.

For example, actions involving scenery lights will always be executed immediately, since turning lights on and off will not cause any operational problems. However, execution of a turnout action request will be delayed if the train is near or on the turnout. Only when the train is on the opposite side of the layout will the turnout be thrown.

Automatic Action Requests

The software automatically executes certain actions, without any manual or program request. Examples include:

  • Turning off the station stop request after the train has stopped at the station.

  • Disconnecting track power and illuminating emergency vehicle flashing lights if there is a track power short circuit (derailment).

  • Managing all control panel messages, color changes, and sprites.

  • Most important, if the train is approaching a turnout that is thrown the wrong way (i.e., the train will derail when it reached the turnout), the software will automatically throw the turnout the right way. This not only avoids an accident, but it also eliminates the need for the programmer or train operator to be concerned about derailments on turnouts that are thrown the wrong way.

  • In the new train table, if 2 noncontiguous blocks are occupied by the same train, the train(s) will be automatically halted. Presumably, this situation can only exist if one or more cars has uncoupled from the engine.

Action Execution

Action Execution is where everything happens in the layout—turnouts are thrown, lights are turned on and off, the station stop is activated, etc. The action execution software doesn't really care where the action request came from. It can be requested by one of the program modes, requested by the train operator using the control panel, or it can be an automatic request based on layout conditions.

Top of Page