09-11-2020 10:49 AM
Hey guys, im working on a simple project where i have 2 analog liquid level sensors that each gives below zero volt when being down and above zero when being up and i want to control the water through a mini water pump with mydaq. I want the pump to open when both sensors are down and close when both are up. So i have a while loop for the whole project and a mini while loop in a case condition which the programm goes when both sensors are down. My problem is when the programm enters the mini while loop it can not read new values from the liquid level sensors inputs and as a result i cant get out of the mini loop when both sensors are up. Any suggestion?
Solved! Go to Solution.
09-11-2020 11:08 AM
Hi!
It would be much easier to figure out the problem, if you attach a vi or a block diagram screenshot.
09-11-2020 11:24 AM
iv made up three states that the sensors can be . when 1st state appears the programma enters in the case condition as shown in the second picture which has a while loop and i want to stop the condition-while loop as shown but the values are not updated when running it. You can replace the sensors with numeric controls
09-11-2020 11:44 AM
@Sam_Rudneff wrote:
Hi!
It would be much easier to figure out the problem, if you attach a vi or a block diagram screenshot.
A screenshot is practically useless. Attaching an actual vi is much preferred.
09-11-2020 12:01 PM - edited 09-11-2020 12:05 PM
Please attach your VI. truncated pictures are useless for us.
09-11-2020 12:08 PM
Rarely is there a need for a while loop inside a while loop. You need to restructure this into a proper state machine.
Some other glaring issues in the screenshot that you shared:
1. You are mixing orange and blue lines. If you add a number to an integer then use an integer. Also, there is a +1 primitive that you can use.
2. Never test equality of floats.
3. I see local variables, meaning that there could be race conditions associated with your program. Use wires instead.
4. Your inner while loop is blocking - learn about THINK DATAFLOW. This will lead you toward a state machine design.
There are probably other things - these were just a few glaring issues.
09-11-2020 03:59 PM - edited 09-11-2020 04:01 PM
Thank you for your reply, i took under consideration your words and i tried to make a simpler programm to understand my problem. I attached the vi here . This vi works fine the problem is that i have inside the inner loop local variables that comes straight from the input controllers. The case which stops the inner loop is similar with the variable : state_3. If you try to replace state_3 as local variables instead of remaking the state inside the inner loop the programm will not work.
My goal is when the programm enters the if case with state_1 to exit the case only when it reachs state_3 .
Moreover the inputs are reffered as upper and bottom sensor because im gonna take data through mydaq as shown in the 1st photo previously but since im working the project in the university i cannot take at home the mydaq board so i have to make 'iconic' inputs. Imagine that the sensors in this vi are simply liquid level sensors so the water goes up and down. Thats why i want to run the pump when both sensors are down until they both go up. but when they are already up i want the pump to run again only when they both go again down..etc etc
09-12-2020 01:07 PM
Please explain exactly how the VI is used, What you press and in what order, what you expect, and what happens instead.
09-12-2020 02:24 PM - edited 09-12-2020 02:25 PM
Why do you think that you need the inner loop? Just use the outer loop (you're really close to a state machine already). Then you won't have to use the value property nodes inside the loop.
Also, why do you convert the boolean to a number and then use >0 to convert it right back to a boolean? That's pure Rube-Goldberg. Use the boolean directly. You can use a NOT to get the same result as your <=0.
As altenbach mentioned you have blocking dialogs in your code. I suspect that you want the code to continue running. Consider just putting a message box on the screen instead.
Also, I noticed that you're using 3 second loop times. I would recommend dropping that. Users will become impatient with waiting 3 seconds after pressing a button to get a response.
09-12-2020 02:35 PM
@johntrich1971 wrote:
Also, why do you convert the boolean to a number and then use >0 to convert it right back to a boolean? That's pure Rube-Goldberg. Use the boolean directly. You can use a NOT to get the same result as your <=0.
Even simpler. 4 booleans can have exactly four conditions, so just do lookup tables, e.g. as follows. No need to overthink this ;):