User Tools

Site Tools


userpages:hermannk:loco_starts_loco-en

Loco Starts Loco

Userpages - Hermann (hermannk)Loco Starts Loco


Here you go directly to the Rocrail-Workspace-Download

Foreword 1:
This documentation was created with this: Status 03.05.2024

Area Details Remarks
Control Rocrail Version 2.1.4545+ (macOS "Sonoma" on Apple M2 CPU)
Computers MacBook Pro (M2) macOS 14.2.1 (Sonoma)

Foreword 2:
- the use of this solution is at your own risk;
- regular backups of the Rocrail workspace are recommended.

A) Task

As soon as a loco arrives at a station the next loco should start.

The station consists of blocks bk01, bk11, bk21 and bk31.
The station blocks are configured: Block Properties / Details / Wait / Type = Stop

B) Solution Details

As soon as a locomotive has arrived in a block two things have to be done:

  • a) if there is a saved command the command should be executed;
  • b) the locomotive of the next block should start;
  • b1) if the next block is empty the drive command for that block must be saved;
  • b2) if the locomotive is already present in the next block the locomotive can start immediately.


Every block of the station will get an action "ac_Loco_Starts_Loco" triggered at the IN event.
The action "ac_Loco_Starts_Loco" starts the XMLScript "ac_Loco_Starts_Loco.xml".
Starting the action is done with the parameter "block ID of the next block".
356

The XMLScript

The scripts starts to display the calling parameters:

<trace text="ac_Loco_Starts_Loco: begin %callerid% %state% for %param1%"/>
Parameter Explanation Example value
%callerid% the block ID of the calling block bk01
%state% the event state of the calling block in
%param1% the first Parameter of the call bk11

In othrer words: if a loco arrives in block "bk01" the loco in block "bk11" should start.

a) Execute a saved command

If there is a saved command the command should be executed.
The saved command is stored in the variable "vr_LSL_%callerid%_todo".
For the calling block "bk01" this variable will have the ID "vr_LSL_bk01_todo".
The command is stored as the value "1"; otherwise the value is "0".

  <if condition="#vr_LSL_%callerid%_todo > 0" >
  <then>
    <trace text="- LSL: prepare late start loco in %callerid% "/>
    <sleep time="2000"/>
    <trace text="- LSL: late start loco in %callerid% "/>
    <lc bkid="%callerid%" cmd="govirtual"/>
    <vr id="vr_LSL_%callerid%_todo" value="0"/>
  </then>
  <else>
    <!-- do nothing here -->
  </else>
  </if>

If there is a saved command:

Statement Explanation
<sleep time="2000"/> wait a short amount of time - here 2 seconds.
<lc bkid="%callerid%" … /> the locomotive in block %callerid% - here "bk01"
<lc … cmd="govirtual"/> start the locomotive in virtual mode
<lc … cmd="go"/> start the locomotive in normal mode
<vr id="vr_LSL_%callerid%_todo" value="0"/> reset the variable

b) Start next loco

If the next block is occupied:
- start the locomotive of the next block immediately;
otherwise:
- store a saved command for the next block.

   <if state="bk %param1% = occupied" >
  <then>
    <!-- start next loco immediately -->
    <trace text="-LSL: start next loco in %param1% "/>
    <vr id="vr_LSL_%callerid%_todo" value="0"/>
    <vr id="vr_LSL_%param1%_todo" value="0"/>
    <lc bkid="%param1%" cmd="govirtual"/>
  </then>
  <else>
    <!-- prepare next start -->
    <trace text="@vr_LSL_%param1%_todo will soon start in %param1% "/>
    <vr id="vr_LSL_%param1%_todo" value="1"/>
  </else>
  </if>

b1) The next block is occupied

Statement Explanation
<if state="bk %param1% = occupied" > if the next block is occupied - here %param1% is "bk11"
<vr id="vr_LSL_%callerid%_todo" value="0"/> reset our saved command
<vr id="vr_LSL_%param1%_todo" value="0"/> reset the saved command for the next block
<lc bkid="%param1%" … /> start the locomotive of the next block %param1% - here "bk11"
<lc … cmd="govirtual"/> start the locomotive in virtual mode
<lc … cmd="go"/> start the locomotive in normal mode

b2) The next block is not occupied

Statement Explanation
<vr id="vr_LSL_%param1%_todo" value="1"/> store the saved command for the next block %param1% - here "bk11"

C) Rocrail workspace

The download workspace "loco_starts_loco.zip" contains the following files:

file meaning
plan.xml the Rocrail plan file
ac_Loco_Starts_Loco.xml the XML script

back to the solution-details.

D) Outlook

You are welcome to implement your own ideas on the basis of this solution.
For example, a second parameter could be used to specify a schedule identifier with which the locomotive should be started in the next block.

Parameters bk11,bk11_runaround next block "bk11", schedule identifier "bk11_runaround"
XMLScript <vr id="vr_LSLs_%param1%_todo" value="1" text="%param2%"/> save schedule identifier
XMLScript <lc bkid="%param1%" cmd="useschedule" scheduleid="%param2%"/> apply schedule identifier
Workspace loco_starts_loco_schedule.zip

Have fun and good luck.

userpages/hermannk/loco_starts_loco-en.txt · Last modified: 2024/05/03 19:23 by hermannk