Android sensor: getRotationMatrix() returns wrong values, why?

人走茶凉 提交于 2019-11-30 07:41:23
Lork

Finnaly i found the answer:

The errors in the numbers are relative to float vars multiplication that is not the same as a double multyplication. Here there is the solution. This sums to the fact that rotation matrix isn't costant if the phone, even if with the same orientation, is accelerating. So is impossible translate acceleration vector to absolute coordinates during motion... It's hard but it's the reality.

FYI the orientation vector is made from magnetomer data AND gravity vector. This cause a ciclic problem: convert relative acc needs oirentation needs magnetic field AND gravity, but we know gravity only if the phone is stop by relative acc..so we are return to begin.

This is confirmed in Android Developers where is explained that rotation matrix give true result only when the phone isn't accelerate (e.g. they talk of free fall, infact there shouldn't be gravity mesaurement) or when it isn't in a non regulare magnetic field.

The matrices returned by this function are meaningful only when the device is not free-falling and it is not close to the magnetic north. If the device is accelerating, or placed into a strong magnetic field, the returned matrices may be inaccurate.

In others world, fully un-useful... You can trust this thing doing simple experiment on the table with Android Senor or something like this..

You must track down this arithmetic error before you worry about rotation, acceleration or anything else.

You have confirmed that

resultVec[0]=Rs[0]*accelerationvalues[0];

gives you

Rs[0]: 0.24105562
accelerationValues[0]: 6.891896
resultVec[0]: 1.1920929E-7

So once again, simpify. Try this:

Rs[0] = 0.2;
resultVec[0] = Rs[0] * 6.8

EDIT:
The last one gave resultVec[0]=1.36, so let's try this:

Rs[0] = 0.2;
accelerationValues[0] = 6.8
resultVec[0] = Rs[0] * accelerationValues[0];

If you do the sums, using the printed values you have appended, I get

`(0.00112, -0.0004, 10)`

which is not as small as what you have. Therefore there is an arithmetic error!

Could the problem be that you are using accelerationvalues[] in the last block, and accelerometervalues[] later?

I have developed several applications that make use of android sensors, so I am answering to one of your questions according to my experience:

But i cant'n understand why the vector A has ALWAYS the first and the second component zero (example: +0,00;-0,00;+6,43)

I have observed this problem with the acceleration sensor and the magnetic field sensor, too. The readings are zero for some of the axis (two as you point, or just one in other occasions). This problem happens when you have just enabled the sensors (registerListener()) and I assume that it is related to some kind of sensor initialization. In the case of the acceleration sensor, I have observed that just a small shaking of the device makes it to start giving correct sensor readings.

The correct solution would be the method onAccuracyChanged() giving the correct information about the sensor state. It should be returning a staus of SensorManager.SENSOR_STATUS_UNRELIABLE, but instead of that, it permanently returns SensorManager.SENSOR_STATUS_ACCURACY_HIGH on all physical devices that I have tested so far. With the method onAccuracyChanged() properly implemented, you could ignore bad readings or ask the user to wait while the sensor is being initialized.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!