LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

interrupt loop

Hello
 
I have a loop to drive a small car to different positions stored in an array. (see attachement).
First I give the command to drive to the desired position. Then I read the current position while the car is moving (inner loop). Then I adjust the position of the car and finally one can Input the distance to the car measured from a test instrument.
 
I'd like to have an emergency stop button that quits the loop immedialtely no matter where the program is (even if its in a subVI).
I tried different things but nothing worked. All the SubVI's run only if no error occured.
 
 
0 Kudos
Message 1 of 7
(3,367 Views)
Sounds as if you've done error-handling (great!!) - so it should not be a problem. Either you use the status-flag of the error-cluster to stop a loop (in addition to any other conditions) or you just wire the error-cluster as a loop condition. If so, you can select between continue on error or stop on error.
 
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 7
(3,362 Views)
hello becktho
 
That was also my idea to stop the loop with an error. The loop stops anyway if an error occured (see my attachment). But one loop can take up to a minute and when I press the stop button at the beginnig of the loop it will execute all subVI's first or am I wrong?
0 Kudos
Message 3 of 7
(3,356 Views)
Yes that's right. So you have to ensure that all subvis are stopped, if you push the button. You can use references, global variables and, I think, LV 2 style globals to make the value of your button available. To set the value, you should have another design because it is as you said - the button will be processed in the next iteration of the loop. You could use for example the producer consumer pattern or just a second while loop which sets a value according to the state of your button.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 7
(3,341 Views)

Thanks for the answer

Sorry, but I've no idea where to put a second Loop. Around or inside my loop doesnt make sense. And I dont get the use of putting it next to the loop like in the producer consumer pattern.

I could ask the state of the button after every subVI and generate an error if it is true. That would work but is a very stupid solution....

0 Kudos
Message 5 of 7
(3,339 Views)
One solution I could imagine for your code is using a reference. This should allow you to read the actual value of the button everywhere. Just pass a reference of the button to the subvis and use a property node in the subvis to read out the state of the button.
 
If you put a second loop in, the button can be processed in parallel execution to your main task. This allows you to set a value, which has to be read in your subvis to stop them.
 
I hope this makes it a bit clearer..
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 7
(3,334 Views)
Ahhh Smiley Very Happy
Didn't know that the second loop really runs parallel. That's very good because I found a good solution.
If stop button pressed, I sent an emergency stop to the motor. Taht also causes an error of the motorcontroller and if the programs gives a command to the motor, an error returns and the then  (thanks error handling) the program stops.
Thank you for your help.
 
0 Kudos
Message 7 of 7
(3,325 Views)