User Tools

Site Tools


userpages:hermannk:departdelaychange-en

Differences

This shows you the differences between two versions of the page.


userpages:hermannk:departdelaychange-en [2023/09/11 15:55] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Depart Delay - Change ======
 +[[:userpages#Hermann (hermannk)|Userpages - Hermann (hermannk)]] \\
 + \\
 +This XML-script solution was requested by a user who needed an extra amount of time for the build-in "Depart Delay" of a block. \\
 +|  Direct jump to the [[userpages:hermannk:departdelaychange-en#the_workspace|workspace]] download (update 11.09.2023).  |
 +
 +===== Introduction =====
 +The "Depart Delay" value (in seconds) is part of the properties of a block. As the locomotive gets the "start" command the velocity command is delayed by the "Depart Delay" value (see [[:block-gen-en#depart_delay|Block - Depart Delay]]). \\
 +Because of special reasons this value should be increased during runtime for certain locomotives. \\
 + \\
 +For that the "departdelay" value of a block has to be modified. \\
 +  <bk id="bk1" departdelay="10"/> \\
 +The timing is important! It will be too late at the DEPART-event of the block! At that time the old "departdelay" value is used for execution. \\
 +So this solution uses \\
 +- the IN-event to prepare the new "departdelay" value of the block and \\
 +- the DEPART-event to reset the "departdelay" value of the block to its original value. \\
 +With that the new "departdelay" value is used for execution at the time of the velocity command for the locomotive. \\
 + \\
 +To make it complete the XML-script will only be executed for those locomotives which belong to the class "DELAY". \\
 +  <query vr="vr_ddS_class" table="lclist" id="mylocomotive" get="class"/>
 +  <if condition="@vr_ddS_class = DELAY"> \\
 +
 +|  Direct jump to the [[userpages:hermannk:departdelaychange-en#the_workspace|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 data structure of the calling block (**%callerid%**) needs got be changed by the new value "#vr_ddS_newValue":
 +    <set vr="vr_ddS_newValue" table="bklist" id="%callerid%" set="departdelay" setint="true"/>
 +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>
 +     <set vr="vr_ddS_newValue" table="bklist" id="%callerid%" set="departdelay" setint="true"/>
 +  </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>
 +  
 +    <set vr="vr_ddS_%callerid%_newValue" table="bklist" id="%callerid%" set="departdelay" setint="true"/>
 +  </then>
 +  </if>
 +  </xmlscript>
 +
 +===== Installation =====
 +The test plan looks like this. (direct jump to the [[userpages:hermannk:departdelaychange-en#the_workspace|workspace]] download) \\
 +{{:userpages:hermannk:departdelay_plan.png?}} \\
 +
 +
 +==== The action definition ====
 +The action is named "**ac_departdelaySet**" and is calling an external script "**ac_departdelaySet.xml**". \\
 +{{:userpages:hermannk:departdelay_action_definition.png?|}} \\
 +==== 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-gen-en#depart_delay|Block - Depart Delay]]). \\
 +{{:userpages:hermannk:departdelay_block_general.png?}} \\
 +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. \\
 +{{:userpages:hermannk:departdelay_block_action.png?}} \\
 +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 [[:loc-details-en#use_depart_delay|Locomotives - Use depart delay]]). \\
 +The locomotive should have set "Class" = "DELAY" (see [[:loc-details-en#class |Locomotives - Class]]). \\
 +{{:userpages:hermannk:departdelay_loco_details.png?}} \\
 +
 +
 +==== 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. \\
 +===== The workspace =====
 +Update: 11.09.2023 \\
 +XMLscript "ac_departdelaySet.xml" has been modified: \\
 +old: \\
 +    <model cmd="change">
 +      <bk id="%callerid%" departdelay="#vr_ddS_%callerid%_newValue"/>
 +    </model>
 +New: \\
 +    <set vr="vr_ddS_%callerid%_newValue" table="bklist" id="%callerid%" set="departdelay" setint="true"/>
 + \\
 +The {{ :userpages:hermannk:departdelay_20230911.zip|workspace}} to test the script. \\
 +{{:userpages:hermannk:departdelay_plan.png?}} \\
 +