04-05-2012 12:02 PM
hello,
I'm a neuroscience student and here's what I'm trying to do: 1) trigger a GigE camera (200fps), 2) start video acquisition, 3) trigger a light that will stay on for x miliseconds, 4) trigger a valve that will blow an air puff, 5) stop the tone and the valve simultaneously and 5) stop the video acquisition 1second after 4). For that, my VI is a state machine, with a state for each trigger (ex, 1 state for trigger camera, 1 state for trigger light, ect) plus a state to "stop" and a state "time to wait". Everything was working except the video acquisition - the program would trigger the camera but only acquire one frame, because it wasn't running in a while loop and this is my first question: for a video acquisition is it always necessary to have a while loop?
I assumed the answer was yes, so I built a "consumer" loop for the camera. Putting a queue in the state "trigger camera" in the producer loop, I was then able to start the video acquisition but now the problem is to stop it in the right time. I have another queue in the "stop" state in the producer loop, but it isn't able to start the "stop" state in the consumer loop, I think that may be because the consumer loop gets "stuck" in the while loop.
I hope you can help me, the VI is attached. Thanks!
Solved! Go to Solution.
04-09-2012 05:45 AM
Hi Albergaria,
I don't have Vision installed so can not open your code. But here is one suggestion, You are right about While loop. Your code gets stuck there..
To read stop command, you can read queue inside that while loop. Keep time out to few ms.
Else, one more option is to use Functional Global.
Let me know if this helps.
04-10-2012 07:08 AM
Hi Gak,
Thanks for the suggestions. I still didn't got it to work though. I moved the stop command to inside the while loop like you said but it didn't work. The problem seems to be in the communication between the producer/consumer loops. When I run the VI in highlight, the queue message "trigger camera" leaves the producer and arrives at the consumer loop in the appropriate time, starting the "trigger camera" state of the case structure. However, the message "stop" doesn't seem to be sent by the producer loop, so the consumer doesn't receive a signal to start the "stop" state of the case structure. Can you think of anything I should change in the producer loop so that the second state (stop) is added to the queue?
About the functional global, I read about it, it seems that either that or a local variable could work, but I don't quite know how to implement it in my state machine, since the stop of the first while loop isn't activated in the "stop" state but in the "shutdown" state. It works more or less like this: after 10 loops of triggering and stopping the camera, light and valve (so after acquiring 10 movies), it goes for shutdown. Can you show me what you had in mind with the functional variable?
04-11-2012 01:06 AM
Hi,
First of all, in your producer loop: IN "Stop" state, you are using flush queue function, then there is no need to use "Enqueue Element At Opposite End". You can use enqueue function.
Secondly, you said "I moved the stop command to inside the while loop like you said but it didn't work". But if you look carefully, you have moved "Enqueue function" inside while loop. Instead of that you should have used Dequeue function. Please look at the picture I posted neatly.
And remove encircled function(i.e.. Enqueue function in consumer loop, where I have written "Why Stop Here").
Now try.
04-12-2012 06:21 PM
Hey Gak,
Thanks for your help, everything's working now 🙂
cheers