04-07-2014 09:40 AM
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?
Solved! Go to Solution.
04-07-2014 09:59 AM - edited 04-07-2014 10:00 AM
Hi hrliew,
as long as you don't provide a formula for your summation I would suggest the easiest snippet possible here:
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…
04-07-2014 11:23 PM
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.
04-07-2014 11:49 PM
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?
04-08-2014 12:42 AM
Hey Gerd,
I think there is even a simpler and better solution to this than a build array and summation function.
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 )
04-08-2014 02:25 AM
04-08-2014 07:27 AM
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.
04-08-2014 09:01 AM
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!
04-08-2014 09:01 AM
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!
04-08-2014 09:15 AM
Well, a running sum of differences is the same thing as taking your current value and subtracting from it the initial value.