LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run while loop again or interrupt it's execution?

Hello I have following problem. I use queued state machine for DAQ and other user operations. Than I have consumer loop that takes care about processing of acquired data passed via another queue. The thing is that I need third loop for independent controlling of ESP motion controller that runs as fast as possible.
I can write program that makes the motion path for servo motors controlled by ESP (simple program that demonstrates the movement attached). But I can write it using two for loops or two while loops. It can run only once and I can’t interrupt it, stop it or run it again. How to write the third loop that starts, runs and then stops when done or when user (probably in the main queued state machine) decides? And then when user decides to start it again...

I attach the simple program that demonstrates the movement of the ESP controller. It’s kind of zig-zag move.

Has anybody any idea? I was again thinking about state machine that starts when the start command is obtained from the main queued state machine ….but I don’t know how to implement the movement states because it consist of one loop inside the other.

Can somebody help me?

Message Edited by ceties on 03-20-2007 07:06 PM

LV 2011, Win7
0 Kudos
Message 1 of 4
(3,100 Views)

Hello Cetis,

Thank you for your question!

1. If you need to stop a process at any time, it is better to implement a while loop with a stop button as opposed to a for loop. You can still keep track of the number of iteration and stop the loop when you reach a certain count number.

2. To go back to the same piece of code in your program as many times as you want, you need to implement that piece of code as one of the states of a state machine. You mentioned that you want to have that code run in a third loop. This means that you have to create one more state machine and put your code there. It was not very clear whether the third loop is dependent on any data from the other two loops or it will run completely independent. In either case make the appropriate adjustments.

Hope this helps!

Message Edited by Kalin T on 03-21-2007 03:08 PM

Kalin T.
Message 2 of 4
(3,072 Views)
The producer/consumer architecture can be extended to multiple loops. I often use 3-loop systems. One loop handles the user interface and usually contains an event structure (GUI Loop). Another loop does the data acquisition or hardware I/O (DAQ Loop) and the third does the calculations and logic to control everything (Process Loop). Pairs of queues exchange commands, status, and data between pairs of loops. Not every pair of loops needs to be connected. The GUI Loop only talks to the Process Loop. The Process Loop talks to both the GUI and DAQ Loops. The GUI and DAQ Loops do not talk to each other.

For your case I would put the ESP controller in a separate loop. It would be a while loop state machine with Initialize, Idle, Run, Error, and Halt states as a minimum. When the program starts the Initialize state runs once. The loop then enters the idle state. When it receives a Run command from one of the other loops (via queue), it switches to Run. A Stop Motion command turns off the motor and returns to the Idle state. The Halt loop command stops the motor, exits the loop and sends a "Stopped" status message back to the main loop. You cannot restart the loop (easily) but since the Halt loop command is only issued when the overall program is shtting down this is not a problem. Use of the queue timeouts can provide suitable loop timing with immediate response to new commands.

Lynn
Message 3 of 4
(3,064 Views)
Thank you both, guys! I will use your advices and in case some problems appear I will ask again. Thanks a lot!
LV 2011, Win7
0 Kudos
Message 4 of 4
(3,045 Views)