So I am attempting to log my navX yaw data with an accompanying timestamp in the hopes of accounting for vision lag while doing things like turning.My goal is to use a camera timestamp to find the yaw at that point in time. My first thought was just create an array, but with my code running at 200hz (or even logging at the navX 100hz native update rate), the array would grow far too large. An arraylist would allow for easy deletion to keep the size small (I see no reason to keep more than 200ms of data), but then looking up values would be pretty cpu intensive even if I normalized the timestamps to the nearest 5ms. My current thinking is to use a HashMap to allow for easy retrieval, but that would make deletion a difficult process because my code does not have consistent timing at 200hz. Deleting the current timestamp - 200ms may or may not work causing issues. I figured this was a pretty common task, but I could not find any examples. Any ideas/code examples would be greatly appreciated (especially something like a fixed size array class that would auto delete as new members are added).
Thanks in advance
Hi Alex, this is what SF2’s first phase release is intended for. Take a look at the vision processing latency correction example on the SF2 website.
SF2 is open source, the implementation code is on github. Not sure what language you are using, but for c++ and Java the class implementing the temporal history and lookup is called ThreadsafeInterpolatingTimeHistory.
This sounds like a job for a circular queue. Declare an array of the number of items in your queue and an integer to hold the index of the oldest entry. Each time you insert a value, overwrite the oldest value and increment the array index so it points to what is now the oldest entry in the queue. Add a bit of logic to handle the wrap when you reach the end of the queue, both when adding data and when looping over it for access.
We have a class for this which you are welcome to use. There’s no documentation yet (I’ll try to wrap that up before kickoff) but the code is on our github.
Oh wow okay those are all three great options. I think I’m gonna try sf2 to start and I’ll see how it goes:)