LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

action engine/array question

Solved!
Go to solution
Im sure there is an easily corrected mistake I'm making. I am going to be making an action engine where I need elements added to an array, and after the array is full, toss away old data and add the new data. If someone can tell me why this array is continuing to be all zeros i'd appreciate it. Probably misuse or misunderstanding of one of the array functions. If someone could put a photo of the corrected VI rather than attach the actual VI it I'd appreciate it as I wont be on a computer with Labview until Monday. Thanks.
0 Kudos
Message 1 of 10
(4,043 Views)
Solution
Accepted by topic author GregFreeman

One problem is that you are inserting into a position that keeps incrementing with every loop.  So you have a 15 element array, but wind up inserting into position 16, 17, 18, ......  Those are undefined positions.  If you are doing something where you are inserting the new element at the top of the array, then you should always insert at position 0.  If you are always wanting to put at the end, you should append to the end of the array and take a subset of the array from index 1 for the length of 15.

 

The real problem you never see anything but zeroes is that the wire going into the right shift register is the same as the one coming out the left.  The changes you make by inserting into the array and taking the subset disappear on each iteration of the action engine and never make it to the array indicator

Message 2 of 10
(4,035 Views)

K thanks. Yes, I hadn't put a stop for the case where it reaches the array size that was initialized but I will. And quite a dumb mistake with the shift register :(. Basically what I want it to do is initialize an array of zeros. Lets say  [0 0 0 0 0]. Each time it loops i want it to put a number into the array.

I.E. [num, 0 0 0 0] .........second iteration [num, num2, 0, 0, 0] , etc.

However, I want to then take a sub array and only plot that point so the zeros arent plotted.

so for the first iteration plot(x,num) second iteration plot (x,num) and (x,num2)

for the n iteration plot (x,num), (x,num 2)... (x,num n).

 

A quick modifcation to my codeso it works would be appreciated. I'm pretty sure I'm using the correct functions, but yes that shift register will cause problems as I amnot returning the array after the new value has been added...woops :smileysurprised:

0 Kudos
Message 3 of 10
(4,032 Views)

Ravens Fan wrote:

One problem is that you are inserting into a position that keeps incrementing with every loop.  So you have a 15 element array, but wind up inserting into position 16, 17, 18, ......  Those are undefined positions.  If you are doing something where you are inserting the new element at the top of the array, then you should always insert at position 0.  If you are always wanting to put at the end, you should append to the end of the array and take a subset of the array from index 1 for the length of 15.

 

The real problem you never see anything but zeroes is that the wire going into the right shift register is the same as the one coming out the left.  The changes you make by inserting into the array and taking the subset disappear on each iteration of the action engine and never make it to the array indicator


Thanks as always ravens...thats all it took was moving the wire now ill just fix the other stuff so it doesn't try and fill an array with dimensions larger than what was initialized!

0 Kudos
Message 4 of 10
(4,031 Views)

Could someone take a quick look at this. I fixed everything except the first 15 times it loops for an array of size 15 it fills liek I want it to. Then it gives me zeros for the next 15 iterations. After 30 iterations it starts doing waht I want it to. Why does it give me zeros for that period of time?

Again, im tossing away the oldest value and adding the newest one to the end of the array. 

0 Kudos
Message 5 of 10
(3,998 Views)

Some general pointers to make your VI more robust.

 

  • Initialize your data with NaN
  • Make the size of your array dynamic, add a terminal with size (default 15) and read this in the init state
  • Don't use split and build array in a sequence. you should replace the 0'th element and then rotate the array by '-1' 
  • There is some logic flaw in the 'true' case that builds your array to 30 elements, if you use the technique from the previous point you will have no iteration checking any more.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 6 of 10
(3,991 Views)

The problem is that before 15 elements, you are inserting into a position on the array which pushes all the zeroes down and grows the array to 30 elements, your 15 with numbers and the original 15 zeroes after it.  Once you have 15 inserted, you are using split array.  This eliminates the 1 off the top, but 29 remain.  Array subset beginning at 1 and for 15 elements would be better.

 

See attached.

Message 7 of 10
(3,990 Views)
That will work! thanks guys for the advice.
0 Kudos
Message 8 of 10
(3,979 Views)
If you could just take a last look at this and make any more comments I'd appreciate it. I'm trying to learn how to do this stuff as efficiently as possible the first time so I don't have to backtrack/relearn. I'll take advice on anything, except tunnel and wiring as I think I can fix that myself. I'm more worried about the actual coding. And yes, I am aware my front panels aren't organized 🙂
Message Edited by for(imstuck) on 01-22-2009 02:59 PM
Download All
0 Kudos
Message 9 of 10
(3,917 Views)

Using Build.Array is a bad thing if you are worried about performance. Replace Element is much better.

Remove the 'Default' from the Case selector box for Initialize, if you add a state to the Enum (average for instance) your code will break and you know you have to edit something.

Replace the enum with a Type-def.

You have two controls with the same name (Temperature B), rename them to 'Temperature in' and Tempererature out'.

 

Why is the 'Write' action in the Action engine? You don't use any of the buffer data.

Rename the enum to Action. Make the control required on the connector pane.

Use less input/output terminals. I would create an action engine for every array one.

Feed the pointer counter directly to the case struecture. make 0..4999 case and a default case.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 10 of 10
(3,908 Views)