LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HOW TO CREATE A STOP CONTROL IN FOR LOOP

Solved!
Go to solution

I have a problem. I can't put a check in the VI attached here. I want to stop iterating without pressing abort execution because i want to connect this VI to a sub VI to control a DC motor.

 

Thanks

0 Kudos
Message 1 of 8
(10,827 Views)

First, if you want to put a Stop control in your While loop (to get it to stop early), you can simply "OR" the value of the Boolean control with the other logic you are using.

 

If you want a Stop terminal to be added to your FOR loop, right-click the top edge of the FOR loop and check "Conditional Terminal".

 

Bob Schor

Message 2 of 8
(10,799 Views)

I try, but I can't do what I want. If i push abort execution, and then i start from the iteration 20 there is error 26 and seem that motor DC doesn't communicate with labview. If it possible you can change the VI to solve this problem? I would be truly grateful.

thanks

0 Kudos
Message 3 of 8
(10,775 Views)

Hi robbie89,

 

Take a look at "Simple State Machine LabVIEW". It will give you a much better sense of how your data is flowing than the stacked sequence structure you currently have. As it is, there is no way for us to run your program (we are missing many SubVIs) but it will make it a lot easier for you to debug and write code if you start off with a good architecture.

0 Kudos
Message 4 of 8
(10,751 Views)

Hey there Rob, think we need some better explaining on exactly what you want to achieve, but from looking at your code in general I can give you some general good advice:

 

-It is usually unadvisable to use the "waitms" function in large chunks of time (1000 ms and above) because it doesn't allow any other input until it's done, and if you want your code to stop on demand, it won't allow it. It's better to use it in tiny intervals (5-10ms) along with iteration counter.

-If the array containing data is a problem, you can use a "reset to default" from the "create invoke node" menu, to ensure you have an empty array every time you call the SubVi, regardless of it was empty to start with or not.

-If you require a for loop to stop, you can add a condition terminal that does exactly that, think it started in LabView 2011 and on.

 

Also, what are you using to control what kind of DC motor? If it's a small/school project, there's a rather excellent Arduino library available in VIPM that has all you need, including a lot of example code.

0 Kudos
Message 5 of 8
(10,740 Views)

Thanks for your advice. I use a DC motor controller to move a micrometer connected to a LASER  TEA. It is a school project. I want to move this laser for 60wavelenghts and it could happen that i have the necessity to stop the misuration to 20 wavelength. If i push the abort execution ends the communication with the software and I obliged to start from the first wavelenght.

0 Kudos
Message 6 of 8
(10,729 Views)

Oh I already get it, even if you still haven't told us what hardware you're using to implement the project, it sounds an awful lot like the constant issue that plagued my colleages when using the Arduino library. In a nutshell, when you hit the "abort execution" button, you tell LabView to immediately stop whatever it is doing, abort all running VIs and SubVIs and terminate execution of the program. This is of course, a very unclean method of program stopping as it leaves a lot of processes open.

 

What happened when using an Arduino was, the communication process stayed open and, when attempting to connect to Arduino again, it of course refused the connection, because it was already open and couldn't be used again. What you need to do is to use the programatical instruction to terminate/destroy connection (in the Arduino library it was simply called "close"). Place it outside your main loop and wire its reference from inside the loop, so it will always execute when your finish main loop. To stop the measuring simply use the afforementioned method of using small time intervals with iteration counters to allow a programatic stop, and avoid using the "terminate execution" button as much as possible, as it will certainly mean a full reset of hardware and Labview when you do it.

0 Kudos
Message 7 of 8
(10,711 Views)
Solution
Accepted by Robbie89

Hi,

in order to stop your first vi you could use a stop button for the while loop in 'or' with the output of your 'equal' comparison function. Then you can use also a local variable created on the stop button to stop the for loop, configuring it with a conditional term (right click on the for loop >> conditional term).

In this way if you press 'stop' you will stop the while loop and the foor loop together.

Bye

Message 8 of 8
(10,640 Views)