简体   繁体   中英

Acceleration and Velocity from X,Y Position Stream C++

I have a stream of (x,y) data that I want to determine velocity and acceleration from. The data is pretty typical and can be thought to represent say a car driving around.

A new data point comes every 2ms and I would prefer to not accumulate/store unnecessary values so I thought to use a boost::accumulator .

Is there a simpler way to handle this type of task? or perhaps other libraries that already exist which already does this? or am I on the right track with my thinking. Not yet sure what tags I'm going to use but I like the idea that the container keeps an updated value for a given property and doesn't store the old positional data.

Another idea is to use a circular buffer (eg size 200) and calculate the acceleration based off the last 50 values and velocity based off all the values in the buffer. However if the buffer stores raw positional data this would require looping over all elements every time to calculate the acceleration and velocity. This could be improved by instead keeping some sort of rolling acceleration and velocity value which recalculates by removing the value from the end element and adding the value from the new element to insert (with weight 1/elements in buffer). However this to me seems like some sort of boost rolling weighted accumulator.

You probably want to apply some sort of a Kalman filter to the data. Old data needs to be there to help reduce the impact of noise, new data needs to be there, and weighted higher so that the answer is sensitive to the latest information.

A fairly simple approach for position, lets call it X , where each new sample is x is:

X = (1-w) * X + w * x

as each new value comes in. Where the weight w adjusts how sensitive you are to new information vs old information. w = 1 means you don't care about history, w = 0 means you don't care at all about new information (and obviously means that you'll never store anything).

The instantaneous velocity can be calculated by computing the difference between successive points and dividing this difference by the time interval. This can in turn be filtered with a Kalman filter.

Acceleration is the difference in sequential velocities, again divided by the time interval. You can filter these as well.

The divided differences will be more sensitive to noise than the position. For example, if object whose position you're monitoring stops, you will continue to get position measurements. The velocity vectors for successive measurements will point in random directions.

Boost accumulator doesn't appear to do what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM