LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pause and restart while loop after defined time

Hello,

 

What I need is to find a way to run a while loop that is acquiring and analysing a movie, to pause this while loop for a time I specify, and re-run it after that time has passed.

I'm attaching a picture of the relevant parts of my VI. In the case structure of the "true" or "false", the program is checking, online, if the eye (my camera is focusing on the eye) is open above some threshold and for a certain duration of time. When "condition to start" is met, two things happen: one, the case structure changes to "false" and waits for some time; second, the loop of my state machine is triggered. Problem is, because I'm not really pausing my while loop (it's still running even when it's the "false" case), my state machine runs really slowly - for example, I have a part of video acquisition in my state machine, and saving the frames to avi takes forever. 

Does anyone have any idea of how I could stop the while loop for x time?

 

Thanks in advance!

 

 

help_pauseWhileLoop.png

0 Kudos
Message 1 of 7
(3,916 Views)

First, your picture is not very useful as the resolution is not very good.

 

Secondly, I suggest that you investigate using parallel tasks to solve your problem. At a minimum do the frame saving in a loop on its own. You may also decide to do the capture there as well. Look at a producer/consumer architecture. In addition, express VIs tend to be very inefficient. You may find that if you write the code yourself you will get better performance.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 7
(3,910 Views)

The simple solution is to add a Wait, but the program might be unresponsive with that solution. 🙂

 

Calculate the time in ms it'll pause and use tick(ms).

 

Which solution you use, remember to have a small wait (10ms?) so you dont starve the cpu with a crazy loop when polling/waiting. 

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 7
(3,881 Views)

Hi,

 

I'm attaching (hopefully) better pics, if you still can't see let me know and I'll attach the code. About the frame saving and acquistion, I'm already doing that in a separate loop - you can't see my entire code in the pics, but what I have is a state machine that works as a producer loop and then a consumer loop, where video acquisition is happening. Now I'm working on a third loop (the one in the picture), that starts before the others and where I don't even want to save the movies - I just want it to check, online, if the condition is met (e g, the eye is open for a specified time) and if so, start the state machine and stop running, until the state machine has finished running. Then do the same, after waiting a specified time. I know that the problem is that the while loop keeps running after triggering the state machine, because if I remove that part and trigger it manually, the VI runs just fine and really fast. So how can I run, stop and restart the while loop?

 

 

 

 

 

 

Download All
0 Kudos
Message 4 of 7
(3,878 Views)

In the false case you Null the camera visa thus closing something completely different. Pass the wire through. The upper boolean will become False as it'll default, is that what you want?

 

Also, add a small Wait in the false case, 10ms whould be good. 

 

Can you post the VI instead of pictures?

 

/Y 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 7
(3,867 Views)

Hi,

 

 

The VI is attached. I passed the wire through but for some reason when I run the VI, it starts with the false case, counts 10s and stops. What I want is for it to count 10s, go to true, run until "condition to start" is true, trigger the state machine and while leaving the state machine running, go to false and stop running for 10 secs. And restart.

0 Kudos
Message 6 of 7
(3,861 Views)

Hello,

 

Just an update: I made a small change to my VI and now it counts 10secs, goes to "true", does the online analysis until "condition to start" is true, triggers the state machine that does the video acquisition really fast while it goes to "false", where the online analysis is STOPPED for 10secs. But then nothing happens. So all I'm missing now is to find a way to make it run again the "true" case. I don't really understand why it isn't doing that, since after 10secs are elapsed the boolean "Time has elapsed" turns true, so it should chose the right case.

 

 

 

 

update.png

0 Kudos
Message 7 of 7
(3,845 Views)