11-04-2024 09:34 AM
That basic idea (using decision logic in the consumer to "signal" to the producer whether or not to send data off to a file writing loop for storage) is a reasonable approach.
I would still recommend some attention to tidying up the wires and creating subvi's out of logical groupings of blocks of code. These things will help make the top-level logic and sequencing a lot more clear.
One very small suggestion for you to consider: it can sometimes be helpful to make use of "pipelining" in a PID loop. Right now, your loop is a little limited in speed because the output generation must happen *after* the data acq and calcs. With pipelining, you would write to the output task in parallel to the reads.
For all but the initial iteration, the behavior is virtually identical. Right now, after doing your data & calcs, you're writing to the output task as the last thing to do before iterating again. In "pipelining" mode, you'd send that calc'ed output value to a right-side shift register. That value would immediately come back out from the left-side shift register on the next iteration and you'd write to the output task as the *first* thing you do (and it would happen in parallel to your data acq reads rather than in series). This kind of thing can speed up the max possible PID loop rate for apps that need higher control bandwidth.
The remaining thing to do is decide what value to feed into the left-side shift register before starting the loop. 0V might be an appropriate default unless you have a method to determine a better starting value.
-Kevin P
11-06-2024 08:02 PM
I am running a separate while loop for my stepper motor control and have sequenced it such that once it has completed rotation by the desired value, it sends out a signal (using channel wire) to the producer loop, where my AI signal is read (for now, I have removed the CI task altogether). I was expecting the two loops to run in parallel so that the AI signal is read continuously. However, the producer loop only performs the first iteration and then waits for the signal from the channel wire - which it doesn't get unless the stepper sequence is run. So, while the stepper loop is running, the producer loop does not iterate anymore. Is this an expected behavior of the channel wires? If so, what would be an alternate method to send a signal to the producer loop to start processing/sending the acquired samples to the consumer loop?
Thanks,
lza
11-07-2024 10:49 AM
Following up:
I tested it on a simple setup with two parallel while loops, each generating a random number per second. The element from the first loop is additionally transferred to the other by placing the channel writer inside a case structure with a Boolean control. The second loop doesn't operate unless the channel wire is active.
If we place the writer outside of the case structure, then both loops run in parallel, and the data is transferred as expected.
How can I use the channel wire to send a signal on-demand while the other loop runs continuously? If this is not a suitable method, what might be a good alternative?
Thanks,
lza
11-07-2024 01:49 PM
TBH, I haven't really explored channel wires much at all and can't speak about them with any authority. Nevertheless, here are things I think, but beware that I may be mistaken.
There are different kinds of channels. A "stream channel" behaves a lot like a queue. That's the right kind of thing to use for delivering data from producer to consumer but is the *wrong* kind of thing to use for signaling from the consumer back to the producer. What you should use for the signaling is probably a "tag channel" which behaves more like a local variable. The channel reader will instantly retrieve the most-recently-written value without having to wait for anything new to be written, preventing your producer loop from getting stuck.
-Kevin P
11-08-2024 03:00 PM
@Kevin: Thank you for your suggestion. The 'tag' channel works fine for my test case. What I am trying to figure out now is how to control the number of samples sent from the producer loop to the consumer loop. In the attached VI, there are three while loops: a stepper control loop which sends a signal to the producer loop to start sending data to the consumer loop, which is where it is saved to files.
The stepper loop has multiple save periods and runs at a rate different from the producer loop. In this case, how can I send the desired number of samples to the consumer? For example, in the attached VI, the producer generates 10 data points every iteration. How can I save 1000 points to a file? I tried using time (High-Resolution Relative Seconds) as a reference and wanted the producer to send the data for 10 seconds, but that did not work. Is it more of a hit-and-trial to get the producer to write between two stepper loop signals?
Thanks,
lza