06-29-2015 10:29 AM
Hi,
I have posted previously trying to solve some of my programming problems. I am designing a VI that acquires data while a stepping motor moves. So far, I have an outer loop. In this outer loop, I am collecting data, writing it to a file and graphing it live. The condtion of this loop is: "if we are within 6 motor positions of the stop position, exit the loop and stop and graphing collecting data". This works fine. But I have since changed my program because I wanted to add a feature where I could stop the motor (and exit the loop, which also stopped data acquisition).
I previously had all my DAQ in a while loop with a condition on "Unbundle by name" and and extra stop button. The problem was that I was unable to collect data - the motor would only move once I was outside the inner loop.
A better question is: with my current program (attached in this post) what should I do to be able to collect data, plot it and also be able to stop (jump out of all loops at once, ending the movement and data processes)?
Thanks.
P.S. I have looked up producer/consumer architechture but I cannot figure out if I should use events or just while loops to exit. I tried putting my plotting process in a separate loop than my data acquisition process, but then I was unable to plot. From what I understand, I need to start the task "n" number of times in order to generate data points each time. If I keep the 'DAQ Start' in a loop, it only runs once and therefore is only able to read one data point. Is this correct? How else can I use producer/consumer in order to solve my problem?
S.
06-30-2015 05:28 PM
I would consider separating your stepper motor control code and your DAQ code into two different loops. You'll need to determine the best way to communicate between the various loops in your code (local variables, FGVs, queues, notifiers, etc.) The advantage of this design is that it allows you to maintain independence between the different aspects of your application. So, if you need to stop one task but not the other, doing so is very straightforward.
If the parallel loop data communication mechanisms are holding you up, I would recommend taking a look at one of the queue examples in the Example Finder, as queues are easy to setup and use, but can be very flexible.