Skip to main content
Jython (Java based Python) scripting is a common tool for running trains automatically. The Python language is relatively easy to use and provides easy access to JMRI facilities, such as turnouts, sensors, blocks, etc. Access to JMRI throttles provides the ability to control locomotives.
The typical script sets turnouts, acquires a locomotive, runs the locomotive while keeping track of its location. Some scripts use occupancy sensors for the location, others rely on time durations.
Frequently the original script needs modifications as additional details are added. When a second train is added which has to share track with the first one, the script becomes ever more complicated.
YAAT is designed to eliminate the programming by using text files that contain English like phrases. For example:
sensor = sensors.getSensor('S-Sensor') If sensor is not None: sensor.setKnownState(ACTIVE)vs.
Set sensor S-Sensor active
Each train has its own text file, but they can coordinate actions by using JMRI sensors, etc.
YAAT works by referencing JMRI objects, such as turnouts, sensors, etc. This means that the layout definition needs to accurately describe the layout that will run the trains that YAAT will be controlling.
Some of the YAAT actions have specific requirements. The signal head and signal mast actions are obvious. The block actions need to have blocks assigned to Layout Editor track components, such as track segments and turnouts.
Since the YetAnotherAutoTrain.py script needs to be modified, the script should be copied from the JMRI install location to the user files location. See Help ⇒ Locations.
Each train needs a set of actions. The orignal design had the actions included in the script file. That feature will be removed in a future release.
The following descriptions used the following formatting:
The If and Endif actions are required. The Else action is optional and is used to separate the true and false actions. Nesting is supported.
The sub routines are placed at the end of an embedded list or text file. The sub routines cannot be nested, but a sub routine can call another sub routine. The sub routine name cannot have spaces. Control returns to the statement after the CallSub when the sub routine is finished.
A demonstration system is available at YAAT Demo. The zip file is a JMRI profile. After expanding the zip file, place the YAAT.jmri directory next to the other profiles and it should show up in the profile list. The demo panel is based on JMRI 4.20.
After starting PanelPro, click on the Open Panel File button and select yaat demo.xml.
Click on the Load YAAT button to start the process. After several seconds the button label will change to Running. Click on the Paused button to start a train. The button label will change to Run. Cllcking again will pause the train when it finishes a loop. Click on Stop to terimnate the train and remove it from the system.
The Stop Threads button will terminate all trains immediately. Active trains might continue running at the last throttle setting.
The standard YAAT process compiles each train from its text file or from the embedded content. THe result of the compile process is a set of tokens that are interpreted while the train is running. The duration of the compile step depends on the number of trains and the number of actions.
If the saveYAATcompiles option is true, a compiled train will be used instead of doing the compile step.
A compiled train is located at the preference:yaatp/<trainname> directory. When YAAT is started, the date/time for each train source file is checked. If it is greater than the compiled train, if any, the compile will occur. Otherwise the compiled version will be loaded. Embedded trains are always compiled.
An extension is a separate Python file that contains additional actions.
Each action requires a do<name> method (def) and a compile<name> method (def). The format of an action name is verb_noun, such as Set_memory... The typical space for built-in actions is replaced with an underscore.
The custom actions are added to the customExtensions dictionary. The key is the file name and the data is a list of actions.
Copyright © 1997 - 2021 JMRI Community. JMRI®, DecoderPro®, PanelPro™, SignalPro™, TrainPro™, DispatcherPro™, OperationsPro™ and associated logos are our trademarks. Additional information on copyright, trademarks and licenses is linked here.
View the View the Site Status.