传感器数据关于真正的北方机器人



我正在使用SensorEvent API,以便从不同的传感器(更具体地说:TYPE_ROTATION_VECTOR、TYPE_GRAVITY、TYPE_GYROSCOPE、TYPE_LINEAR_CCELERATION)获取应用程序的数据。现在,我知道在iOS中有一个所谓的CMAttitudeReferenceFrameXTrueNorthZVertical,它给出了所有传感器相对于正北的值,而z轴将始终是垂直的。

我在安卓系统中找不到类似的东西,所以我想手动翻译坐标系。我也在考虑使用remapCoordinateSystem方法。然而,我仍然不知道如何获得关于正北的数据。以前有人处理过类似的事情吗?

这个答案的灵感来自这里使用的类:

您应该在SensorEventListener 中具有onSensorChanged方法

@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
//get the rotation matrix from the sensor (this will be using the magnetic north)
SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
//change the coordinate system (your new matrix is in the variable mChangedRotationMatrix)
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
SensorManager.AXIS_MINUS_X, mChangedRotationMatrix);
//get the orientationMatrix of your new coordinate system
SensorManager.getOrientation(mChangedRotationMatrix, mOrientation);
//get the magnetic heading 
float magneticHeading = (float) Math.toDegrees(mOrientation[0]); 
//adjust accordingly by calculating the true north with either the "computeTrueNorth" method available the above link or the method used in the link below
}
}

为了获得真正的北方度数,你可以使用这个答案

相关内容

最新更新