11-18-2008 10:12 AM
Hello,
I am recording position data on particular events. I want to store these position values in an array.
I am trying to store these values in an array one after another. I want the pointer to the array to automatically increment after the previous position value starting from 1 has been written to the array.
How do you automatically increment the pointer?
11-18-2008 10:51 AM
11-18-2008 11:46 AM - edited 11-18-2008 11:47 AM
Let's assume you are doing this in a FOR loop.
If you only need the array after all points have been recorded, you can create the array by autoindexing at the right loop boundary. You'll get one element per iteration in the order they are generated.
If you need to have access to the array data while the loop is still executing, you can built it in a shift register initialized with an empty array.
If the array is large, you should initialize the shift register with the correctly sized array and then replace values as they are generated using "replace array subset" with the index wired to the iteration terminal. This will avoid memory allocation overhead.
Once we see your code, we can give more specific advice. 🙂
11-19-2008 03:13 AM
I have attached a jpeg file with the code I am trying to do.
Position Feedback is the data which I want to record in an array everytime the Detection Trigger is true for the case structure
I have initialized the array outside the case structure and want to increment the array pointer everytime the detection trigger is true so that position data is saved sequentially in the array.
11-19-2008 03:54 AM - edited 11-19-2008 03:56 AM
See image for some ideas.

11-19-2008 04:32 AM
The problem is that the feedback node is only availiable for for /while loops.
I am using a case statement in which I want to record the position feedback only when the trigger is activated.
So do I use this code which u gave inside a for loop which is inside a case statement?
i.e for loop in a case statement
11-19-2008 10:56 AM
SInce LabVIEW 8.5 (?), a feedback node can be standalone and globally initialized. If you have a FOR loop you can place the shift register or feedback node in the loop. Built the array in one case and wire it across the other case of the case structure so nothing happens.
Why don't you attach a simplified version of your code so we can see what you're doing. It is difficult to guess from words alone. 🙂
11-20-2008 02:37 AM
Hello altenbach,
Your previous advice was crucial. But I now have a new problem of initializing the feedback node everytime so that previous values in feedback node are not used in the VI when VI is stopped and runs again.
I am attaching my code VI here. It would be useful if you could have a look at the while loop at the bottom.
I am also attaching a picture which shows that part of the code.
It will be useful if you could also inform me about displaying pictures in the messages that we post here.
Regards.
11-20-2008 03:26 AM - edited 11-20-2008 03:28 AM
OK, you have a lot of work to do on this, because there are glaring mistakes. First of all, your inner FOR loop has no purpose, delete it. Use a shift register on the while loop and initiaize it with an empty array. Built the array in one case and wire it across the other case This should take care of the problem.
Now, let's talk race conditions!
Your biggest mistake is overuse of local variables, in this particular case you get the "Position feedback" into an indicator and read from a local variable of it in two different places. Most likely, the reading from the local variables in the midlde loop happens before the new value is written to the terminal, causing unpredictable code. Since the terminal is right there, you should use a wire. This ensures that the data is consistent.
Similarly, and probably even more important, the same applies to the "detection trigger". Use a wire!!!
The attached image show the middle while loop with some of the ideas implemented. Let me know if anything is not clear.

Some additional points (there are many more) you might want to look into:
11-20-2008 04:20 AM
Hello altenbach,
Thank you for your prompt reply. It would be worthwhile to mention that I am using Labview 8.2.
I tried out your code (in the picture) and removed the feedback node from build array. I also removed the for loop.
But the problem in this case seems to be that the positions, which I want to acquire at every true case (trigger), are overwritten at the same first index of the array built.
I want to acquire all the true case positions and store them in the array. Whenever the case turns true, the previous position value in the array is overwritten by the new value.
It would also be important for you to know about the top for loop with the event structure, which seemed complicated.
This for loop is used to send motor commands and the middle while loop (the one in the picture which you showed) is used to continuously gather data packets from the controller for monitoring. The event structure is used to disconnect motor in case of emergency.
So whenever the middle while loop runs to continuously gather data packets, it seems that the build array is initialized once again to 0. Hence the old value of position is erased and new one just overwrites it.