LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop with shift register

Solved!
Go to solution

Hi all,

 

First I want to say that I appreciate all the help people get here!

So this week I posted this thread about doing several live edits on a graph:

https://forums.ni.com/t5/LabVIEW/Live-editing-multiple-graphs/m-p/3662802#M1029428

I've made two subVI's for the functions I need: a VI for calculating the max, min, avg, and mean of the array, and a VI to clip data in the graph. The problem I encounter is this: I need to be able to do both SubVI's live. So when I clipped some data, I want it to recalculate it's max, min, avg and mean. So I need them both in a while loop. However, the max, min, avg, and mean function doesn't work with a shift register, it keeps updating the data in some way I don't really understand (Some explanation would be appreciated 😉 ). The clipping function does need the shift register, because I want my program to remember the things I've clipped. I've thought about doing a while loop in a while loop but when I looked into that, it seemed that it isn't a good option.

On another note, I would like an undo option for the clipping function, but I have no idea where to start. So maybe some tips to get me started would be nice. 

I've attached the main program (sorry if it's a bit messy), the subVI's, and the file I read.

 

Thanks a lot in advance!!

LvL

 

0 Kudos
Message 1 of 20
(5,612 Views)

Hi LvL,

 

However, the max, min, avg, and mean function doesn't work with a shift register, it keeps updating the data in some way I don't really understand

There is a shift register inside! It's hidden in the PtByPt-Mean function…

With each call of this subVI you are recalculating the averages and so changing the data between in/out of that subVI!

 

I would like an undo option for the clipping function, but I have no idea where to start.

You could start by looking how other tools implement such an UNDO feature.

Most often they keep a history of the actions done…

 

Btw. next time please ZIP your files. Much easier for you to upload one file and for us to download one file…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 20
(5,602 Views)

Hi,

Thanks for the input. Sorry for the late reply, I was away for the weekend.

So I've deleted the shift registers in the mean subVI, but now it doesn't show data at all. When I run it and highlight the execution I see that it gets stuck at the mean subVI. What am I doing wrong?

I'll zip my files next time!

0 Kudos
Message 3 of 20
(5,523 Views)

Hi LvL,

 

So I've deleted the shift registers in the mean subVI, but now it doesn't show data at all.

I hope you don't have edited a functions supplied by NI in the vi.lib…

 

When I run it and highlight the execution I see that it gets stuck at the mean subVI.

Ok. And for what reason?

 

What am I doing wrong?

You did not attach the current state of your VI(s)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 20
(5,521 Views)

Sorry, here it is.

I honestly have no idea why it gets stuck 😕

the program is also running very slow, so I guess It would be better to use a while loop somewhere? Since the max, min, avg and mean is the same program for every array of data should it be implemented there? 

0 Kudos
Message 5 of 20
(5,517 Views)

Hi LvL,

 

I honestly have no idea why it gets stuck

It gets stuck because you have replaced shift registers by tunnels! You should have seen this instantly by using highlight execution mode!

 

How should those while loop replace NaNs/ZEROs in your array when they aren't allowed to store their work in a shift register?

Btw. why did you remove those shift registers at all? I didn't recommended to do so…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 20
(5,514 Views)

I thought you implied to remove them, so that was a misunderstanding from my side.

So now I'm back to where I was, it keeps updating the data. How can I stop the program from doing that?

0 Kudos
Message 7 of 20
(5,509 Views)

Hi LvL,

 

it keeps updating the data. How can I stop the program from doing that?

You need to prevent to call the averaging loop again and again…

 

As you (seem to) most things here driven by user interaction (press a button, load a file, do some filtering, set parameters for filtering) I strongly recommend to use an event structure and implement an event-driven algorithm! (Like IF event "xyz" THEN do task "xyz"…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 20
(5,506 Views)

The problem is, I need to re-calculate the max, min, avg and mean every time the user deletes a part of the data, because when there are parts that are deleted, the max, min, avg and mean obviously change. So it seems to me that it is necessary to recall that function, and keep it in the while loop. Is it an option to switch the order of the functions? So the clipping function comes first and the mean etc function comes second? 

Yes, there is a lot of user interaction. The raw data needs to be edited because there can be faulty data points in there, like extreme high or low peaks. Those have to be taken out. Also the amount of measurements can differ from 4 to 32 (so when the program eventually works I need to scale it up to handle 32 arrays), and the distance between the measurements can differ for every new set of measurements.

I will look into the event structure, thanks for the tip!

0 Kudos
Message 9 of 20
(5,503 Views)

Hi LvL,

 

I need to re-calculate the max, min, avg and mean every time the user deletes a part of the data

That's what I wrote: your VI should react (only) on user input: use an event structure and implement an event-driven algorithm!

 

Right now it loops at 8Hz iteration rate - even when there is no user action at all…

Best regards,
GerdW


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