Hi everyone! I've heard great things about this forum and hence thought I'd post my question here to let the experts take a stab at it. I'm trying to write LabVIEW code to receive data from sensors (linear potentiometer and load cell), convert them from voltages to displacements (for the potentiometer) and loads (for the load cell). Then I need to find velocity from the displacement data so I took the derivative from the position data by converting it into an array and then plotted the resultant derivatives into a graphical waveform. I pretty much did the same thing for the load cell and the potentiometer. But there is one added difficulty to this and that is that this whole process must terminate when certain specifications are reached, so it shouldn't actually capture all of the data into an array and then sort it out per specs. It must continuously analyze the data and check it against specs and terminate if they are reached. For that, what I did was I added the specifications to the waveform output and set a case structure to it to terminate the process upon reaching the specifications. Although the code runs smoothly, it does not work to do what is intended. I have attached the file to this forum. If you would like me to clarify on any of this please let me know! Any help would be greatly appreciated!!! Thank you!
Start by learning about Shift Registers and Feedback Nodes. These are used to hold values from a previous iteration of the loop. So you can use a Feedback Node to subtract the previous displacement from the current displacement to get your velocity (assuming your dt is actually 1 second). You can then use In Range And Coerce to check to see if the velocity is within your desired range and stop the loop. Nothing should need to be done outside of the loop.
Hi! Thank you for your quick response. I will try using those functions in my code and let you know how it goes or if I have further problems!
So I did what you said with the shift register, while continuously inputting it into an array. But my dt is not 1 second, since it takes differing amounts of time between position changes. I tried doing a feedback node on position and time, but not sure how to pair them together. Any thoughts?
Again, you can move everything into the loop.
1. Since the myRIO is a RealTime computer, make the loop a Timed Loop. Now you should know the rate at which you are acquiring data, making the derivative calculation a lot simpler. In the attached file, I set the rate to be 1ms, giving the simple subtraction a m/s result (mm/ms = m/s).
2. Change your graphs into Charts. Charts keep at history for you, so you don't have to mess around with arrays.
3. Again, a simple Feedback Node is all you need to hold the previously read displacement.
I can't make the loop a timed loop since the time between iterations will change. This is dependent on how long it takes for the position of the potentiometer to change, which will vary a lot. I have tried doing this instead, including feedback nodes to get change in displacement and then divide by the change in time to get velocity. Haven't put in the In range and Coerce function parameters yet, will do that today. Also, how did you happen to get the chart function? I didn't see it in the block diagrams but I did notice it on the front panel and you're right it looks much much cleaner than the graph function (waveform). It would be awesome if you could help with that. Please check out the new VI attached.
I can't make the loop a timed loop since the time between iterations will change. This is dependent on how long it takes for the position of the potentiometer to change, which will vary a lot.
No, your iterations should be the same. This is the same as Sample Rate. For your calculations to be useful, you need a consistent sample rate.
Also, how did you happen to get the chart function?
I just replaced the graphs with charts on the front panel.
Hi sorry I haven’t replied back in so long. I actually haven’t tried your solution yet, I’ll let you know when I get it done. Thanks!