We tried to figure out if it’s possible to reconstruct a smartphone’s three-dimensional path using only accelerometer and gyroscope data. This could be used for instance to draw a race track in a room by walking around, while waving your phone as a brush to draw the track.
This is definitely not an easy task. To obtain the right information, the following needs to be done:
- Combining the information from the accelerometer (measuring accelerations, including gravity) and the gyroscope (measuring the 3D rotation of the device) to obtain the device’s acceleration without gravity. This is the basic information required to start the reconstruction of the device’s path.
- The resulting data is quite noisy; even if the phone is lying still on the table, small accelerations are recorded. I evened this out a bit by using the average of the last few samples.
- To determine the device’s position, we have to integrate the acceleration data to obtain the device’s velocity, and then integrate that again to obtain its position. However, these integrations dramatically enlarge any small error in the data, rendering it unusable.
A good overview of this can be seen in this video:
So it turns out that creating a correct 3D path of a smartphone using only accelerometer and gyroscope data is impossible.
Based on the application in which you’d want to use this, you may be able to come up with a way to make it work though – although some form of drift will probably always exist.
- If your path is limited to straight movement and 90 degree angles, you could specifically look for accelerations in specific directions
- It may be possible to use the GPS position of the device to correct the errors to some degree.
- You could try using a Kalman filter to predict current position based on previous values.