LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lossy Enqueue Setup

Solved!
Go to solution

So, this seems like a simple problem, but I couldn't find anything that really helped me by searching these forums. I apologize if this is a redundant question.

 

Right now I have an X and a Y coordinate that are varying and I'm hoping to find a rolling average of each. I've been trying to use a queue to find this average, but when I attempt to flush the queue, I end up with an array of one value. For some reason, the queue doesn't seem to be populating correctly. What am I doing wrong?

 

I've attached a picture of my code. Also, I'm using LV2009. Thanks Smiley Happy 

0 Kudos
Message 1 of 4
(2,872 Views)
Solution
Accepted by topic author GoldenBoy

You are queueing one value and then immediately after you are flushing the queue, which is now empty for the next loop iteration.  You will never have more than one element in the queue at one time.  So how can you expect to get an array greater than one element when you flush?

 

If you want to keep a running average, use a shift register to hold an array of data.  Use Add Array Elements and divide by the Array Size.  Or use the Mean function.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 4
(2,862 Views)

Ok thanks. I was using Flush to get the data into an array for summation, but I guess I just overlooked the fact that it actually flushed the data in the queue with each iteration. I feel a bit like a fool, but I do appreciate the feedback, tbob.

 

I was thinking the queue method would be more efficient than the shift register/array method, but I suppose if it doesn't work, that's not very efficient...

 

Thanks again.

0 Kudos
Message 3 of 4
(2,839 Views)

Instead of a flush, you can use Get Queue Status to get the elements without deleting them.

Message 4 of 4
(2,835 Views)