LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling RT Process and Stage Timing

Solved!
Go to solution

I have a cRIO 9023. I will need to control the timing of various processes and stages within each process. An example template is attached and uses a half second timer for each of three stages. Each process begins after the user chooses which process to start. I will need to control the length of each process independently of each other and the length of each stage independently (if required). For example:

 

1. Process 1 runs for 1 minute.

    a. Stage 1 runs for half a second

    b. Stage 2 runs for two seconds

    c. Stage 3 runs for three seconds

2. Process 2 runs for 2 minutes

    a. Stage 1 runs for two seconds

    b. Stage 2 runs for three seconds

    c. Stage 3 runs for half a second

3. Process 3 runs for 30 seconds

    a. Stage 1 runs for 10 seconds

    b. Stage 2 runs for two seconds

    c. Stage 3 runs for four seconds

 

Here is the attached example:

 

https://forums.ni.com/t5/Example-Programs/UI-Producer-Loop-with-State-Machine-Consumer-Loop-Using-La...

 

Any assistance greatly appreciated.

 

0 Kudos
Message 1 of 7
(2,877 Views)

If the duration is an input to your code, and you know it before you start any of your processes, then this should be easy - just include the durations in the message data that you send to the consumer (following the template you linked, although you don't have to do it that way) and then call each of your stages with the appropriate input.

 

If the different processes have different stages that they need to call (not just changed durations), then you might instead prefer to queue up the stages individually. Be aware that if you allow multiple locations in your code to place new items in your queue, then you can't guarantee the execution order is as you expect (so don't do this unless it doesn't matter - usually it matters!)


GCentral
0 Kudos
Message 2 of 7
(2,862 Views)

Thank you for the input - greatly appreciated. If you have a specific example of how to "...include the durations in the message data that you send to the consumer..." this would also be helpful. I have limited access to the cRIO that I am programming (hence, the delay to your response) and would like to make the most of my time spent hands-on.

 

I agree that manipulating the queues execution order may be more troublesome that its worth. 😞 

0 Kudos
Message 3 of 7
(2,829 Views)
Solution
Accepted by topic author Newton2this1

I've attached a zip file containing the VIs to run the example pictured below, which I quickly created.

The stages each call a Dialog VI, which displays the count-down and then closes.

Each stage can have a time specified in the caller.

 

stages.png

If you were to reproduce something like this, I strongly recommend using a typedef for the data type of the Queue - otherwise changing it later will be difficult (and you may decide you want to pass more data, in which case you'll need to change it.

 

In this example, I used the error output of the Queue to terminate the loop. A more complete example might have a data element containing an Enum or String, and a Variant, and then a series of typedefs of different data (including the time duration) for different commands (enum/string). The Variant then contains the appropriate data for a given command. One of your commands can then be a "stop" command.

 

Taken to a slightly further level, you have the Actor Framework (where each message is its own class, and so the data is strictly defined without needing so many typedefs or any variants (but now you have lots of classes).


GCentral
Message 4 of 7
(2,826 Views)

I think I see where you are going with this...!  I like it. 🙂 How would the Caller know however when to execute stage 1, then stage 2,...and so on? Hitting start in this case - (as you said earlier, we know what delays we want to enter in ahead of time) does not initialize or start stage 1 currently.

0 Kudos
Message 5 of 7
(2,818 Views)

At least when I ran it on this computer, hitting start does execute Stage 1, 2 and 3. Is that not what you observe? Are you sure your delays were long enough to observe (the defaults will be 0s, which may just cause a strange flickering 3 times, I'm not sure). If so, try changing them to 2 or 3 seconds each to be able to see the VIs.


GCentral
0 Kudos
Message 6 of 7
(2,816 Views)

Okay, weird. It is working now! I had chosen values for Stages 1,2,3 as 20,30,40 originally and nothing happened. I lowered the values to 2,3,4 and it took off running perfectly - go figure.  Thank you for the help! 🙂

0 Kudos
Message 7 of 7
(2,811 Views)