10-12-2023 05:27 PM
I am trying to find a way to exit a while loop when the value in a variable does not change for a certain time. Basically, I am looking at the current volume and target volume in a syringe. If the current volume is greater than the target volume in the syringe by a certain value x, the loop will continue. Unfortunately, the sensor on the syringe does not work consistently and sometimes stops at a reading greater than 'x' and stays there. I tried using a shift register to compare the current volume values and ending the while loop if the current volume has not changed and the target volume criterion has been met. But, sometimes, the loop ends after the first iteration since the current volume value does not update after the first iteration. I am trying to figure out a way where the loop will stop if the current volume value does not change for a set period of time.
Any help is greatly appreciated!
10-12-2023 05:59 PM
What about adding some logic to ignore the comparison on the first iteration, on top of what you have done?
10-12-2023 06:06 PM
It might not be for one iteration that the value remains the same. Ideally, I want to do the check after the current and target volume criteria are met. I tried using a feed back node with the delay set to 10 iterations, but it did not seem to work.
10-12-2023 06:22 PM
Using the shift register to compare values is the way to go.
You need to figure out when to start comparing the values.
10-12-2023 09:03 PM
Oh I see. I am trying to figure out how to start that particular condition check after the loop has run for some time.
10-13-2023 04:03 AM
Add a counter. If it's the same as before, add 1. If counter is > limit, stop.
10-13-2023 05:26 AM
10-13-2023 12:41 PM - edited 10-13-2023 12:45 PM
Typically we can provide much more specific advice once you attach your VI.
LabVIEW does not really have "variables", so I think you are talking about the value in a wire. What is the datatype? (i.e. what are the possible digital quantization steps). The term "does not change" is a very dangerous requirement for floating point values, a better definition would be that it "stays within a certain narrow range". How often is the value read? How much noise does it have?
If the signal is well behaved, you could feed your value into a ptbypt linear fit with the history length adjusted according to the sample rate and desired stability time, then do a simple ["value > target" AND "slope approximately zero"] to decide what's next. 😄
10-13-2023 03:37 PM
I tried this set up and it seems to work as of now. Thank you all for your inputs!