User Tools

Site Tools


userpages:hermannk:departdelaychange-nl

This is an old revision of the document!


Vertrekvertraging - Verandering

Userpages - Hermann (hermannk)

Deze XML-script oplossing werd aangevraagd door een gebruiker die wat extra tijd nodig had voor de ingebouwde "Vertrekvertraging" van een blok.​

Directe sprong naar de workspace download.

Invoering

De waarde "Vertrekvertraging" (in seconden) maakt deel uit van de eigenschappen van een blok. Als de locomotief het "start" -commando krijgt, wordt het snelheidscommando vertraagd met de "Vertrekvertraging"
- waarde (zie Blok - Vertrekvertraging).​

Om speciale redenen moet deze waarde voor bepaalde locomotieven tijdens de looptijd worden verhoogd.
Daarvoor moet de "vertrekvertraging" -waarde van een blok worden aangepast.

<bk id="bk1" departdelay="10"/> \\

De timing is belangrijk! Het zal te laat zijn op het DEPART-event van het blok! Op dat moment wordt de oude "vertrekvertraging" - waarde gebruikt voor uitvoering.
Dus deze oplossing gebruikt
- het IN-event om de nieuwe "vertrekvertraging" -waarde van het blok voor te bereiden en
- de DEPART-event om de "vertrekvertraging" -waarde van het blok terug te zetten naar zijn oorspronkelijke waarde.
Daarmee wordt de nieuwe "vertrekvertraging" -waarde gebruikt voor uitvoering op het moment van het snelheidscommando voor de locomotief.

Om het compleet te maken wordt het XML-script alleen uitgevoerd voor die locomotieven die tot de klasse "DELAY" behoren.

<query vr="vr_ddS_class" table="lclist" id="mylocomotive" get="class"/>
<if condition="@vr_ddS_class = DELAY"> \\
Directe sprong naar de workspace download.

Explaining the script

- Preparations
- State IN
- State DEPART
- Changing the Depart Delay value

Preparations

At first a solution for a block named "bk1" is shown. At the end the general solution can be seen.
The XML-script will be named "ac_departdelaySet.xml".
The ID of all variables of this script start with the string "vr_ddS_".

The new alternative "departdelay" value is stored in the variable "vr_ddS_delayValue" at the very beginning of the script to make it easier for a user to change that value. In this solution there will be just one alternative value.

<vr id="vr_ddS_delayValue" text="" value="10" generated="true"/>

Because this script is called at two different events the actual event is saved in "vr_ddS_state".

<vr id="vr_ddS_state" text="%state%" generated="true"/>

Because this script should only be executes for locomotives of class "DELAY" we query for the locomotive ID and for the class of that locomotive and store the values in "vr_ddS_locid" and "vr_ddS_class".

<vr id="vr_ddS_locid" text="" generated="true"/>
<query vr="vr_ddS_locid" table="bklist" id="%callerid%" get="locid"/>
<vr id="vr_ddS_class" text="" generated="true"/>
<query vr="vr_ddS_class" table="lclist" id="@vr_ddS_locid" get="class"/>

At the end of the preparation the variable for the new value "vr_ddS_newValue" is cleared.

<vr id="vr_ddS_newValue" text="0" value="0" generated="true"/>
<trace text="ac_departdelaySet: begin %callerid% @vr_ddS_state @vr_ddS_locid @vr_ddS_class " />

State IN

It is assumed now that a locomotive of class "DELAY" is IN this block.
The original value is saved in "vr_ddS_orgValue".

    <vr id="vr_ddS_orgValue" text="-1" value="-1" generated="false"/>
    <query vr="vr_ddS_orgValue" table="bklist" id="%callerid%" get="departdelay"/>

The new value is prepared in " vr_ddS_newValue".

    <vr id="vr_ddS_newValue" value="#vr_ddS_delayValue"/>

State DEPART

It is assumed now that a locomotive of class "DELAY" is DEPARTing this block.
The original value is prepared at this time in " vr_ddS_newValue".

    <vr id="vr_ddS_newValue" value="#vr_ddS_orgValue"/>

Changing the Depart Delay value

It is still assumed that a locomotive of class "DELAY" is using this block.
The model of the calling block (%callerid%) needs got be changed by the new value "#vr_ddS_newValue":

  <model cmd="change">
    <bk id="%callerid%" departdelay="#vr_ddS_newValue"/>
  </model>

As can be seen the value attribute ("#") is used with "#vr_ddS_newValue" - not the text attribute ("@").

The script (single block)

At first this variant of the script will only work for just one block.
All comments and all trace lines are removed:

