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 ?
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.
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.
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.
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.
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 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.
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."