LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While Loop Won't Terminate

I am writing a code for a lego mindstrom on labview. There are two sensors on the front of the car: an ultrasonic sensor pointed downwards and a touch sensor with a piece pointing forwards. I am having problems with terminating the outermost loop of the nested while loops. The loop has no problem iterating, but doesn't terminate when the sensor is pushed. All the other while loops work fine. 

0 Kudos
Message 1 of 5
(2,392 Views)

If you run the VI by itself in a while loop with an indicator attached, do you see the output move between true and false as you press the button?

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 5
(2,383 Views)

I can check in a couple hours! But I'm almost certain the problem is the code and not the sensor, because I also wrote this code for the mindstorm to maneuver around a box of set length and width, once it "knocks" into it (the sensor is pushed). The push sensor is able to terminate the while loop in this code.

0 Kudos
Message 3 of 5
(2,368 Views)

Well the button press function has no data dependencies in the first VI you attached so it's hard to tell when it is actually reading the press. From the sounds of it, you might want to wire everything up so that you ensure the button is checked only after you exit the second while loop.

 

Instead of using nested while loops I would also suggest taking a look at the state machine pattern.

Matt J | National Instruments | CLA
0 Kudos
Message 4 of 5
(2,362 Views)
Message 5 of 5
(2,355 Views)