开云体育

Locked Re: Getting throttle settings with LogixNG #logixng


 

Jos,

I made some assumptions.

Here is a script:

# Called by LogixNG to get the current throttle speed setting for an auto active train.

# The train name is in the trainName local variable.
# Return the train speed in the speed local variable.? -2 indicates no train, -1 indicates emergency stop, 0.0 to 1.0 is the train speed

import java
import jmri

trainName = symbolTable.getValue('trainName')
speed = -2.0??? # Default to no train found

dispFrame = jmri.InstanceManager.getDefault(jmri.jmrit.dispatcher.DispatcherFrame)

for at in dispFrame.getActiveTrainsList():
??? if at.getAutoRun():
??????? if at.getTrainName() == trainName:
??????????? aat = at.getAutoActiveTrain()
??????????? speed = aat.getTargetSpeed()

symbolTable.setValue('speed', speed)

And a test LogixNG:

LogixNG: Get Train Speed
??? ConditionalNG: IQC:AUTO:0001 ::: Startup
??????? ! A
??????????? Many
?????????????? ::: Local variable "trainName", init to String "asdf"
?????????????? ::: Local variable "speed", init to Floating number "-3.0"
??????????????? ! A1
??????????????????? Execute script: Run script. Script preference:trainspeed.py
??????????????? ! A2
??????????????????? Log local variables

Dave Sand



----- Original message -----
From: Dave Sand <ds@...>
Subject: Re: [jmriusers] Getting throttle settings with LogixNG #logixng
Date: Friday, September 06, 2024 2:38 PM

Jos,

What is in the memory variable? ?A string or a roster entry? ?If it is a string, what does the string value represent?

How does the ConditionalNG stop and start a train?

Dave Sand


----- Original message -----
From: Jos Smeele <jossmeele@...>
Subject: Re: [jmriusers] Getting throttle settings with LogixNG #logixng
Date: Friday, September 06, 2024 2:02 PM

If I start a Dispatch then I can follow the train around the track by querying the Block-comment.
I wrote a ConditionalNG to resolve a conflicting situation when two trains approach a crossing and Dispatcher doesn't always stop one of the trains to avoid a crash. I use the Block-comment to determine which train to stop and which to allow to continue.
The ConditionalNG will stop one train, then restart it when the other train has passed. I've got this working but would like to restart the stopped train at the same speed it was running before it got stopped.
Jos


Join [email protected] to automatically receive all group messages.