From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LV DataFlow Suggestions and Why Conditional For Loops Won't Exit Right Away.

Solved!
Go to solution

Hi all,

New to LV. I have a system of relays driving pneumatic solenoids with limit switch feedback to show that each relay has actually completed what it was commanded. They are dependent on each other, i.e. they follow each other in a sequence. There is timing, checks for user inputs, and safety sensors along the way. I would like the program to bail out IMMEDIATELY if any of the user inputs, i.e. Stop condition, prior relay status mismatch, or safety relay conditions occur.

 

I am having the hardest time trying to visualize how to do this. Here is a small piece of what I am doing. The For Loop will not exit upon the first false condition. Essentially if I trip a condition during the test I default to a false state. This causes the program to just cascade false states until the program is complete. I need to be able to exit immediately.

 

Right now I am strong-arming the limit switch feedback since I don't have the test fixture built up yet and I am working from home 🙂

I have shown a true and false case, both cases have essentially the same false case shutting things down safely.

garretw_0-1585863650323.png

 

 

Any help is much appreciated!

0 Kudos
Message 1 of 8
(2,206 Views)
Solution
Accepted by topic author garretw

LabVIEW operates on the Dataflow Principle.  If you remember two main rules, you will know what runs and when.

 

1.  A structure, node, subVI, will not execute until all inputs to it are available.

2.  A structure, node, subVI will not finish until all code inside of it has completed.

 

Structures include the For Loop and the flat sequence structure inside your code.  So although the first frame of your flat sequence is complete and is telling the loop to stop, you still need to wait for the 2nd frame of the sequence to complete.  At that time the OR function will have both of its inputs then will pass the True to stop terminal of the For Loop and then it can complete.

 

What you need is a state machine architecture. It is a loop with a case structure.  Each case of the structure represents a state, or an action to do.  When a state is complete, it can signal to itself through a shift register what is the next action to take.  Whether that is to stop, go to step 2,  go back to step 1 and also increment a counter. 

 

PS:  Your control and indicators for # of shots should be an integer not a floating point value since it is a straight up count, never fractional.

 

Message 2 of 8
(2,199 Views)

@RavensFan wrote:

LabVIEW operates on the Dataflow Principle.  If you remember two main rules, you will know what runs and when.

 

1.  A structure, node, subVI, will not execute until all inputs to it are available.

2.  A structure, node, subVI will not finish until all code inside of it has completed.

 

Structures include the For Loop and the flat sequence structure inside your code. 


No, unfortunately, strictly speaking, that's not true.

 

A flat sequence structure will not wait until all inputs are available..

 

A flat sequence structure frame will fire when it's inputs are available.

 

The reverse is also true. A flat sequence structure frame output is available when the frame is done. It won't wait until the structure is finished.

 

In itself a reason not to use a flat sequence structure...

 

Spoiler

 

FSS are weird.png

Both popups fire after 1 second. Long before the structure is finished or completely started!

 

Message 3 of 8
(2,124 Views)

Yes.  Wiebe is correct.

 

A flat sequence "structure", while singular, is really a series of  frames where each is a structure in itself with a an inherent dataflow dependency is assigned that frame 2 can't execute until after 1 is done,  and so on.

 

It really doesn't change the explanation to why your code behaves the way it does as the loop still requires the output from the 2nd frame in order to evaluate the stop condition.

 

The rules I stated are correct, it is just that a flat sequence "structure" is a special entity that is really a series of "structures".

Message 4 of 8
(2,115 Views)

wiebe@CARYA wrote:

A flat sequence structure frame will fire when it's inputs are available.

 

The reverse is also true. A flat sequence structure frame output is available when the frame is done. It won't wait until the structure is finished.

 

In itself a reason not to use a flat sequence structure...

 

Spoiler

 

FSS are weird.png

Both popups fire after 1 second. Long before the structure is finished or completely started!


If you add that a previous frame is considered an input i agree. 🙂 The 2nd frame wont start until the 1st is finished, but the outputs don't need to wait for the following ones to output results, unless they're wired through.

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 8
(2,108 Views)

@Yamaeda wrote:

wiebe@CARYA wrote:

A flat sequence structure frame will fire when it's inputs are available.

 

The reverse is also true. A flat sequence structure frame output is available when the frame is done. It won't wait until the structure is finished.

 

In itself a reason not to use a flat sequence structure...

 

Spoiler

 

FSS are weird.png

Both popups fire after 1 second. Long before the structure is finished or completely started!


If you add that a previous frame is considered an input i agree. 🙂 The 2nd frame wont start until the 1st is finished, but the outputs don't need to wait for the following ones to output results, unless they're wired through.

 


Yes, indeed! It might help to think of flat sequence structure frames as structures, forced in sequential expectation.

 

Or, as a monstrosity 👺.

Message 6 of 8
(2,105 Views)

Thank you all for the clarification and help, also the integer tip. I was looking into the state machine architecture a little bit, but the only other LV colleague at my location recommended against it. I am going to go with my gut and what you all have said.

 

Thank you very much! Have good weekends!

0 Kudos
Message 7 of 8
(2,064 Views)

😆

 

Definitely go with your gut on that.

0 Kudos
Message 8 of 8
(2,054 Views)