LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying slide position real-time in a 1D Array

Solved!
Go to solution

Hi!

I'm trying to create arrays when I don't know the size prior to creation. For the first step I'm trying to get the current position of a slider and put it to a 1D array. My problem is, that the while loop overwrites the first element of the array instead inserting the new value to the end of the array.

The diagram so far:

RT_position

0 Kudos
Message 1 of 10
(3,033 Views)

Right click on the tunnel between the slide control and the array and select enable indexing. Connect the output of the while loop directly to the array indicator (remove the build array fuction).

 

Ben64

0 Kudos
Message 2 of 10
(3,026 Views)

Short answer: Remove the "built array" node and make the inner output tunnel autoindexing. (but keep reading!)

 

Long answer: Still, this is very bad code, because you will run out of memory in seconds. Either use an inner FOR loop with a limited number of iterations or place a significant wait inside the inner loop. It is typically not a good idea to grow arrays indefinitely. What exactly are you trying to do?

0 Kudos
Message 3 of 10
(3,024 Views)

Still the first element of the array changes only.

My aim is to get the position of the slider to the array when I press the OK button. Kind of getting a "sample".

0 Kudos
Message 4 of 10
(3,022 Views)
Solution
Accepted by topic author PierreBatka

Actually, looking at your code once more, it seems you want to grow the array inside the outer loop. Place a shift regsiter on the outer loop and use "built array" with the upper connector coming from the left shift register and the lower connector coming from the slide. The output goes into the right shift register. Initialize the shift register with an empty array.

Use an event structure instead of the inner loop.

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

This is a part of a large project the final aim is to log the position of the moving part of an instrument in every x sec. The problem is that the logging will take as much time as necessary for the operator to solve a task, so I cannot say how long the array will be.

I am aware of the possible memory losses, still I don't have a better idea.

Basically I would be content if I could create any of the following:

1: Getting the position of the slider on button press, and writing it to the end of the array.

2: On button press get the position of the slider with a preset sampling frequency and putting it to the array, until the button is pressed again.

0 Kudos
Message 6 of 10
(3,010 Views)
Did you try my suggestion above?
0 Kudos
Message 7 of 10
(3,000 Views)

I did. It was an advance, so thank you, but I don't know if I can give any condition to the event structure (it should be active only if I switch the button from OFF to ON), and can I specify some kind of sampling frequency?

Anyway thank you for you help!

0 Kudos
Message 8 of 10
(2,994 Views)

 


PierreBatka wrote:

1: Getting the position of the slider on button press, and writing it to the end of the array.

2: On button press get the position of the slider with a preset sampling frequency and putting it to the array, until the button is pressed again.


Here's a quick example (LV 8.5) using "elapsed time". Modify as needed.

 

0 Kudos
Message 9 of 10
(2,981 Views)

Perfect. Thank you very much, I've learned a bunch of things about LabView.

0 Kudos
Message 10 of 10
(2,962 Views)