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: 

"Check if True, Then Continue" - How to Implement?

Solved!
Go to solution

Hello LV Community,

 

I am trying to create a VI that checks if a certain condition (in this case, that the wavelength my monochromator is putting out is at the correct value) is true, then continues and takes measurement. I tried using a combination of a case structure and a timed sequence (see attached screenshot - I'm self-taught and a beginner so sorry if it's a disaster stylistically), but the case structure requires there to be an input from the "false" case into the tunnel. I just want it to do nothing if the case is false - any inputs from "false" would be added to the "sum array elements" and taint my data (right?), so I don't want that.

 

Thanks!

0 Kudos
Message 1 of 7
(4,938 Views)

Something has to be done in the false case.  What do you want to sum if the case is false?

 

Perhaps if we saw more of your code then just a tight screenshot of one section, we can give you a better idea what to do.

 

If you don't want to do things like sum the array, then that part of the code should be in the case structure as well.

0 Kudos
Message 2 of 7
(4,928 Views)

Hi RavensFan,

 

If the case is false, I would like the program to wait until the case has become true (and, I suppose, if it fails to become true after a certain time, display an error message and time out). There is nothing that I would like summed in the false case - I just want my power meter to sit idle and update once the mono has begun outputting the desired wavelength.

 

I think my issue (or, potentially, misunderstanding) comes because there will be times when the case is false, because the mono has to move the motor, but I don't want there to be any data put out in that time - just waiting. Is there a better structure to use for that than the case structure? Is there a way to add a "continue when true" item to the sequence structure?

Full screenshot provided (there are a number of instrument-specific sub-VI's from Newport on the block diagram; I've added commenting to explain them)

 

Thanks!

0 Kudos
Message 3 of 7
(4,921 Views)
Solution
Accepted by topic author WorkerDrone

If you are waiting for something to become true, that means you need to keep looping and testing the condition until that happens.

 

Hearing that you are working with a motor move, and a series of steps that involve some waits in between, it sounds like you should be developing a "state machine" architecture.  Search the forums for that topic.  There is even a template for it in LabVIEW.

 

A state machine allows a sequence of events to occur, but you build in intelligence so that it know when to move onto the next step, or when to return to the same step (such as to measure something and check the condition again), or perhaps even return to an earlier stop.

 

I see you have potential race conditions in your current code with the way you are using local variables.  Within just the For Loop, you are reading Current Wavelength at 3 different places, and writing to it once.  But you have a race between when the one read and update occurs and when it gets read in the other two locations. You don't know whether you'll get an old Current Wavelength or a newly updated current wavelength on every loop iteration.  Just from looking at your code, I can't even tell which way you want it to be.

0 Kudos
Message 4 of 7
(4,904 Views)

State machine it is; thank you so much!

As for the race condition, that's sloppiness / being bad at LabView on my part - I want it to do the measurements for a certain wavelength, then update the wavelength and repeat.

0 Kudos
Message 5 of 7
(4,896 Views)

Store the wavelength in a shift register so you have it every loop iteration.  Update the value going to the shift register only in whatever steps  ("states") where that makes sense.

0 Kudos
Message 6 of 7
(4,892 Views)

Thank you again! You are the hero of this forum

0 Kudos
Message 7 of 7
(4,888 Views)