From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you calculate accumulated displacement?

Hello! I would like to calculate the amount of displacment accumulated during a laboratory test using LVDT positions. Acquiring the signal and determining the position is no problem. However, I cannot think of an efficient way to sum the displacement measured by the LVDTs during the test period. From a progamming standpoint, I would simply save an initial value and subtract the current loop value to obtain the displacement. In the attached example I use a method which uses a case structure and a shift register, but it seems a bit brute force. Do you know of a more elegant way of doing this? If not, how do I tidy it up?

Download All
0 Kudos
Message 1 of 7
(2,848 Views)

It is not clear which signal you are trying to accumulate.  Do you want to accumulate the data in Avg. Position?  The shift register is useful and elegant  for accumulation. Your implementation does no accumulation - it just grabs a non-zero value and keeps it.

 

Another question: Do you want the algebraic sum of all the positions so that you end up with the net position or do you want the total distance travelled? The two are quite different.

 

Lynn

0 Kudos
Message 2 of 7
(2,837 Views)

Yep, that's right. I only use the shift register and case structure to store the initial value and then I determine the 'net' displacement each step. So, the code performs the action I intended. I'm simply curious if there is another way of doing this. How would you do it?

0 Kudos
Message 3 of 7
(2,765 Views)

The shift register and case structure is a good way to handle something like this. I would make a few minor changes.

 

1. Equality comparisons of floating point numbers can result in problems due to the finite representation of numeric values in binary. In this case you are probably OK but it is not a good habit. A better choice would be to compare the loop iteration count "i" to zero rather than the data in the shift register. Use the =0? primitive rather than =? and a zero constant.  If you need to compare to data, use In Range and Coerce with the limits set slightly above and below the actual threshold value. The limits might be ~ the peak to peak noise specification of the DAQ device for example.

2. What is the purpose of the Add zero?

3. You can expand the Index array to get both the first and second values from one function.

4. Eventually you should learn to use the DAQmx VIs directly and get away from the overhead associated with the DAQ Assistant. You could then select a DAQmx Read option to generate the arrays rather than the data format obscuring Dynamic Data Type.

5. You did not have any default values in the slope and intercept controls so I have no idea how much data you generate on each iteration. It seems a bit strange to have arrays of slope and intercept values applied to single data points.

6. Look into the Producer/Consumer archtecture. It puts the data acquisition in one loop and the write to file in a parallel loop. That way any delays from the OS in writing to the file do not cause problems for the program.

 

Lynn

Message 4 of 7
(2,745 Views)

Hi Lynn,

  Thanks for these great suggestions. The comparison and add zero issues are simple to resolve, I can see your point in both cases. I am only trying to generate one value each loop iteration, so I am also confused about the use of the arrays rather than single values. When I click the wiring input of a numeric operator and 'create control', that is what is automatically inserted. Is this what you're referring to when you suggest that I use the daqmx functions? So, I can have more control over the data type?

Evan

0 Kudos
Message 5 of 7
(2,718 Views)

Evan,

 

Create control will create arrays on Add or Multiply only if an array is wired to one of the other terminals. Did you have the array from DDT wired to the Multiply (without the Index Array) when you first created the slope and intercept controls?  If you do not want arrays, go to the front panel, delete the array controls, and drop scalar controls on their places. Then wire the terminals to the numeric functions on the block diagram. Everything should then be scalars.

 

It looks like the DAQ Assistant is set to acquire data from two channels at 1000 samples per second and to retrieve 100 samples on each call.

 

When you convert from DDT to 1D array of DBL you get only one of the two channels. The array should contain 100 points from the first channel. All of the data from the second channel is lost. You then index out the first and second elements of the array from the first channel.

 

I doubt that this is what you really wanted to do.

 

The DAQmx VIs will give your direct control over the datatypes and eliminate the extra overhead of the DAQ Assistant.

 

You should be able to configure the From DDT to allow you to select the channels. Double click to bring up the configuration dialog. You can select 2D array of scalars and then use Index Array to get the channel you want. Another option is to use 2 copies of From DDT and select 1D array of scalars - single channel. Then choose the channel with the control below the Scalar Data Type box.

 

Once you get the arrays configured correctly I suggest that you calculate the Mean of each array and use that for your single value per iteration. Averaging the 100 points should significnatly reduce any noise on the signal.

 

Lynn

 

 

Message 6 of 7
(2,709 Views)

Lynn, thanks so much for your help. I learned a lot.

0 Kudos
Message 7 of 7
(2,661 Views)