LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building a 1D array from an analog signal – velocity measurements

Solved!
Go to solution

Good day,

 

Hopefully, somebody can help me to answer a fairly simple question. I perform velocity and acceleration measurements in the scan mode, using a cRIO 9068 and Special Digital configuration mode of an NI 9401 DI module. I have a quite noisy input signal from the utilised encoder, so I was planning to use some filters to get rid of the noise. However, by looking at the filters blocks, I realised that their inputs should be 1D arrays of doubles. Whereas the DI node output (velocity) is scalar.

 

After that, the most interesting part of the code started. Knowing filtering techniques, I could not figure out how to put all my scalar velocity readings into one 1D array. I remember about the standard example of generating an array with the use of a FOR loop. Trying to find the simplest and the fastest solution I have decided to use the same approach. However, without any success.

 

Since I use a single-cycle timed loop, I was planning to use the iteration indicator node to save the current velocity value (for this iteration) as the next value in the array. I was planning to achieve it by wiring the iteration number node to the FOR loop with the velocity node. And since I am posting it here, you can imagine that it did not really work out Smiley Indifferent Every single iteration I am getting a bigger array which is filled with the same value of the velocity. Tried to overcome this problem with the use of the “Insert into array” and shift registers to pass the current value of the velocity into the array. But the output does not give me a proper measurement sequence as well.

 

Either I over complicate this task, or I definitely miss something in the thinking process for the conversion. Are there any suggestions for tackling this code? Any help will be highly appreciated.

array_question.JPG

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

Hi ESturov,

 

can help me to answer a fairly simple question.

Sure.

 

I could not figure out how to put all my scalar velocity readings into one 1D array.

Read the input in a loop, create an array using an autoindexing output tunnel.

Simple, basic LabVIEW stuff. You shold know that from going through the beginner courses offered for free!

 

Since I use a single-cycle timed loop

- You set the loop to iterate at 1MHz clockrate with a delay of 1µs. Why? You are using the ScanEngine on your cRIO - and so you are limited to ~1kHz sample rate!

- Additionally you put a WAIT function inside the TWL!? Why do you wanted to use a TWL then???

- In this TWL you still put a FOR loop? Set to just one (1) iteration!? To create an array from your local variable??? Using a BIG RACE CONDITION??? And why do you need to write a value to a terminal AND a local variable of this very terminal???

I already mentioned the basic LabVIEW tutorials: did you take them? Did you learn to THINK DATAFLOW???

 

Either I over complicate this task, or I definitely miss something in the thinking process for the conversion.

Both is true… 😞

Suggestion: take the beginner tutorials and THINK DATAFLOW.

 

This should remain after doing the things learned in the beginner courses:

check.png

Remember: it's not the best solution to create an autoindexing tunnel for a WHILE loop. It's even more bad on a cRIO RT system…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(5,777 Views)

GerdW,

 

As always my pleasure to see you here.

 

I could not figure out how to put all my scalar velocity readings into one 1D array.

Read the input in a loop, create an array using an autoindexing output tunnel.

Yep. Exactly what I was trying to do before. 

 

Since I use a single-cycle timed loop and other questions.

Probably smth that is not included into the beginner course. But i think a good read for those who is interested. 

http://www.ni.com/white-paper/7338/en/

http://zone.ni.com/reference/en-XX/help/372603F-01/riohelprt/quad_rt/

With regards to other questions, my real set up is different from the code that I posted. But it does not change the main question...

 

Suggestion: take the beginner tutorials and THINK DATAFLOW.

Do you know that according to dataflow, this array will show zeros? Because there is no data being transferred outside of the loop during its execution. The standard trick with local variables won't help as well, since I am looking for an auto-indexed tunnel (hence there will be no second while loop that handle the array being updated).

 

Remember: it's not the best solution to create an autoindexing tunnel for a WHILE loop. It's even more bad on a cRIO RT system…

So what is it the best solution for RT systems? Or it is in the beginner course as well?

 

As always, thank you for your time.

 

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

@ESturov wrote:

 

array_question.JPG


There are plenty of things wrong with your code, for example why would you place a wait inside a timed loop? In the above image, you are only reading a scalar and pushing it into a local variable once per iteration of the outer loop. Now you are building an array with all identical elements, and with the size corresponding to the iteration could of the outer loop. What a duplication of effort!

 

Writing to a terminal and to a local variable of that same terminal in parallel shows a basic misunderstanding of local variables, dataflow, and LabVIEW in general. I strongly urge you to go over the tutorials once more.

 

