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
- Simulated trains obey the Internal connection's throttles, by DCC address, and on a CAN
Simulation connection the speed and direction its simulated command station gives each loco,
whichever cab sets them. A throttle window, Dispatcher, a Warrant or a script using one of
those drives them with no further set-up. Other connections' throttles don't drive them
yet.
- They set the layout's own occupancy sensors, the ones its Blocks already use, on any
simulator connection, so no extra sensors are needed. A sensor is set as a script or a
sensor icon sets it, so the connection sends what it would for that; on a CAN Simulation
connection, CBUS sensors send their own events as a real detector would. A Block's sensor
goes active when the first part of a train that detectors see enters it, and inactive when
the last of every train has left it.
- On some systems' simulator connections, such as CAN Simulation and the DCC-EX Simulator,
they also obey that connection's throttles and set its sensors, reported as that system's
command station or detectors report them. Each system's help page says whether its
simulator does.
- Two trains that touch both stop. A train whose turnout is moved under it derails and
stays where it stopped.
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:
- a Block drawn on a Layout
Editor panel is followed on the drawing, with its turnouts as they are set;
- an OBlock is followed through its Portals and paths;
- any other Block is followed by its own paths, each of which
names the Block it leads to.
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:
- 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.
- 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:
- DCC address, for a marker with no roster entry. A number the marker's
name starts with is offered. A marker from the roster uses its entry's address, speed
profile and momentum.
- Train length. Lengths in this window are in the units chosen for
Block lengths in the Block
table: whole millimetres when Blocks are in centimetres, or inches to 1/32 inch, shown
and typed as a whole number and a fraction such as
7 3/16, when Blocks are in
inches.
- Detected: the entire train, the head only (the loco, whose length is
then asked), or the head and tail (the loco and a marker at the rear, whose length is also
asked).
- Rear towards: the neighbouring Block the train's rear is towards, or
the end of the track. This is the way the train faces: running forward, it leaves by the
Block's other end.
- Front, into the Block: how far the train's front is into the Block,
measured from the end its rear is towards. The middle of the Block is offered. A train
longer than that reaches back into the Block behind.
- Also tell train tracking it is here: ticked, the drop also tells
train tracking
where the train is, as a dropped marker does on a real layout. Unticked, train tracking is
left to find the train from its detectors.
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
- Trying out Dispatcher, Warrants, Logix, LogixNG, scripts and panels before running them
on the layout, or when the layout isn't to hand.
- Showing how a layout's automation works, with trains moving on its panels.
- Testing JMRI itself. Tests and scripts can also set faults, such as a detector that
misses a train for a moment, a sensor showing a train that isn't there, two sensors wired
to each other's Blocks, a Block longer or shorter than JMRI has it, a train that stalls, or
a train that parts.