LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Formula Node and Array Calculations

Solved!
Go to solution

Hello,

 

I am trying to do calculations in the formula node with DBL data. The if statements, to filter the data are working fine. When is time to do calculations, which is the last formula node is not working well. The code supposed to do calculations when the value is different than zero but is not working well..

 

I have spotted the reason, which is the 10 samples per channel...So what the formula node does is: Doing the calculations (continues summation) for 10 elements, and then when it detects that is the 11th element, it starts the calculations again for the next 10 elements... without taking into consideration the previous calculations

 

I cant understand why is doing that...I need to have it continuously. For example continuous summation of 1000 elements, but after the filtering part..

 

I am attaching the VI for your reference.

Thank you in advance and any feedback is highly appreciated!

0 Kudos
Message 1 of 12
(2,379 Views)
Solution
Accepted by topic author Alexis_Koul

Hi Alexis,

 


@Alexis_Koul wrote:

Hello,

 

I am trying to do calculations in the formula node

 

I have spotted the reason, which is the 10 samples per channel...So what the formula node does is: Doing the calculations (continues summation) for 10 elements, and then when it detects that is the 11th element, it starts the calculations again for the next 10 elements... without taking into consideration the previous calculations

 

I cant understand why is doing that...I need to have it continuously. For example continuous summation of 1000 elements, but after the filtering part..


Why do you use formula nodes at all? Why not use pure plain LabVIEW/G code?

This is a very literal translation from your formula nodes to LabVIEW G code: you can join the content of both loops!

The variable "S_Time" isn't defined (or initialized) very well, according to your formula node it will be zero all the time!

Why do you need to calculate all elements when you only need the 2nd element as result???

 

When you want to "take into consideration" values from previous iterations you should use shift registers. This is pretty basic LabVIEW stuff!

When you "don't understand" shift registers: take the Training resources as offered in the header of the LabVIEW board!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(2,353 Views)

Dear GerW,

Thank you very much for your answer! As always very helpful!

 

The reason that I didnt you shift register is that the calculation is working but only for 10 data points. Will try what you sent!

Thanks again!

0 Kudos
Message 3 of 12
(2,337 Views)

Dear GerW,

Could you please explain me why the formula node is starting again the summation/calculation for 10 elements and initiate again in the 11th?

As I said in my initial message, I know that is because of the 10 samples per channel, so is this a limitation?

If I use Mathscript Node, may work better?

 

Appreciate your support..

0 Kudos
Message 4 of 12
(2,239 Views)

Hi Ale_is,

 


@Alexis_Koul wrote:

Could you please explain me why the formula node is starting again the summation/calculation for 10 elements and initiate again in the 11th?
As I said in my initial message, I know that is because of the 10 samples per channel, so is this a limitation?
If I use Mathscript Node, may work better?


There are 10 samples per channel, so in each iteration those 10 samples are processed.

But it doesn't matter if you use a FormulaNode or Mathscript: it's your programming if you use values from last iteration or not!

Learn to use shift registers when you need to forward values to the next iteration of a loop!

Best regards,
GerdW


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

Hello GerdW,

I apologize for writing your name wrong.

In what you have sent me, I added the following statement between. If the current value is equal to the previous, then to put 0, else to put the actual value.. But obviously I am doing something wrong, and even if the current with the previous value is equal, it takes the actual value.

 

Alexis_Koul_0-1612451300875.png

 

Would be great if you can give a feedback. As always I appreciate your help.

 

0 Kudos
Message 6 of 12
(2,221 Views)

Hi Alexis,

 


@Alexis_Koul wrote:

But obviously I am doing something wrong, and even if the current with the previous value is equal, it takes the actual value.


I see two three main problems with your image:

  • Most case structure tunnels are "default if unwired" and there are unwired cases.
  • Your shift registers aren't initialized.
  • You attached just an image of code, but not the code itself. How should we debug/edit an image with LabVIEW?

Minor problems:

  • Your block diagram should be cleaned up! No backward wires, no hidden wires, wires as straight as possible…
  • Comparing float values for equality is dangerous! It can give unexpected results, as has been explained in the forum quite often…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 12
(2,204 Views)

Dear GerdW,

Attached you can find the code. I initiated the shift register and also I changed the equality with a subtraction. So if the subtraction is less than a value, which should be actually 0, then it should be that it is zero else the actual value..... but still is not working...

I appreciate your support

0 Kudos
Message 8 of 12
(2,171 Views)

Hi Alexis,

 


@Alexis_Koul wrote:

I initiated the shift register…


There are still two uninitialized shift registers. And there are "default if unwired" tunnels…

 


@Alexis_Koul wrote:

I changed the equality with a subtraction. So if the subtraction is less than a value, which should be actually 0, then it should be that it is zero else the actual value..... but still is not working...


There is only one subtract node in the VI, and you don't compare with zero after this subtraction…

 

Can you set some typical values in the "data" array to default? (Edit -> set current values as default) Then save the VI and attach it again…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(2,169 Views)

Dear GerdW,

 

Thank you for your quick reply and support.

Attached find the VI with values. Please see the results from <<Array3>>. I dont compare with zero because it didnt work, so thats why I put a value of 0.5...so element 5 and 6 in Array 3 should be zero..

 

Thank you!

0 Kudos
Message 10 of 12
(2,166 Views)