SensorManager.getRotationMatrix gravity parameter or accelerometer parameter values ​​in android?

In the documentation for Android , the third parameter is specified as

float[] gravity 

then indicates

 [0 0 g] = R * gravity (g = magnitude of gravity) 

Now, in most examples online, I see how everyone passes the accelerometer values ​​to getRotationMatrix, but is it supposed to send me only gravity values?

For example, if the mobile phone has a gravity sensor, Should I send the original output to getRotationMatrix? If it is missing, should accelerometer values ​​be sent? Should I first extract components without gravity? (as the values ​​of the accelerometer - acceleration minus G).

Will using gravity sensor values ​​be more reliable than using accelerometer values ​​in mobile phones with this sensor?

Thanks in advance! Guillermo.

+4
source share
1 answer

I think the reason you see only examples using accelerometer values ​​is because the gravity sensor was only launched in API 9, and also because most phones could not separate these values ​​from the accelerometer values ​​or not have sensor etc etc ..

Another reason is that in most cases the result tends to be the same, because what the accelerometer sensor gives out is linear acceleration of the device and gravity, but most of the time the phone will stand or even move at a constant speed, so the acceleration of the device will be zero .

From setRotationMatrix Android Docs:

The matrices returned by this function make sense only when the device does not fall freely and it is not close to magnetic north. If the device is accelerated or placed in a strong magnetic field, the returned matrices may be inaccurate.

Now you ask, will gravity data be more reliable? Well, there is nothing like testing, but I believe that it will not make much difference, and it really depends on which application you want. Also, getting simple gravity is not trivial, and it requires filtering, so you can get noisy results.

+1
source

Source: https://habr.com/ru/post/1394385/


All Articles