12-15-2017 09:10 AM
Hello,
I would like to create a loop function with a changing value. I want to create a binary image with the IMAQ threshold. Now I want to change the lower value in the front panel and I want that the new binary image appears on the screen.
So far I tried it with a case structure but I do not know how to compare the old value of the lower value with the new value from the front panel.
Can someone help me with this?
Thanks a lot!
12-15-2017 09:34 AM
comparing values from one iteration to the next is mostly done via shift registers
12-15-2017 03:12 PM
Christina,
This is not the first time you've heard this advice, but when you have a question like this, post the code that you tried to use. It is much easier to make a correction ("put the lower value in a Shift Register of a While Loop") than try (without knowing the structure of what you currently have) to describe how we might approach this problem ("Use a Producer/Consumer Pattern driven by a Lower Value Changed Event").
Bob Schor
12-16-2017 03:09 PM
@jwscs wrote:
While the shift registers piece here is a good example of what you'd want to do. I'd remove the Sequence Structure. On a non-deterministic OS relying on user input, you aren't gaining value looking at 200ms. If you remove the structure, you still slow the loop down giving the cpu free time. You also read the user input at essentially the same time. As the free time is purely for the sake of free time and not an attempt to time the loop, any value forcing the read to happen later is lost. We've just added complexity to the code, taken options away from the compiler, and gained nothing for our trouble.
12-16-2017 06:44 PM
i agree with you.
12-17-2017 10:52 AM
This is my code. I do understand your example, but I am not sure how to adapt it to my code. If I change the lower value of the range I want the whole process to start again.
Therefore, I do not know how to connect N, because it is not a constant and I do not know what my output of the shift register on the right side would be.
12-17-2017 11:51 AM
Christina,
The combination of your original Post that says what you want to do (but not in a way that I, for one, really understood what you meant) and the picture of your Block Diagram that you just posted have given me a better guess at what you want to do. See if I'm right:
You do not need a For loop, since (as you noted) there is nothing saying how many times you want to do something (maybe only once, maybe dozens of times). What you do need is a way to detect if the Threshold Range has been changed. Does the phrase "Value Changed?" mean anything to you? Do you know what an Event Structure is and does?
It seems to me that you want something like a Queued Message Handler driven by an Event Loop. The Initialize Message would take the initial Threshold Range and compute/save a Threshold. If Threshold Range changed, a "Range Changed" Message would do the same thing. You would also have a Front Panel Control called "Done" (you could use the Stop Button and change the Text to say "Done") that lets you exit from the Message Loop. This would do precisely what I think it is you want to do, namely process an Image as many times as you choose (by changing the Range), with the added proviso that you have to add a control to say when to stop.
There are numerous examples of the Queued Message Handler on the Web and in LabVIEW Examples.
Bob Schor