开云体育

Script with wait timer - how do I do it? #jython


 

A while back I asked about how to make a script that would simulate a train moving around a layout. I got some help but the task seemed to complex so I gave up - until now.
?
So, It was given some hints by Dave Sand and Bob Jacobson on ways to do this. Also I hadn't looked yet at all of the scripts and tools available. Now I see there are some scripts that kind of do what I want but not exactly.
?
Here is what I am trying to do:
Start a virtual train in some block with a direction to head and an average speed.
the script will look ahead to the next signal and add up the distance. If the signal is clear it will begin to activate block sensors in the direction of travel at a rate near the average speed.? It will also de activate block sensors "behind" the train.?
With this script a human dispatcher could control the movement by setting switches and signals.
?
In the future maybe It could actually run a train.
?
I see there is a script that called RobotThrottle.py that kind of does this, but I don't think it does any simulation, also I can't get it to run. maybe because I have simulated I/O ?
?
I also found a script called blocklister.py that seemed like something I could understand so I used that as my starting point.? ( I also added the block metric to the lister output since there seems to be no easy way to get that info).
?
So now I have a script that will look east to the next signal mast, add up the distance and then prepare to set the block sensors accordingly.??
the problem I am having is how to control the timing?? waitMsec() doesn't work because apparently it will run in a different thread and does not make my script wait.? There is a timer for a grade crossing in GradeCrossing.py I can get this timer to work but I am a bit lost on how to use it as a variable delay in some kind of while or for next loop that is stepping through a list or series of blocks at a controlled rate.
?
I admit that I have a lot to learn about python classes and objects so up to now I have just been hacking the examples.? Also the JMRI documentation is huge and there seems to be many different classes and methods that can to the same or similar things.
?
If you can give me some hints I would appreciate it.
?
?
?
?


 

John,

In some respects, you are trying to do what Dispatcher already does. ?However, Entry/Exit and Dispatcher both want to be in control.

The waitMsec works fine as long as your virtual train script is using the AbstractAutomaton class. ?This also provides the ability to create and control JMRI throttles. ?The?AbstractAutomaton "handle" def would be the train controller. ?

For building your block list, the Block/Path data from BlockLister.py probably works. ?I would use the "neighbor" support in LayoutBlock.

Dave Sand




----- Original message -----
From: "John Figie via groups.io" <zephyr9900=[email protected]>
Subject: [jmriusers] Script with wait timer - how do I do it? #jython
Date: Thursday, February 13, 2025 2:33 PM

A while back I asked about how to make a script that would simulate a train moving around a layout. I got some help but the task seemed to complex so I gave up - until now.
?
So, It was given some hints by Dave Sand and Bob Jacobson on ways to do this. Also I hadn't looked yet at all of the scripts and tools available. Now I see there are some scripts that kind of do what I want but not exactly.
?
Here is what I am trying to do:
Start a virtual train in some block with a direction to head and an average speed.
the script will look ahead to the next signal and add up the distance. If the signal is clear it will begin to activate block sensors in the direction of travel at a rate near the average speed.? It will also de activate block sensors "behind" the train.?
With this script a human dispatcher could control the movement by setting switches and signals.
?
In the future maybe It could actually run a train.
?
I see there is a script that called RobotThrottle.py that kind of does this, but I don't think it does any simulation, also I can't get it to run. maybe because I have simulated I/O ?
?
I also found a script called blocklister.py that seemed like something I could understand so I used that as my starting point.? ( I also added the block metric to the lister output since there seems to be no easy way to get that info).
?
So now I have a script that will look east to the next signal mast, add up the distance and then prepare to set the block sensors accordingly.??
the problem I am having is how to control the timing?? waitMsec() doesn't work because apparently it will run in a different thread and does not make my script wait.? There is a timer for a grade crossing in GradeCrossing.py I can get this timer to work but I am a bit lost on how to use it as a variable delay in some kind of while or for next loop that is stepping through a list or series of blocks at a controlled rate.
?
I admit that I have a lot to learn about python classes and objects so up to now I have just been hacking the examples.? Also the JMRI documentation is huge and there seems to be many different classes and methods that can to the same or similar things.
?
If you can give me some hints I would appreciate it.
?
?
?
?

Attachments:
  • NAPM_VTrain2.py


 

Hi John
I wanted to run a virtual train using dispatcher, and have written dispatcher system (with help from Dave Sand with the setup program) which does just that? .
It also runs an actual train if you want to do that. Full documentation is provided
Bill Fitch

On Thu, 13 Feb 2025 at 21:20, Dave Sand via <ds=[email protected]> wrote:
John,

In some respects, you are trying to do what Dispatcher already does.? However, Entry/Exit and Dispatcher both want to be in control.

The waitMsec works fine as long as your virtual train script is using the AbstractAutomaton class.? This also provides the ability to create and control JMRI throttles.? The?AbstractAutomaton "handle" def would be the train controller. ?

For building your block list, the Block/Path data from BlockLister.py probably works.? I would use the "neighbor" support in LayoutBlock.