<xmlscript>
<vr id="vr_ddS_delayValue" text="" value="10" generated="true"/>
<vr id="vr_ddS_state" text="%state%" generated="true"/>
<vr id="vr_ddS_locid" text="" generated="true"/>
<query vr="vr_ddS_locid" table="bklist" id="%callerid%" get="locid"/>
<vr id="vr_ddS_class" text="" generated="true"/>
<query vr="vr_ddS_class" table="lclist" id="@vr_ddS_locid" get="class"/>
<vr id="vr_ddS_newValue" text="0" value="0" generated="true"/>
<if condition="@vr_ddS_class = DELAY">
<then>
  <if condition="@vr_ddS_state = in">
  <then>
    <vr id="vr_ddS_orgValue" text="-1" value="-1" generated="false"/>
    <query vr="vr_ddS_orgValue" table="bklist" id="%callerid%" get="departdelay"/>
    <vr id="vr_ddS_newValue" value="#vr_ddS_delayValue"/>
  </then>
  </if>
  <if condition="@vr_ddS_state = depart">
  <then>
    <vr id="vr_ddS_newValue" value="#vr_ddS_orgValue"/>
  </then>
  </if>
  <model cmd="change">
    <bk id="%callerid%" departdelay="#vr_ddS_newValue"/>
  </model>
</then>
</if>
</xmlscript>

The script (multiple blocks)

This variant of the script will work for more than one block.
Therefore each variable has to be defined for each block that should call this script.
This is done by adding the calipers ID "%callerid%" to each used variable ID.
The variable "vr_ddS_state" will be named "vr_ddS_%callerid%_state" (which results in "vr_ddS_bk1_state" for block "bk1") and so on.
:!: This requires all corresponding blocks to have "well formed" IDs (no spaces, no special characters, no …).
All comments and all trace lines are removed:

<xmlscript>
<vr id="vr_ddS_delayValue" text="" value="10" generated="true"/>
<vr id="vr_ddS_%callerid%_state" text="%state%" generated="true"/>
<vr id="vr_ddS_%callerid%_locid" text="" generated="true"/>
<query vr="vr_ddS_%callerid%_locid" table="bklist" id="%callerid%" get="locid"/>
<vr id="vr_ddS_%callerid%_class" text="" generated="true"/>
<query vr="vr_ddS_%callerid%_class" table="lclist" id="@vr_ddS_%callerid%_locid" get="class"/>
<vr id="vr_ddS_%callerid%_newValue" text="0" value="0" generated="true"/>

<if condition="@vr_ddS_%callerid%_class = DELAY">
<then>
  <if condition="@vr_ddS_%callerid%_state = in">
  <then>
    <vr id="vr_ddS_%callerid%_orgValue" text="-1" value="-1" generated="false"/>
    <query vr="vr_ddS_%callerid%_orgValue" table="bklist" id="%callerid%" get="departdelay"/>
    <vr id="vr_ddS_%callerid%_newValue" value="#vr_ddS_delayValue"/>
  </then>
  </if>

  <if condition="@vr_ddS_%callerid%_state = depart">
  <then>
    <vr id="vr_ddS_%callerid%_newValue" value="#vr_ddS_%callerid%_orgValue"/>
  </then>
  </if>

  <model cmd="change">
    <bk id="%callerid%" departdelay="#vr_ddS_%callerid%_newValue"/>
  </model>
</then>
</if>
</xmlscript>

Installation

The test plan looks like this. (Directe sprong naar de workspace download)

The action definition

The action is named "ac_departdelaySet" and is calling an external script "ac_departdelaySet.xml".

The block properties

The block should have defined "wait" = YES.
The depart delay of the block may be of any value - here a value of "4" seconds is used (see Block - Depart Delay).

The list of actions for this block must hold
- action ID "ac_departdelaySet" for the state "in"
- action ID "ac_departdelaySet" for the state "depart"
The other entries just display the depart delay value of the block in a text field of the plan. They are included in the test workspace. They are not required for the functionality of the depart delay script.

What has been shown for block "bk1" is also installed for block "bk2" in the test workspace.

The locomotive properties

The locomotive should have set "Use depart delay" = YES (see Locomotives - Use depart delay).
The locomotive should have set "Class" = "DELAY" (see Locomotives - Class).

Test sequence

- start the Automatic Mode,
- start each locomotive (do not use "Virtual start"),
- simulate the appropriate sensors and
- watch the delay the locomotive gets a velocity command larger than zero.

Remark: the "departdelay" value is not used by Rocrail in case of using "Virtual start locomotive"!
Have fun.

De werkruimte

The werkruimte to test the script.

userpages/hermannk/departdelaychange-nl.1614496413.txt.gz · Last modified: 2021/02/28 08:13 by hermannk