JMRI® is...
Tools
JMRI tools for working with your layout:
Layout Automation
Use JMRI to automate parts of your layout and operations:
Supported Hardware
JMRI supports a wide range of DCC systems, command stations and protocols.
Applications
By the community of JMRI.org:

JMRI Help:

Contents Index
Glossary FAQ

Donate to JMRI.org

JMRI: Simulated Trains

Simulated trains are virtual trains that run on your layout's track as JMRI knows it, with no layout connected. They move when JMRI sends them speed commands, as real trains would, and set occupancy sensors as they pass, so Dispatcher, Warrants, Logix, LogixNG, scripts and panels see them as they would see real trains. The simulator also keeps the truth of where each train really is, which can be compared with what JMRI concluded.

Only in a simulated profile

A train can only be placed in a profile whose connections are all simulators: the Internal connection, and the simulator connections of the hardware systems, such as CAN Simulation. Simulated trains can therefore never show occupancy on a real layout. If a real connection is added while trains are placed, they are all removed, with a warning.

How they are driven and seen

Turnouts with feedback sensors need something to answer their commands. On any simulated connection, LogixNG's Simulate turnout feedback action does this.

The track they run on

The simulator works out its own routes from the layout's configuration:

Block lengths matter: a train takes as long to cross a Block as its length and speed say.

The trains

A simulated train has a name, its locos (the first is at the front), its length, and how detectors see it: the whole train, only the loco, or the loco and a marker at the rear, such as a resistor wheelset.

A loco can be described from its roster entry. Its speed then comes from the measured steps of its speed profile, and its momentum from CV3 and CV4 in its roster file (with CV23 and CV24 in a consist). Without a profile, its speed is in proportion to the throttle setting, up to a scale 100 mph at the layout scale set in the Warrant preferences.

Placing a train

On a Layout Editor panel, in a profile whose connections are all simulators:

  1. Take the panel out of edit mode, and add a loco marker from the panel's Marker menu, from the roster or by typing its name.
  2. Drag the marker onto the track of the Block the train is to be in. The Place Simulated Train window opens, filled in with what is known. Usually OK is all that is needed.

The window asks for:

If the train can't be placed there, the window says why and asks again. Dropping the marker of a train that is already placed moves it. To take a train off, right-click the track of a Block it is in and choose Remove Simulated Train.

In a profile with a connection to a layout, a dropped marker never places a simulated train: it only tells train tracking where the train is.

From a script

Trains can also be placed by scripts. The sample script SimulatedTrains.py (Scripting ⇒ Run Script..., in a profile whose connections are all simulators, such as one with only the Internal connection) builds a short line of five Blocks, places two trains on it, drives them with Internal throttles, and prints after each move what each sensor reports beside which trains are really in each Block. It removes its trains at the end.

In a script of your own, a train is described and placed like this:

import jmri
from jmri.jmrit.simulation import Detection, SimulatedLayout, SimulatedLoco, VirtualTrain

loco = SimulatedLoco.builder(jmri.DccLocoAddress(3, False)).length(150).build()
train = VirtualTrain.builder("Goods").loco(loco).length(400).detection(Detection.entireTrain()).build()
layout = SimulatedLayout.getDefault()
# front 200 mm into Block B2, having come from Block B1
layout.place(train, blocks.getBlock("B2"), blocks.getBlock("B1"), 200)
...
layout.remove(train)

For a loco in the roster, use SimulatedLoco.builder(entry) with its roster entry instead of its address.

What they are for