Android的传感器:getRotationMatrix()返回错误值,为什么呢? [英] Android sensor: getRotationMatrix() returns wrong values, why?

查看:137
本文介绍了Android的传感器:getRotationMatrix()返回错误值,为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几天来,因为我开始使用此功能,但尚未成功地获得有效的结果。

It's past several days since I started using this function and have not yet succeeded in obtaining valid results.

我要的是基本转换加速度矢量从设备的坐标系,以现实世界的坐标。我知道这是可能的,因为我有加速的相对坐标,我知道该设备在现实世界体系的方向。

What i want is basically convert acceleration vector from device's coordinates system, to real world coordinates. I' know that is possible because i have acceleration in relative coordinates and i know the orientation of the device in real world system.

<一个href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5B%5D,%20float%5B%5D,%20float%5B%5D,%20float%5B%5D%29"相对=nofollow>阅读Android开发者看来,使用getRotationMatrix()我得到R =旋转矩阵。

Reading Android developers seems that using getRotationMatrix() i get R = rotation matrix.

所以,如果我想从A(加速度在世界体系向量)(在电话系统加速度矢量)我必须做的只是:

So if i want A (acceleration vector in world system) from A' (acceleration vector in phone system) i must do simply:

  A=R*A'

但我cant'n理解为什么在矢量A始终的第一和第二部分零(例如:+0,00; -0,00; +6,43)

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)

我目前的code是类似这样的:

My current code is similar to this:

  public void onSensorChanged(SensorEvent event) {
     synchronized (this) {   
        switch(event.sensor.getType()){
        case Sensor.TYPE_ACCELEROMETER:
            accelerometervalues = event.values.clone();
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            geomagneticmatrix =event.values.clone();
            break;
        }
        if (geomagneticmatrix != null && accelerometervalues != null) {
            float[] Rs = new float[16];
            float[] I = new float[16];
            SensorManager.getRotationMatrix(Rs, I, accelerometervalues, geomagneticmatrix);
            float resultVec[] = new float[4];
            float relativacc[]=new float [4];
                relativacc[0]=accelerationvalues[0];
                relativacc[1]=accelerationvalues[1];
                relativacc[2]=accelerationvalues[2];
                relativacc[3]=0;
            Matrix.multiplyMV(resultVec, 0, Rs, 0, relativacc, 0);

            //resultVec[] is the vector acceleration relative to world coordinates system..but doesn't WORK!!!!!

        }
      }
   }

这个问题很类似这样的<一个href="http://stackoverflow.com/questions/5464847/transforming-accelerometers-data-from-devices-coordinates-to-real-world-coordi">Transforming从设备坐标加速度计的数据,以真实世界坐标但我无法找到解决办法......我已经尝试了所有的办法。

This question is very similar to this one Transforming accelerometer's data from device's coordinates to real world coordinates but there i can't find the solution...i had tried all the ways..

请帮我,我需要帮助!

更新:

现在我的code是下面,我曾试图解释矩阵的产品,但没有什么变化:

Now my code is below, i had tried to explain matrix product, but nothing change:

            float[] Rs = new float[9];
            float[] I = new float[9];
            SensorManager.getRotationMatrix(Rs, I, accelerationvalues, geomagneticmatrix);
            float resultVec[] = new float[4];

            resultVec[0]=Rs[0]*accelerationvalues[0]+Rs[1]*accelerationvalues[1]+Rs[2]*accelerationvalues[2];
            resultVec[1]=Rs[3]*accelerationvalues[0]+Rs[4]*accelerationvalues[1]+Rs[5]*accelerationvalues[2];
            resultVec[2]=Rs[6]*accelerationvalues[0]+Rs[7]*accelerationvalues[1]+Rs[8]*accelerationvalues[2];

下面一些数据比如阅读和结果:

Here some example of data read and result:

Rs separated by " " Rs[0] Rs[1]....Rs[8]
Av separated by " " accelerationvalues[0] ...accelerationvalues[2]
rV separated by " " resultVec[0] ...resultVec[2]

正如你可以看到在x和y轴在现实世界中的分量是零(约),即使你移动speddy电话。相反,相对加速度矢量正确地检测每一个动作!

As you can notice the component on x and y axes in real world are zero (around) even if you move speddy the phone. Instead the relative acceleration vector detect correctly each movement!!!

解决方案: 在numberrs的误差相对于浮动瓦尔乘法是不一样的双multyplication。 这总结到的事实旋转矩阵不costant如果手机,即使有相同的方向,正在加速。 所以是不可能的运动过程中转化加速度矢量绝对坐标... 这很难,但它是事实。

SOLUTION The errors in the numberrs are relative to float vars multiplication that is not the same as a double multyplication. 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.

推荐答案

Finnaly我找到了答案:

Finnaly i found the answer:

在号码错误是相对于浮动瓦尔乘法是不一样的双multyplication。 <一href="http://stackoverflow.com/questions/8035566/android-big-fail-on-float-values-product/8039857#8039857">Here有解决方案。 这总结到的事实旋转矩阵是不是如果手机,即使使用相同的方向,正在加速 costant。所以是不可能的运动过程中转化加速度矢量绝对坐标......这很难,但它是事实。

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.

仅供参考方向向量从magnetomer数据和重力向量进行。这会导致ciclic问题:转换相对ACC需求oirentation需要的磁场和重力,但我们知道引力只有当手机是相对acc..so阻止我们回到开始

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.

这是证实了<一href="http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix%28float%5B%5D,%20float%5B%5D,%20float%5B%5D,%20float%5B%5D%29">Android开发商哪里的旋转矩阵解释给真正的结果,只有当手机没有加速(如他们谈论的自由落体,事实上不应该有重力mesaurement),或者当它不是在非regulare磁场。

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.

在别人的世界里,完全未有用... 你可以相信这件事情做简单的实验在桌子上与Android塞纳或者是这样的。

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

这篇关于Android的传感器:getRotationMatrix()返回错误值,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