将来自设备的坐标加速度计的数据,以真实的世界坐标 [英] Transforming accelerometer's data from device's coordinates to real world coordinates

查看:264
本文介绍了将来自设备的坐标加速度计的数据,以真实的世界坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很抱歉,如果这是一个非常基本的问题,但我没有选择,只能问它:你怎么翻译的加速度数据从设备坐标到真实世界坐标

I'm really sorry if this is a very basic question, but I have not choice but ask it: How do you translate the accelerometer data from the device coordinates to real world coordinates?

我的意思是,假设加速度传感器是给我somenting像(AX,AY,AZ) - <一href="http://www.anddev.org/novice-tutorials-f8/acceleration-orientation-visual-reference-t11818.html"相对=nofollow>在设备坐标 - ,我应该申请转换值成什么样的转换(AX',唉,AZ') - <一href="http://developer.android.com/reference/android/hardware/SensorManager.html#getOrientation%28float%5B%5D,%20float%5B%5D%29"相对=nofollow>在现实世界中的坐标 - ,这样我就可以用加速度矢量在现实世界的坐标来计算,如果该设备正在加快华北,华东,西南等

I mean, assuming that the accelerometer is giving me somenting like (Ax,Ay,Az) -in device's coordinates-, what transformations should I apply to transform the values into (Ax',Ay',Az') -in real world's coordinates-, so I can use the acceleration vector in real worlds coordinates to calculate if the device is accelerating north, east, south-west,etc?

我一直在努力解决这个问题,在过去的几天里。起初我以为这shound't是困难的,但是搜索几十页之后,我还没有想出什么功能。

I have been working around this issue during the past few days. At first I thought that it shound't be difficult, but after searching dozens of pages I haven't come up with anything functional.

顺便说一句,这里有一些code与我到目前为止已经实现的:

By the way, here is some code with what I've implemented so far:

    private SensorEventListener mSensorEventListener = new SensorEventListener() {

    public void onAccuracyChanged(Sensor sensor, int accuracy){
}

    public void onSensorChanged(SensorEvent event) {
        switch(event.sensor.getType()){
        case Sensor.TYPE_ACCELEROMETER:
            accelerometervalues = event.values.clone();
            AX.setText(accelerometervalues[0]+"");
            AY.setText(accelerometervalues[1]+"");
            AZ.setText(accelerometervalues[2]+"");
            break;
        case Sensor.TYPE_ORIENTATION:
            orientationvalues = event.values.clone();
            azimuth.setText(orientationvalues[0]+"");
            pitch.setText(orientationvalues[1]+"");
            roll.setText(orientationvalues[2]+"");
            break;
        case Sensor.TYPE_MAGNETIC_FIELD:
            geomagneticmatrix =event.values.clone();
            TAX.setText(geomagneticmatrix[0]+"");
            TAY.setText(geomagneticmatrix[1]+"");
            TAZ.setText(geomagneticmatrix[2]+"");
            break;
        }
        if (geomagneticmatrix != null && accelerometervalues != null) {
            float[] R = new float[16];
            float[] I = new float[16];
            SensorManager.getRotationMatrix(R, I, accelerometervalues, geomagneticmatrix);
            //What should I do here to transform the components of accelerometervalues into real world acceleration components??
        }
   }
};

我有:

在本地坐标加速度在一个vector accelerometervalues​​

A vector of accelerations in native coordinates in accelerometervalues.

磁场值在一个vector geomagneticmatrix

A vector of magnetic field values in geomagneticmatrix.

方位角,俯仰和横滚在 orientationvalues​​

Azimuth, pitch and roll in orientationvalues.

旋转矩阵研究。 倾角矩阵

Rotation matrix R. Inclination matrix I.

我觉得所有必要的信息是存在的,方位角,俯仰和横滚应说明该设备的坐标系的位移相对于现实世界的坐标系。另外,我认为,研究是/甚至可以用作设备内的真北向量的坐标。

I think all the necessary information is there, azimuth, pitch and roll should describe the displacement of the device's coordinate system in relation with the real world coordinate system. Also, I believe that R is/can even be used as a true north vector inside the devices coordinates.

在我看来,这obtaing加速在现实世界中的价值仅仅是一个数学变换远离那些数据。我只是不明白。

It seems to me that obtaing the values of acceleration in real world is just a mathematical transformation away from those data. I just can't figure it out.

在此先感谢。

编辑:

我曾尝试直接multipliying accelerometervalues​​ 的组件旋转矩阵研究(trueaccel =加速* R)但没有奏效。

I have tried directly multipliying the components of accelerometervalues with the rotation matrix R (trueaccel=accel*R) but it didn't work.

                    trueacceleration[0]= accelerometervalues[0]*R[0]+accelerometervalues[1]*R[1]+accelerometervalues[2]*R[2];
                trueacceleration[1]= accelerometervalues[0]*R[1]+accelerometervalues[1]*R[4]+accelerometervalues[2]*R[7];
                trueacceleration[2]= accelerometervalues[0]*R[2]+accelerometervalues[1]*R[5]+accelerometervalues[2]*R[8];

我也尝试multipliying accelerometervalues​​ 倾斜度矩阵I.与两个R也multipliying和我(trueaccel =加速* R * I)和没有工作无论是。也不对打电话来 remapcoordinates(),然后乘以任何的previous形式。

I have also tried multipliying accelerometervalues with the inclination matrix I. Also multipliying with both R and I (trueaccel=accel*R*I) and that didn't work either. Neither does calling to remapcoordinates() and then multiply in any of the previous forms.

没有任何人有什么我做错了的想法?

Does anybody have an idea about what am I doing wrong?

推荐答案

冲,我曾这样了数学上自己,所以请大家多多包涵。

Oki, I have worked this out mathematically myself so please bear with me.

如果你想翻译的加速度矢量 accelerationvalues​​ 成加速度矢量 trueacceleration EX pressed现实世界坐标,一旦你的方位,俯仰和横滚存储在 orientationvalues​​ 载体,只要做到以下几点:

If you want to translate an acceleration vector accelerationvalues into an acceleration vector trueacceleration expressed in real world's coordinates, once you have azimuth,pitch and roll stored in a orientationvalues vector, just do the following:

                trueacceleration[0] =(float) (accelerometervalues[0]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[2]*(-Math.sin(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])));
            trueacceleration[1] = (float) (accelerometervalues[0]*(-Math.cos(orientationvalues[2])*Math.sin(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.cos(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.cos(orientationvalues[0])) + accelerometervalues[2]*(Math.sin(orientationvalues[2])*Math.sin(orientationvalues[0])+ Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.cos(orientationvalues[0])));
            trueacceleration[2] = (float) (accelerometervalues[0]*(Math.sin(orientationvalues[2])*Math.cos(orientationvalues[1])) + accelerometervalues[1]*(-Math.sin(orientationvalues[1])) + accelerometervalues[2]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[1])));

这篇关于将来自设备的坐标加速度计的数据,以真实的世界坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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