计算参考真北加速度加速度、真北

2023-09-13 23:58:26 作者:王:王中王,小王旺旺旺,头戴王冠

有关我的应用程序,我需要计算参照真北我的设备的加速。我的想法是计算设备的方向磁北,磁偏角适用于它来获得方向正北。然后我想计算设备的加速,并参考了方向,但我不知道我应该怎么做。

For my App I need to calculate the acceleration of my device in reference to true north. My idea was to calculate the device orientation to magnetic north and apply the declination to it to get the orientation to true north. Then I want to calculate the acceleration of the device and reference it to the orientation, but I do not know how I should do this.

我会尝试让使用设备的方向 SensorManager.getRotationMatrix() SensorManager.getOrientation()。然后,我得到的偏角通过 GeomagneticField.getDeclination()的方向值的方位应用它SensorManager.getOrientation()

I would try to get the device orientation using SensorManager.getRotationMatrix() and SensorManager.getOrientation(). Then I get the declination by GeomagneticField.getDeclination()and apply it on the azimuth of the orientation values from SensorManager.getOrientation().

但我怎么映射加速度值这个方向?它甚至有可能?

But how do I map the accelerometer values to this orientation? Is it even possible?

推荐答案

加速度传感器返回设备的加速。这是在3维空间中的向量。这个载体是在设备坐标系统返回。你想要的是这个载体在世界的坐标的坐标,这简直就是

The accelerometer sensor returns the acceleration of the device. This is a vector in 3 dimentional space. This vector is returned in the device coordinate system. What you want is the coordinate of this vector in the world coordinate, which is simply

R = rotation matrix obtained by calling getRotationMatrix
A_D = accelerator vector return by sensor ( A_D = event.values.clone )
A_W = R * A_D is the same acceleration vector in the world coordinate system.

A_W is an array of dimention 3 
A_W[0] is acceleration due east.
A_W[1] is acceleration due north.

下面是一些code计算它(假定重力包含输出从各自的传感器):

Here is some code to compute it (assumes gravity and magnetic contain output from their respective sensors):

            float[] R = new float[9];
            float[] I = new float[9];
            SensorManager.getRotationMatrix(R, I, gravity, magnetic);
            float [] A_D = values.clone();
            float [] A_W = new float[3];
            A_W[0] = R[0] * A_D[0] + R[1] * A_D[1] + R[2] * A_D[2];
            A_W[1] = R[3] * A_D[0] + R[4] * A_D[1] + R[5] * A_D[2];
            A_W[2] = R[6] * A_D[0] + R[7] * A_D[1] + R[8] * A_D[2];