Sorry, I don't have RT/FPGA installed here but I assume that this is running on the RT, not on the FPGA, so "single cycle" makes no sense. For filtering a scalar, you could use one of the ptbypt filters, which automatically operate on the last N points. To build an array in a loop, you would use a shift register as in the picture below, but that seems not right here either. If the stop condition is never met, it will grow without limit. This is just a general comment, not really applicable here.

 

BuildingArray.png

 

0 Kudos
Message 4 of 10
(5,744 Views)

Hi ESturov,

 

Yep. Exactly what I was trying to do before. 

No, wrong.

You didn't read from an input in your (FOR) loop, but from a local variable. And even worse: the corresponding terminal of that local variable was only written to once outside that FOR loop…

Again: THINK DATAFLOW!

 

Do you know that according to dataflow, this array will show zeros?

No, never heard of such behaviour.

With dataflow you will get exactly the data at the data sink which where flowing from the data source! How should there be zeros in between?

 

Because there is no data being transferred outside of the loop during its execution.

You didn't mention you want/need to transfer data out of your loop during loop execution…

Doing the beginner courses you should have heard of notifiers, queues and similr stuff!

 

The standard trick with local variables won't help as well,

Which "standard trick"? Local variables will help you in just ONE special case: when you need to set values in a control…

 

since I am looking for an auto-indexed tunnel (hence there will be no second while loop that handle the array being updated).

I have shown how to use an autoindexing tunnel…

Before you said, you want to transfer data to a second loop, now there is no second loop??? Please be clear with your descriptions!

 

So what is it the best solution for RT systems? Or it is in the beginner course as well?

On RT systems you should not use arrays of variable length - every call of the memory manager will hurt the RT performance. On RT systems you should work with arrays of fixed length: the usual InitArray before a loop with ReplaceArraySubset in the loop (which also is shown in the beginner courses).

And yes, you should of course also take the beginner courses for cRIO!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(5,732 Views)

Hi GerdW,

 

On RT systems you should not use arrays of variable length - every call of the memory manager will hurt the RT performance. On RT systems you should work with arrays of fixed length: the usual InitArray before a loop with ReplaceArraySubset in the loop (which also is shown in the beginner courses).

 

I see the logic. However, just to be sure that we are on the same page. By the beginner courses do you mean Core 1/2/3 and others for RT and FPGA? http://www.ni.com/training/labview/

 

I completed them a couple of years ago. I am not planning to delete all my codes that have been designed since then 🙂 Because apparently I need to take these courses again.

 

But the real question is, where this array approach is shown in these courses? I've checked now and did not find this example/explanation. Could you please guide and show me which one of the beginner courses has this information? Will be more than happy to educate myself more. Meanwhile it will help to avoid similar questions in future. Thank you in advance.

0 Kudos
Message 6 of 10
(5,717 Views)

Hi ESturov,

 

I can recommend the example finder in LabVIEW. Under "basics" you will find several example VIs explaining how to use arrays. One of them is called "Separate Array Values", which shows how to use InitArray, ShiftRegisters and building arrays inside a loop. (It's not ideally suited for RT, but shows the basic principle.)

For cRIO there are several courses offered, see here.

There used to be a good tutorial for cRIO beginners, but can't find that at the moment… (I guess due to massive restructuring of NI's website in the last two years.)

I also started with this one.

 

I am not planning to delete all my codes that have been designed since then 🙂

Why not? (Well, I mean "improve" instead of "delete".)

Most of my "basic" subroutines are located in a huge user.lib folder. When I learn about new/better algorithms I can implement them once in the user.lib and all software projects can easily use the new algorithm…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(5,708 Views)

GerdW,

 

Sorry for the late response. Are you sure that we are talking about the same example? The file that you specified shows this:

Capture.PNG

Checking after other codes I did not see (or maybe missed it) the example similar to what you have told me. Could you please guide me which one will suit the issue? I see the point how to build an array based on your description, but I still could not make it work in the best way. Thank you and have a great weekend.

0 Kudos
Message 8 of 10
(5,676 Views)
Solution
Accepted by ESturov

Hi ESturov,

 

Are you sure that we are talking about the same example? The file that you specified shows this:

No, they are not the same.

When I was suggesting the example I was working with LV2011 - which doesn't know about conditional tunnels and uses plain array functions…

 

I was referring to plain routines like this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 10
(5,671 Views)

Hi GerW,

 

Totally makes sense. Tested this routine for some time and it works perfectly fine. Thank you again for your help. Have a good one.

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