LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate Target Velocity Using 2 Photoelectric Sensors

Solved!
Go to solution

I am using 2 photoelectric sensors mounted parallel to each  other. As the target passes in front of the sensor, the output voltage signal goes from 0V to 10V. Since I know the distance between the sensors, I need to use the difference in time of signal rise between the sensors to calculate velocty. I can do this when I export the data to excel, but I would like to do this automatically in my LabVIEW code.

 

The data from my sensors is waveform type. I can extract the waveform components (t0, dt, Y) using "Get Waveform Components" and then find the timestamp for each value using t0, dt, and the index for the value. I need to calculate the timestamp for each sensor once the signal rises to 10V (Y=10V). I'm having trouble extracting the waveform components for both sensor signals (I seem to only be able to extract components for one sensor) and once I extract the components, setting up my calculation of velocity. I'm thinking I need a case structure to save the timestamp once the signal first hits 10V (if Y=10V save timestamp; if Y=0V continue indexing values).

 

Any suggestions on extracting waveform components or indexing values and calculating velocity are greatly appreciated! Attached is the code I wrote to collect signals.

 

Many thanks,

Alberto M.

 

Below is a sample of the sensor signals showing time difference in rise in signal. 

VelSensorSignals.png 

 

0 Kudos
Message 1 of 10
(3,839 Views)

You can use a for loop to find where the voltage rises above some threshold:

 

scan array.png

 

Once you do that, it's just a matter of adding t0 + [index]*dt where index is the array element when the rise occurred.

Message 2 of 10
(3,816 Views)

Thank you for your reply! This will be very helpful once I can extract the waveform components for both channels.

 

Do you know how I can split the signals in the data wire (since both input channels are in this wire and I need to calculate the timestamp of both). I tried the split signals function but I'm receiving an error since this converts the data to dynamic.

 

Many thanks!

0 Kudos
Message 3 of 10
(3,801 Views)

If you want help with your code, it is always a good idea to attach your code ("code" usually means one or more VIs, rarely does it mean pictures).  If you have two signals sampled simultaneously, the problem is even simpler -- simply find the difference between the indices where the signals shoot up and multiply by the delta-t ("dt" element of the Waveform cluster) to get the time.

 

Bob Schor

0 Kudos
Message 4 of 10
(3,793 Views)

Bob, thank you for your reply. I attached my code in my original post, but here it is attached as well. Both signals are sampled simultaneously like you said, I'm just having trouble splitting the signals so I can extract the components of each (and thus the index where the signal reaches a threshold). 

 

Any suggestions are greatly appreciated!

0 Kudos
Message 5 of 10
(3,784 Views)

Yes, you did -- my apologies.  I'll take a look ...

 

BS

0 Kudos
Message 6 of 10
(3,778 Views)

Strange -- when I open your VI, I see the Front Panel, but when I try to open the Block Diagram, LabVIEW hangs (after 2 minutes, I force it to stop).  I'll keep trying a few more times ...

 

BS

0 Kudos
Message 7 of 10
(3,775 Views)

Aha, I just have to wait longer ...

 

According to your code, you are collecting samples one at a time, and are displaying them for every point (which may affect your sampling rate).  Why not take 1000 samples all at once so that your two Waveforms will have 1000 points, instead of 1 point, in them?  [Am I missing something?  My marbles, probably ...]

 

Bob Schor

Message 8 of 10
(3,769 Views)
Solution
Accepted by topic author martiaa3

1. You should use Finite Sample mode and read all of the samples.  To match what you have, I would use 10k samples.  That would be 5 seconds worth of data.  This eliminates the need for the while loop and gives you the full waveforms.

2. Just use the Basic Trigger Level Detection VI (in the Signal Processing->Waveform Measurements->Waveform Monitoring palette) to get the time for each rising edge.  Then it is a simple subtract and divide.

 

Also, if you wanted to make things even easier, you could have used a device with an A-B counter.  Then the counter just gives you the time difference directly.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 10
(3,731 Views)

Thank you for the reply! Your code works perfectly, this is exactly what I wanted.

0 Kudos
Message 10 of 10
(3,692 Views)