LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to find a change in value greater than threshold in a specific time frame

Hi,

I acquire Pitch Roll Yaw angles continuously from a gyro. I would like to check if the value (RPY angles) changes greater than 60 degrees in a time frame of 500ms. I run the loop every 10ms. According to the data below, the value changes 10 to 80 degrees in 5 or more steps when a change actually occurs. 

Can someone guide me as to how this could be implemented

 

01/03/2017  12:19:01,860   10,790822 

01/03/2017  12:19:01,984   15,046648
01/03/2017  12:19:02,083    26,481090
01/03/2017  12:19:02,201    40,054445
01/03/2017  12:19:02,300    61,342823
01/03/2017  12:19:02,387    82,453988

0 Kudos
Message 1 of 10
(3,746 Views)

I think that your question is slightly ambiguous.  You state that you are sampling every 10 msec and have a question about values in a 500 msec sample = 50 samples.  So let me rephrase the question slightly -- given 50 samples, do you want to know:

  • Does any of the subsequent 49 samples differ from Sample #1 by > 60°?
  • Do any of the first 49 samples differ from the succeeding samples by > 60°?
  • Since you have Roll, Pitch, and Yaw, are you handling the three channels independently, or are you asking "Does the total rotation change by > 60°?"  Note that this is a much more complex problem that may require Rotation Matrix/Rotation Vector algebra.
  • I'm assuming that if the answer to the above question(s) is "No" (there is no difference), you want to "slide" the 50-sample Window down by one sample and consider Samples 2 through 51, but maybe you want to do Samples 51-100 (but this might be a different question).

Bob Schor

 

0 Kudos
Message 2 of 10
(3,721 Views)

Here's one way:

 

If you sample every 10 mSec, then your interval (500 mSec) is 50 samples.

Create a buffer (array) of size 50.

Use it as a circular buffer, i.e. every sample, you store at BUFFER[i} and then increment i.

If I >= 50, set i = 0.

That means that i always points to the NEXT sample to replace, and the buffer always (after you get 50 samples) contains the most recent 50 samples.

Every sample, take the MAX-MIN of the buffer and subtract MAX - MIN.  That's your max change over the last 500 mSec.

 

You might have to do some special things:

1... If you have zeroes in the buffer at the start, then 0 might show up as your minimum, until you get 50 samples.  Disregard the result for the first 500 mSec, or start with empty (0 element) buffer and expand it each sample up to 50, or take the first sample and fill the buffer with 50 copies of it.

2... If your data ranges from 0..359, or from -180..+179, then you have some wrong results when crossing that boundary.  (359 - 0 = 359, but it's only a 1-degree change). There are ways to deal with that, but get the first part basically working first.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 10
(3,719 Views)

Hi Steve,

 

Thanks for the idea and I tried the circular buffer concept. I am now running the loop at 50ms and so I am checking the every 11 samples (every 550ms) and a threshold of 60 degrees. But there are instances, like in the front panel screenshot attached, where Peak angle value is not added to the buffer because by then, the buffer is full and hence the threshold check condition is not met. I want to check for value greater than 60. How can this be overcome?

 

P.S. I running the VI with sample data from file and not with the actual acquisition VI

Download All
0 Kudos
Message 4 of 10
(3,685 Views)

I can't see anything terribly wrong there, but then I can't see everything that's there.

 

Is "Buffer" on the front panel the same as "SubArray" on the diagram?

Do the FALSE cases pass thru the indicated wires unchanged?

 

If so, then you need to use single stepping and probes to find out what's happening.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 10
(3,664 Views)

I think the VI is working fine but its the logic now ehich is the problem. I am checking every 11 elements in 550ms. The change in angle in the file starts at index 107 with lowest value of 10 and peak value of 82 at index 111. So this range of 5 values does not come under the multiple of 11 altogether. I hope you understand

0 Kudos
Message 6 of 10
(3,655 Views)

So... what does a probe tell you the peak is when you extract the array MAX/MIN ?

Looks like it should be 82 if you do a comparison on the data you show.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 10
(3,653 Views)

The max value is 61. The buffer gets full, moves to index 0 and peak value 82 which comes after 61 is stored at index 0. The next 10 elements are between 80 and 90. the subtraction will give 10 which less than threshold 60 and output is zero. I have attached the data file. Use the VI and you will understand my earler point

0 Kudos
Message 8 of 10
(3,647 Views)

I set your buffer size back to 11, put some phony data in column 5 of a 2-D string array, and your code does exactly what you tell it to (they usually do).

 

You are aware that your light will only come on for 50 mSec, right?

The next time you go thru the loop, the index will be different and you turn OFF the light.

If you want to see it longer, put a 500 mSec wait IF TRUE on the output of your CASE structure.

 

 

Here's another problem with your code - you will miss some changes unless you test (MAX - MIN > 50) on EVERY SAMPLE.

Note how my original scheme said test on EVERY SAMPLE.  You are testing every 10 SAMPLES.

 

That means that I could have data like 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, and your scheme will not see the change, because it happens to line up with your block size.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 9 of 10
(3,645 Views)

The code you actually sent has some logic errors, too.

 

You fill up a buffer with 50 copies of "-1".  After replacing 10 of those samples with real data, you test the whole buffer for MAX/MIN.  your min is.... -1.

 

As I said originally, you have to ignore the results until the buffer is full, or pre-load the buffer with the first real sample.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 10
(3,643 Views)