Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read spreadsheet for velocity setpoints using Velocity Control (Closed Loop)

Solved!
Go to solution

My VI is currently able to go through a series of velocity set points that are in a sort of array constant. I need to be able to go through a series of a couple hundred set points, and filling out the array constant everytime I have a new profile to test is not going to work out.

 

I tried using a Read from Spreadsheet block and Index Array to read in the values from a spreadsheet, but when I run the program, it does not seem to read the values in the file.

 

The pathing should be correct, but I'm not sure if maybe there's a formatting issue with the spreadsheet file with respect to the delimiter. Or maybe not all the parameters are met with the Read from Spreadsheet block.

 

Anyways, any help with my problem would be appreciated. I'll provide the VI as an attachment to this post. The nine setpoints that worked with the VI are in the blue array constant, which was before attached to where the To Long Integer block is now attached.

 

Brandon

0 Kudos
Message 1 of 10
(5,989 Views)

Hi Brandon,

 

Looking at your code it seems that you're only reading the value stored at index 0 of the array you're reading from file. In order to iterate through the array, pulling the next value in each loop iteration, you will need to enable indexing at the tunnel in question. This explains how this can be done in case you're not sure.

 

In case this is not what you're looking for, please post a sample text file to see if it has the proper format.

 

Hope this helps.

Tarek B
Applications Engineer
National Instruments
0 Kudos
Message 2 of 10
(5,980 Views)

I tried doing what you suggested, but it sadly didn't solve the issue.

 

I attached the test file I'm using.

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

Brandon,

 

The file format is correct and the output of the Read from Spreadsheet File VI is indeed an array. Now the reason it's not working is because you're indexing the array twice: you're using the Index Array function outside the loop then inside it. Since it's a one dimensional array, you cannot use it more than once, otherwise you will trying to access elements of an integer, which doesn't exist.

 

Let me know if this helps.

Tarek B
Applications Engineer
National Instruments
0 Kudos
Message 4 of 10
(5,956 Views)

Tarek,

 

I think I get what you're saying with regards to indexing twice, but I'm not sure how to apply this to my vi.

 

I tried leaving the index array inside the loop, and deleting the one outside. On the Current Speed indicator on the Front panel of the vi, it quickly ran through the velocities, but the actuator didn't move, nor did it stay on any of the velocities for the duration that they are supposed to. If I leave the index array on the outside, and take out the one on the inside of the loop, the vi immediately stops after starting. Both these cases are with indexing enabled.

 

Brandon

0 Kudos
Message 5 of 10
(5,953 Views)

Indexing enabled and the Index Array function operate the same why, only difference is that you can control the index you're accessing in the former while the latter imposes that you go through the array in order.

 

So if you have an Index Array function inside the loop, you do not need to have indexing enabled.

 

You should note that the array you're obtaining from the Read From Spreadsheet File is exactly equivalent to to the constant array you were using earlier. So the code that was working previously should work now.

Tarek B
Applications Engineer
National Instruments
0 Kudos
Message 6 of 10
(5,950 Views)

Tarek,

 

The array from Read From Spreadsheet is a 2D array of quad 64-bit integer while the constant array from before is a 1D array of long 32-bit integer.

 

Brandon

0 Kudos
Message 7 of 10
(5,933 Views)
Solution
Accepted by topic author PumpGuy

Hi Brandon,

 

That's correct, I take back my previous statement. I apologize about that.

 

I noticed that, in your code, you're selecting the row at index 0 instead of the first column. When you use the Index Array block outside the loop, make sure you're selecting the column at index 0 so you can grab the first column of the input file. This should get you the 1D array you're looking for.

Tarek B
Applications Engineer
National Instruments
0 Kudos
Message 8 of 10
(5,913 Views)

Hi Tarek,

 

For one reason or another, I was under the impression that you could only select the row and not the column. After reading the detailed help again, I did what you suggested, and now it works perfectly. Thank you for your help and patience with my problem. 

 

Brandon

0 Kudos
Message 9 of 10
(5,909 Views)

Glad I was able to help!

Tarek B
Applications Engineer
National Instruments
0 Kudos
Message 10 of 10
(5,907 Views)