LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean loop termination if all values equal

Solved!
Go to solution

Hey guys,

 

I'm working on automating a process at work. We are monitoring temperature with a thermal camera in a while loop. The thermal camera saves to a txt file and LV reads out the values from the text file.

 

This bit works well but LV has no feedback if the thermal values stop being rewritten. (eg. Loss of connection to the camera) I wanted to record the most recent four values (previous 4 loops) and confirm that all values in the array are not equal to each other. If equal, generate a boolean true which i can use to stop the loop and flag the fault.

 

For the boolean i was thinking i could use the min / max function from the array pallet paired with the = to function in the comparison pallet to create the boolean but having difficulty building an array with 4 rolling values from the loop.

 

I can whip up some code quick to illustrate what i mean if this doesn't make sense. Just let me know.

 

Thanks,

 

0 Kudos
Message 1 of 10
(4,038 Views)

Use a shift register.

 

Either rotate a pre-sized Boolean array, or simply use build array and split string (or delete from array) to keep the array 4 elements.

4 Booleans.png

 

There are so many ways to do this, it's scary.

 

 

The min max is a bit  obscure, but a good compact way to check if all values are the same.

0 Kudos
Message 2 of 10
(4,028 Views)
Solution
Accepted by Ghost_79

Here's one possible way to stop a loop if the input is equal for 4 consecutive iterations.

 

altenbach_0-1638903099733.png

 

 

You haven't really explained in detail how the file(s) are written, updated and read. Is each image in a new file? Is each image appended to an existing file? Does it overwrite the current file? If the file contains just the last image, there is no need to parse it into value. Just compare the entire file as a string. Maybe you could just read the modification time of the file? So many possibilities!

0 Kudos
Message 3 of 10
(4,016 Views)

Hi Altenbach thanks for your response.

 

So the temperature data from the camera is extracted from the image and saved to a text file by a c# program. This txt file is overwritten with new values every 500 ms.

 

I'm pulling the data out via a read from txt file function than converting the value from a string to a float. The read function is performed every loop iteration and compared to an upper threshold value via a less than comparator. Boolean out is wired to the stop terminal on the while. This is meant to stop the part from exceeding a max temperature. This loop also measures optical power and has a min / max threshold with similar boolean controls to stop the loop and combines the boolean signals through an OR function.

 

The main measurement loop is set to terminate after 30s and takes about 250 ms to complete 1 iteration so it could run as many as many as 120 times in 1 cycle if all stop conditions are false. The timer expired boolean is also OR-ed into the stop terminal with the other two.

 

So what I'm looking for is for LabVIEW to consider the most recent 4 loops temperature measurement values (floats) and confirm all four are not equal. If so, generate a true. Else false.

 

Does this clear things up or have I made things worse? I'll try and build an example app and supply it when I return to work tomorrow if the latter. Unfortunately the main VI is not at all concise or optimized so it's embarrassing to post directly. Thanks for your time.

 

 

 

 

 


 

0 Kudos
Message 4 of 10
(3,993 Views)

@Ghost_79 wrote:

So what I'm looking for is for LabVIEW to consider the most recent 4 loops temperature measurement values (floats) and confirm all four are not equal. If so, generate a true. Else false.

 


My code will stop the loop if four consecutive values are identical. You can substitute any datatype for the "value", which is a 2D array in the picture (scalar float, string, integer, whatever.). The feedback node gives the value from the previous iteration, which is compared with the new value. You can probably use the string directly, no need to scan it into a float.

0 Kudos
Message 5 of 10
(3,989 Views)

@Ghost_79 wrote:

So what I'm looking for is for LabVIEW to consider the most recent 4 loops temperature measurement values (floats) and confirm all four are not equal. If so, generate a true. Else false.


To check if all four are not equal you'll have to keep a buffer of all 4 values.

 

That's basically what I posted, only you'd have to keep the values, not the Booleans.

 

You can use a set to check if all 4 values are different:

4 different values.png

 

Note that you're comparing floats, which is generally a bad idea. Those floats better be quantized in some way, because 1.2 doesn't always equal 1.2.  See for instance equality - What's wrong with using == to compare floats in Java? - Stack Overflow or Comparing Floating-Point Numbers Is Tricky (bitbashing.io). It's the same problem for Java, C++, C# and LabVIEW...

 

 

0 Kudos
Message 6 of 10
(3,940 Views)

@Ghost_79 wrote:

So what I'm looking for is for LabVIEW to consider the most recent 4 loops temperature measurement values (floats) and confirm all four are not equal. If so, generate a true. Else false.

 


This is actually an incorrect algorithm for the given problem. All you need to see is if the value has not changed in the last four updates. For that it is sufficient to compare each new value with the previous as I have done.

 

For example if the last five values are A-B-C-B-A, they have been correctly updated four times, once with each iteration, even though some of the values are the same.

 

I would still recommend an out-of-band monitoring of the instrument connection, depending on the noise and bit resolution of the signal and formatting, values can be the same even if there was an update.

 

You are good comparing floating point numbers because if the value does not update, it will be binary identical. But in the general case, listen to Wiebe. Remember that I said to compare the string instead (avoiding the expensive scanning!). Faster and safer!

0 Kudos
Message 7 of 10
(3,918 Views)

Also be aware that doubles have the NaN corner case.  NaN is not equal to anything, including NaN.  If you could have a NaN value then just know extra code is needed to evaluate if it is the same.

0 Kudos
Message 8 of 10
(3,908 Views)

Thanks for the follow-up. I'm pleased to report I implemented your code this morning and it's working great. I guess new members are only allowed two posts in the first 24 hours so sorry for the late response. Thanks for the suggestions everyone and the cautions relating to float comparisons. In my little corner case the many sig figs actually work to my advantage because im far less likely to get consecutive identical values out to 4 digits of precision if the instrument is actually measuring as intended.

 

Thanks again!!

 

I'll keep an eye out for the NaN values thanks for the warning.

Message 9 of 10
(3,896 Views)

And a kudo (your first) for accepting a solution and being a responsive author!

 


@Ghost_79 wrote:

I guess new members are only allowed two posts in the first 24 hours so sorry for the late response.


Sadly, that seems to be necessary.  

0 Kudos
Message 10 of 10
(3,857 Views)