math3dgdscriptsensor-fusion

How do I calculate the traveled path of mobile devices using sensor data?


I want to plot the device's movement in 3D space using the accelerometer, gyroscope and other smartphone sensors.

After a bit of research, I found an equation that said it can be done by doing double integration of the a*t^2 equation, but that introduced a huge margin of accumulated error and drift. My solution to this was to skip double integration and instead calculate area of a trapezoid - ((a(t) - a(t-1)) * dt / 2) + (dt * a(t)) however this is giving discrete results which when added up do not provide the correct path (even without applying gravity filter and when moving the device on a flat surface).

Is there a more accurate way of performing these calculations in real time given that I have a constant value for delta time and a sensor data sample on each time interval where Nth sample is taken at time N*dt.


Solution

  • Unfortunately if you're just using accelerometer and gyroscope data then you're generally going to see quite a bit of drift over time of your data. What other sensors are you using? Do you have access to GPS data? And do you have a mathematical model of the kind of motion you expect the smartphone to undergo?

    That said, if you're stuck with an IMU then there are a huge variety of filters that will give you estimates that are better than simple integration. The simplest of which is probably a Madgwick Filter, it's straightforward to implement and just combines your linear accelerometer and gyroscopic data. An important takeaway here is that the gyroscopic sensor data is converted and updated as quaternions.

    That tutorial actually gives a pretty nice overview of the mathematical model of an IMU, and a few of the filters you can test out. The most complex is the Kalman Filter and varieties of it, like the Unscented Kalman Filter, they can be difficult to tune but general give good performance.

    Sorry there's not a simple answer to your question. But you ask a broad question and the answer is heavily dependent on your application. But I would recommend playing around with the Madgwick or Complementary filters listed in that tutorial, they're pretty simple and might give you a quick improvement over your initial estimations.