LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array component not adding correctly

Solved!
Go to solution

Hi, I am running a program on myrio which i want to input the accelerometer values into an array and sum all the components up. I believe i had gotten the getting the values into array correctly, however, i cant seem to sum up the components correctly. can any experts help?

Download All
0 Kudos
Message 1 of 13
(3,702 Views)

Hi hrliew,

 

as long as you don't provide a formula for your summation I would suggest the easiest snippet possible here:

check.png

On your VI (image):

- You create a cluster of your accelerometer values, but no array…

- You create a 2D array containing just one element with your "Z axis" value"…

- What's the reason for using a FOR loop here?

- Cleaning up a VI before posting would be a good idea too…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(3,692 Views)

Hi, i have cleaned up the solutions and reattached the vi. I have used your suggestion of using the array function for summation, but the outcome is still the same. the 'summation' value kept flucuating, although the values are supposed to be increasing since I have added the absolute function to make all the values positive.

0 Kudos
Message 3 of 13
(3,640 Views)

You are subtracting the values from the last iteration from the current iteration, then summing them.  Depending on how different the data is from one iteration to the next will determine whether the result of the absolute value and summation will be higher or lower then the previous iteration.

 

Why are you turning the 1-D array into a 2-D array?

0 Kudos
Message 4 of 13
(3,633 Views)

Hey Gerd,

 

I think there is even a simpler and better solution to this than a build array and summation function. 

 

comp arithmetic.PNG

I think this must be more memory efficient as well (at least theoretically :)).

 

regards,
NitzZ

(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved :smileywink:)

0 Kudos
Message 5 of 13
(3,619 Views)
@ravensfan yup you are right about the subtraction of values from last iteration to current iteration, and I took all the individual products from each continuous subtraction and absolute them and store into an array. So I believe all the values that I stored into the array should be positive, so the summation of all the components in the array should always be increasing? But however, the summation shows a fluctuation pattern.

Did I changed it to a 2d array? Sorry, I'm really new to lab view and I thought what I did was just to store the values into the array.

@nitzz hi thanks for your input, if you look at the code, before I sum up whatever I wanted from the 3 signals x, y and z, I did a summation on each individual signal x,y and z. At the summation of each individual signal, it is where the error arises, and since it is only summation of 1 array, I shouldn't be able to use arithmetic adding?
0 Kudos
Message 6 of 13
(3,598 Views)

You are not storing the sum in the array, you are only storing the last iteration in the array.

 

If last iteration is 1 and this iteration is 2, the difference is 1, and you are storing 2 in the feedback node.

If the next iteration is 4, last iteration is 2 from the feedback node, the difference is 2, and you are storing 4 in the feedback node.

 

If the next iteration i s3, last iteration is 4 from the feedback node.  Difference is -1, absolute value is 1, but it is still less than the difference you had in the previous iteration.  Now you chart looks like 1, 2, 1.

 

Put indicators on your wires, or put probes on the wires and turn on highlight execution so you can see the data as it is flowing through your diagram.  It seems like you are looking for some other calculation (a running sum of the differences?) that is different from what you actually programmed.

0 Kudos
Message 7 of 13
(3,577 Views)

actually what you saying me wanting to get a running sum of differences (as components in the array) is correct. ok maybe i didnt phrase my issues carefully.

 

Cause what i want is to get inputs from all the x, y and z components (accelerometer) individually, and I would like to take a difference between current iteration (t) and the previous iteration (t-1).

 

Once i get the differences, i would like to absolute each differences found, and stored the values in the array_x, array_y and array_z.

 

Next, I would like to get the sum of all the components stored in the array.

 

Here is where the issue is, I cant seem to get the right summation value of the all values in array to display in the indicator, what i am getting are array values that are not being summed up (the running sum of differences).

 

and yeahh, your first sentence summed up exactly my issue!

 

Im really sorry if i didnt post my issue correctly!

0 Kudos
Message 8 of 13
(3,563 Views)

actually what you saying me wanting to get a running sum of differences (as components in the array) is correct. ok maybe i didnt phrase my issues carefully.

 

Cause what i want is to get inputs from all the x, y and z components (accelerometer) individually, and I would like to take a difference between current iteration (t) and the previous iteration (t-1).

 

Once i get the differences, i would like to absolute each differences found, and stored the values in the array_x, array_y and array_z.

 

Next, I would like to get the sum of all the components stored in the array.

 

Here is where the issue is, I cant seem to get the right summation value of the all values in array to display in the indicator, what i am getting are array values that are not being summed up (the running sum of differences).

 

and yeahh, your first sentence summed up exactly my issue!

 

Im really sorry if i didnt post my issue correctly!

0 Kudos
Message 9 of 13
(3,563 Views)

Well, a running sum of differences is the same thing as taking your current value and subtracting from it the initial value.

Message 10 of 13
(3,559 Views)