Harshit Jain
Harshit Jain

Reputation: 71

How to apply calibration to accelerometer in android?

I am using rotation vector sensor to calculate the orientation of my device. There seems to be an error in the output of rotation vector sensor due to some offset in accelerometer data. I am able to calculate that offset but how can I apply that offset to rotation vector sensor in order to return correct orientation.

Upvotes: 1

Views: 431

Answers (1)

Remc4
Remc4

Reputation: 1180

Sensor.TYPE_ROTATION_VECTOR fuses multiple sensors together (accelerometer, geomagnetic field, gyroscope) to estimate the rotation of the device. However, different manufacturers use different algorithms to achieve this. You might notice that on Samsung devices, this sensor is rather "twitchy", while on Google Pixel phones, it's very steady.

I don't believe it's possible to calibrate the rotation sensor. While the device might always know where down is (using accelerometer data), it can't be 100% certain where north is. Try waving metal scissors above the device, and you'll see the sensor output goes crazy, starting to spin in circles.

What you might be able to do is write your own implementation of sensor fusion to at least make the algorithm consistent across all devices (note that some cheaper tablets don't have a magnetic field sensor though). See this library for an example: https://github.com/apacha/sensor-fusion-demo.

Upvotes: 1

Related Questions