LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView Code for myRIO not working

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!

Download All
0 Kudos
Message 1 of 8
(1,124 Views)

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.


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 2 of 8
(1,099 Views)

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!

0 Kudos
Message 3 of 8
(1,093 Views)

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?

0 Kudos
Message 4 of 8
(1,072 Views)

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.


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
0 Kudos
Message 5 of 8
(1,065 Views)

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.

0 Kudos
Message 6 of 8
(1,058 Views)

@makrilavy79 wrote:

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.

 


@makrilavy79 wrote:

Also, how did you happen to get the chart function?


I just replaced the graphs with charts on the front panel.


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
0 Kudos
Message 7 of 8
(1,051 Views)

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!

0 Kudos
Message 8 of 8
(1,030 Views)