LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculating distance from sensor

I have linear sensor(0,7metres) with analog 4-20 mA signal, how i can calculate total distance, when sensor goes up and down while the program is running, i.e. sensor starts from 0 goes to max. 0,7 metres and back to zero -> 1.4 metres or 0 to 0,4 and back to 0,1 ?
0 Kudos
Message 1 of 15
(4,311 Views)
I am not sure I understand exactly what you want. Are you trying to measure the accumulated distance travelled?

To measure the accumulated distance travelled use a while loop and two shift registers. On each loop iteration subtract the current sensor position from the previous one as saved in one shift register. Add the difference to the accumuated total in the other shift register. You will need to use an absolute value function if the direction is not significant. The sensor must be read fast enough that the device being measured cannot reach a peak value, reverse, and travel a significant distance back before the next reading to avoid missing some distance.
Message 2 of 15
(4,306 Views)
Hello,
Yes, i want to measure accumalated distance travelled.

I tried your advice, but i dont know what i am doing wrong, can you show me example?
0 Kudos
Message 3 of 15
(4,306 Views)
I have attached a sample. This uses two loops. The outer while loop contains the Sine Wave.vi which simulates the sensor. The inner for loop performs the calculations as I described.

Lynn
Message 4 of 15
(4,306 Views)
Thanks for your answer, I have to ask one more question, How i can measure also distances between start and stop signal, like i have sequence 1, 2 and 3. And all start and stop with boolean signal.

Jani
0 Kudos
Message 5 of 15
(4,306 Views)
Jani,

Try this VI to see if it does what you want. I added two buttons to the front panel. One starts and stops the accumulation and the other resets the accumulated distance to zero.

Lynn
Message 6 of 15
(4,308 Views)
hello,

your VI is good, but i wanted that i can measure one "full time" like period, and then there is parts of the period. I do this for the plastic injection machine, so there is time parts like portion/apportion, injection etc.

i hope you understand, sorry for my english.
0 Kudos
Message 7 of 15
(4,306 Views)
I can use your VI, but there is one problem, if i do one calculating, reset and then start, VI add value from sensor to distance travelled, so if sensor is on 300 mm. -> distance travelled is 300 mm. It should be 0 mm. ?
You can try this, put slider to simulate the sensor.
0 Kudos
Message 8 of 15
(4,294 Views)
Hi Jani!

In response to your last post, I saw the same behavior that you were talking about. I made some modifications to the VI and now it does reset to zero when you press "reset."

I hope this helps!

Take care,
Travis H.

National Instruments
Travis H.
LabVIEW R&D
National Instruments
Message 9 of 15
(4,269 Views)
thank you, that was great!
0 Kudos
Message 10 of 15
(4,256 Views)