LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data Queue PtByPt VI

Solved!
Go to solution

Hello everyone,

 

I use Data Queue PtByPt VI to get a set of incoming data with the specific length for calculation. We can set the sample length in the input terminal, and there is a output terminal named "current length", I though it will return 1, 2, 3, ..., n, n, n,..., n, where n is the sample length. However, it keeps returning n, n, n,....

I don't know what is this terminal for. I hope the output is as the above, such as 1, 2, 3, ..., n, n, n....

Can you help me please? Thank you very much.

Capture0104.PNG

 

 

Qun

0 Kudos
Message 1 of 8
(3,872 Views)

Hi chalkwu,

 

I though it will return 1, 2, 3, ..., n, n, n,..., n, where n is the sample length. However, it keeps returning n, n, n,....

Let's read the LabVIEW help together:

current length is the size of the current queue.

Data Queue PtByPt Details: The data queue begins as a set of zeros that matches the size of sample length.

So you get what the LabVIEW help says you will get!

 

Can you help me please?

Help with what?

When you want to know the number of "real" data in your queue you could get the minimum of sample length and loop iteration count…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,840 Views)
Solution
Accepted by topic author chalkwu

I recommned looking at a lossy queue if you do not want to start with an array of 0's.  The queue size will increase everytime you add a new element up to the size of the queue.  Then they will drop off the end as new items are added.

CLA
0 Kudos
Message 3 of 8
(3,799 Views)

@chalkwu wrote:

 

Capture0104.PNG

 


Some general suggestions about comments about your coding style:

  • Simplify! Use "built array" to append an element to an existing 1D array. Your use of "insert into array" is much more complicated because you need to keep track of the insert point. (What do you do if you accidentally keep the program ruunning and the array grows forever and you run out fo memory?)
  • Since you are dividing by the number of samples, maybe "mean ptbypt" would be more direct. Much less code!!! (alternatively, you can make you own. Here is a simple example comparing the two. No need for coercions and extra shift registers). Also mind your representations. Counting should be done in blue.
  • Next time please attach an actual VI or snippet instead of a blurry picture.

 

Message 4 of 8
(3,766 Views)

Cat Happy        I can get your sense of humor. Thank you.

0 Kudos
Message 5 of 8
(3,750 Views)

Hello, 

Thanks for your reply.

I thought to use "build array" to store history data. However, it seems I need to intial the array and I don't know how to intial the array with an empty array. I can only do something like this, please see the attached vi.

Thanks for introducing me  "mean ptbypt". There are plenty of useful functions I could use in the future. But my problem here is that the difference have to be divided by increasing number, such as 1, 2, 3,.... until n, and n is the maximum length if I use "Lossy enqueue element". I think I can not use the "mean ptbypt" directly.

Next time, whenever I start a post here I will attach actual vi. I did not post real vi because I thought you can not run the code without some device in my lab. Now I realized that you guys do not need to run the code, If someone are willing to help me, they only need to read the code. Sorry for before.

 

Qun

0 Kudos
Message 6 of 8
(3,746 Views)
  • To initialize with an empty array, set the size to zero instead of 1. SImply change the blue diagram constant! 😄
  • You can configure the history size of mean ptbypt and once you wire your N, it will do exactly what you need. Have you tried?
  • To demonstrate a problem, the code should be simplfied for the forum. (Leave out all irrelevant stuff, replace acquired data with simulated data (e.g. random data as you just did!), etc.)
  • You might want to place a wait inside your loop. There is no reason to built an array with millions of elements within seconds.
0 Kudos
Message 7 of 8
(3,744 Views)

See the attached LLB which implements a rolling average using a lossy queue.  It may give you some ideas.  Top level VI is "Using Rolling Average.vi"

CLA
0 Kudos
Message 8 of 8
(3,712 Views)