LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rate of change

Hi,
I am trying to build a program where it reads the input data,and calculate the rate if change.
The program suppose to work this way,where it reads the first data and read the data again 1 seconds later,and compare the change of data within this 1 sec.

>Read Data
>eg.4° 
>Read data again
>eg.7° 

>Compare the data in this 1 sec span
|4° -7° | / 1sec=3° /sec


I am using labview robotics 2015,version 15.0.1.I am using arduino to input data and the task I am trying to
perform is measure the rate of angle change in a second.

0 Kudos
Message 1 of 18
(4,669 Views)

Hi CQL,

 

I am trying to build a program where it reads the input data,and calculate the rate if change.

And what is your problem?

Where are you stuck?

All you need is a while loop with a shift register and a 1s wait function inside…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 18
(4,633 Views)

Sounds good so far. You have a well described algorithm (if not necessarily a very accurate one) and so now it just comes to programming it.

 

Have you managed to take a measurement yet? This will be the first/main step by the sounds of it - once you know how to make 1 measurement, it's just a matter of repeating and each time calculating differences. For that, it's likely easiest to use a Shift Register.

 

Example:

Example_VI.png


GCentral
0 Kudos
Message 3 of 18
(4,627 Views)

@GerdW wrote:

Hi CQL,

 

I am trying to build a program where it reads the input data,and calculate the rate if change.

And what is your problem?

Where are you stuck?

All you need is a while loop with a shift register and a 1s wait function inside…


Thanks for the reply.
Currently i am stuck with implementing the shift register function with my current program.

@I've tried implementing @cbutcher shift register program with my current program and the program just did not work as before.
Is it because of 2 while loop? or something else?
Or which other function will be the best for me to implement the rate of change from that particular data with my program?

Download All
0 Kudos
Message 4 of 18
(4,594 Views)

Thank for the reply.

I've tried putting the program you showed with my program and my program just do not work as before.
Is it because of the 2 while loop function at the same program?Not sure whats the issue

My programMy programThe shift registerThe shift register

0 Kudos
Message 5 of 18
(4,590 Views)

My example was using the loop to generate subsequent samples - you should move the shift register onto the outer While loop and not add a second while loop at all. Then, it might work how you want it to.

 

I'm curious as to why you're using the Bytes at Port to trigger a read with no wait, especially given I'm thinking that 50 bytes combined with the True constant wired to the Configure Serial Port indicates it does use a termination character (and the lack of termination character specified suggests if I recall correctly a CR character (but it might be LF?)).


GCentral
0 Kudos
Message 6 of 18
(4,576 Views)

@cbutcher wrote:

I'm curious as to why you're using the Bytes at Port to trigger a read with no wait, especially given I'm thinking that 50 bytes combined with the True constant wired to the Configure Serial Port indicates it does use a termination character (and the lack of termination character specified suggests if I recall correctly a CR character (but it might be LF?)).


This is actually a good setup for instruments that sporadically send data.  If any data has come in (Bytes At Port > 0), then a message has started.  Therefore it is safe to read and let the read complete with the termination character.  Just make sure there is a wait in the FALSE case (Bytes At Port = 0).


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 7 of 18
(4,565 Views)

crossrulz wrote:

This is actually a good setup for instruments that sporadically send data.  If any data has come in (Bytes At Port > 0), then a message has started.  Therefore it is safe to read and let the read complete with the termination character.  Just make sure there is a wait in the FALSE case (Bytes At Port = 0).


Good to know! 


GCentral
0 Kudos
Message 8 of 18
(4,543 Views)

Apparently this work.But then i am pretty sure that the value i read at "Change/time indicator is not the the change/1sec.
Right now i am trying to find out how long does it take to travel from one shift register to another.(The difference in time for the "new value" and "old value"). So i can ÷ the value accordingly.
Note: I am unable to put the timer to 1000ms as it will cause lag to my rotation of compass etc.
Current testCurrent test

0 Kudos
Message 9 of 18
(4,528 Views)

As you are not polling the data but simply read it whenever available, you need to adapt to the pace of the input.

If you know that you get exactly N samples in a second, you may discard N-1 data out of N.

Alternatively, you may record a time stamp after each read (for example using the Tick Count (ms) function) in a second shift register. The value difference should be divided by the time stamp difference - that is the elapsed time - expressed in seconds.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 10 of 18
(4,519 Views)