I am new to Arduino and this forum, so please forgive me if I am asking something really trivial and stupid.
I have an Ardino board which collects sensor readings from a mpu6050 sensor(Acceleration+Gyroscope). The next step for me would be to process these data directly on the board. I want to somehow store N last sensor values and then query this set (collection, vector, array, whatever you call it) to fetch certain values. This set will be constantly updated with new values, whereas older values will be pushed out, so that only the most up-to-date values are stored in the set. For example, I want to know if the acceleration exceeded 10 m/s in the last minute.
In the literature this kind of set with most recent values is sometimes called window - this approach allows limiting an unbounded sequence of constantly generated tuples to a bounded bag and then apply traditional SQL-like query operators. For example, Oracle has come with CQL - an engine and a query language for handling streaming data.
Before I start implementing this, I am wondering if there is a similar (and, of course, much simpler) library for Arduino? If not, which data structure should I use to implement such functionality?
Also, my intention is to query not just individual values, but certain patterns and sequences - e.g., I want to know if the acceleration first decreased and then increased again (something similar to the WHERE condition of an SQL query). Does it look realistic to implement with Arduino?
You said you wanted to find a specific value in the last minute's worth of data. How often is the sensor read and the value stored in the array? Also, what are the type of values coming in (e.g., integer data or floating point)? I would think an array would work where the current values are "bumped up" when a new reading arrives, as in:
memmov(&values[1], values, (sizeof(values) / sizeof(values[0]) ) - 1); // slide all values up 1 place...
and then use:
values[0] = newReading; // Add new value
You can then search the array for a specific value. If the values are sampled at regular intervals, then the match index could be used to tell you how "old" the value is.
EDIT: I screwed up the memmove() call. I think it should be:
memmov(&values[1], values, (sizeof(values) - sizeof(values[0]) ) ); // slide all values up 1
That is, if the array is 60 ints, only the first 118 bytes need to be moved up.
How often is the sensor read and the value stored in the array? Also, what are the type of values coming in (e.g., integer data or floating point)?
Given the fact that all the variables are stored in RAM (which is just 2.5kB for Arduino Yun in my case), I have to use this space efficiently. My plan is to use integer values and see what the maximum sensor read frequency can be - I will start with 10 reads per second to see how many of them I can store in the array.
In some other forum I was suggested to look at the Average library. It implements the so-called "rolling" set of data with a circular buffer. It allows to store a rolling set of data where you get to push values into it and the oldest one drops off the end. It also has some built-in functions like min, max, mean, average, etc. Has anybody of you tried it before?