Dave Sand




----- Original message -----
From: "John Figie via " <zephyr9900=[email protected]>
Subject: [jmriusers] Script with wait timer - how do I do it? #jython
Date: Thursday, February 13, 2025 2:33 PM

A while back I asked about how to make a script that would simulate a train moving around a layout. I got some help but the task seemed to complex so I gave up - until now.
?
So, It was given some hints by Dave Sand and Bob Jacobson on ways to do this. Also I hadn't looked yet at all of the scripts and tools available. Now I see there are some scripts that kind of do what I want but not exactly.
?
Here is what I am trying to do:
Start a virtual train in some block with a direction to head and an average speed.
the script will look ahead to the next signal and add up the distance. If the signal is clear it will begin to activate block sensors in the direction of travel at a rate near the average speed.? It will also de activate block sensors "behind" the train.?
With this script a human dispatcher could control the movement by setting switches and signals.
?
In the future maybe It could actually run a train.
?
I see there is a script that called RobotThrottle.py that kind of does this, but I don't think it does any simulation, also I can't get it to run. maybe because I have simulated I/O ?
?
I also found a script called blocklister.py that seemed like something I could understand so I used that as my starting point.? ( I also added the block metric to the lister output since there seems to be no easy way to get that info).
?
So now I have a script that will look east to the next signal mast, add up the distance and then prepare to set the block sensors accordingly.??
the problem I am having is how to control the timing?? waitMsec() doesn't work because apparently it will run in a different thread and does not make my script wait.? There is a timer for a grade crossing in GradeCrossing.py I can get this timer to work but I am a bit lost on how to use it as a variable delay in some kind of while or for next loop that is stepping through a list or series of blocks at a controlled rate.
?
I admit that I have a lot to learn about python classes and objects so up to now I have just been hacking the examples.? Also the JMRI documentation is huge and there seems to be many different classes and methods that can to the same or similar things.
?
If you can give me some hints I would appreciate it.
?
?
?
?

Attachments:
  • NAPM_VTrain2.py


 

For full instructions search for 'Dispatcher System' in JMRI help

On Fri, 21 Feb 2025 at 21:57, bill fitch via <bill.fitch14=[email protected]> wrote:
Hi John
I wanted to run a virtual train using dispatcher, and have written dispatcher system (with help from Dave Sand with the setup program) which does just that? .
It also runs an actual train if you want to do that. Full documentation is provided
Bill Fitch

On Thu, 13 Feb 2025 at 21:20, Dave Sand via <ds=[email protected]> wrote:
John,

In some respects, you are trying to do what Dispatcher already does.? However, Entry/Exit and Dispatcher both want to be in control.

The waitMsec works fine as long as your virtual train script is using the AbstractAutomaton class.? This also provides the ability to create and control JMRI throttles.? The?AbstractAutomaton "handle" def would be the train controller. ?

For building your block list, the Block/Path data from BlockLister.py probably works.? I would use the "neighbor" support in LayoutBlock.

Dave Sand




----- Original message -----
From: "John Figie via " <zephyr9900=[email protected]>
Subject: [jmriusers] Script with wait timer - how do I do it? #jython
Date: Thursday, February 13, 2025 2:33 PM

A while back I asked about how to make a script that would simulate a train moving around a layout. I got some help but the task seemed to complex so I gave up - until now.
?
So, It was given some hints by Dave Sand and Bob Jacobson on ways to do this. Also I hadn't looked yet at all of the scripts and tools available. Now I see there are some scripts that kind of do what I want but not exactly.
?
Here is what I am trying to do:
Start a virtual train in some block with a direction to head and an average speed.
the script will look ahead to the next signal and add up the distance. If the signal is clear it will begin to activate block sensors in the direction of travel at a rate near the average speed.? It will also de activate block sensors "behind" the train.?
With this script a human dispatcher could control the movement by setting switches and signals.
?
In the future maybe It could actually run a train.
?
I see there is a script that called RobotThrottle.py that kind of does this, but I don't think it does any simulation, also I can't get it to run. maybe because I have simulated I/O ?
?
I also found a script called blocklister.py that seemed like something I could understand so I used that as my starting point.? ( I also added the block metric to the lister output since there seems to be no easy way to get that info).
?
So now I have a script that will look east to the next signal mast, add up the distance and then prepare to set the block sensors accordingly.??
the problem I am having is how to control the timing?? waitMsec() doesn't work because apparently it will run in a different thread and does not make my script wait.? There is a timer for a grade crossing in GradeCrossing.py I can get this timer to work but I am a bit lost on how to use it as a variable delay in some kind of while or for next loop that is stepping through a list or series of blocks at a controlled rate.
?
I admit that I have a lot to learn about python classes and objects so up to now I have just been hacking the examples.? Also the JMRI documentation is huge and there seems to be many different classes and methods that can to the same or similar things.
?
If you can give me some hints I would appreciate it.
?
?
?
?

Attachments:
  • NAPM_VTrain2.py