"Rewinding" Data

Hello all!

I’m trying to implement a “rewind” function for our robot state. Essentially, what I want is something like this:

-Periodically (say, every 50ms) a gyro angle is written into this data structure
-At any time, I would like to be to request the “historical” value of the gyro from somewhere between 0 and 3 seconds ago.

What sort of data structure should I be using?

-John Gilbert

I’d use an array of the appropriate size.
Make it a circular queue and just toss the oldest value while inserting the newest value.
You’ll have to calculate the appropriate past position to retrieve.

There’s an example of keeping “n” past values for purposes of a moving average on this page. Search for “Moving Average”.