如何检测Android设备的绝对旋转 [英] How to detect an absolute rotation of an android device

查看:353
本文介绍了如何检测Android设备的绝对旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用在Android设备上运行的软件实现在室内导航的机器人.一种强制性的功能是实时"知道机器人的方向.

我有一个主要限制:android设备应该放在重力斧上的屏幕上(这意味着:垂直,就像用设备上的相机拍照一样)

这使我无法使用方位角,这是获取参考角的最常用方法.使用没有道理:

SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector, event.values);

然后

SensorManager.getOrientation(mRotationMatrix, orientation);

因为应该提供方位角的方向[0] 不一致.

我已经搜索了很长时间,但是在这里找不到任何可接受的解决方案.

可接受的解决方案"是使系统响应在100毫秒内,且精度接近5°.参考不一定是磁性北极,但它必须在一段时间内保持稳定.它可以是一个起始位置(但是存在一些漂移问题...)

除此类型的传感器以外,是否还有其他类型的传感器? TYPE_ROTATION_VECTOR ?我尝试使用 TYPE_GYROSCOPE ,但效果不佳...

我的android设备是Google Tango平板电脑.

感谢您的帮助

解决方案

如果您只关心任何参考系中的方位角,那么Tango提供的信息就是您想要的-具体来说,此处. >

这个问题也应该有一个简单的答案.磁力计传感器应该能够提供平板电脑相对于地球磁场的绝对方向,该磁场大致指向北方-这几乎是任何Android设备都可以做到的.您可以从三个原始磁力计传感器值构造自己的方向,但是Android提供了一种更便捷的方式来访问融合传感器: SensorManager .但是, Tango平板电脑存在软件问题,导致其磁力计无法正常工作;有关更多详细信息,请参见此处.真令人失望的是,专门为导航设计的设备无法确定其绝对方位.

如果SensorManager的TYPE_ROTATION_VECTOR确实可以在Tango平板电脑上工作,则可以使用SensorManager.getRotationMatrixFromVector从onSensorChanged返回的四元数中获取3x3旋转矩阵,然后使用SensorManager.getOrientation获取设备的方位角"(如您所指出的)在您的问题中).但是,此方法有些局限性,因为当平板电脑的屏幕朝上时,该方法具有木框锁.当您选择自己的矢量并使用四元数将其旋转为世界坐标,然后根据三个坐标中的两个坐标来计算方位角时,可以更加精确地确定方位角"的确切含义.

I'm looking to implement a robot that is navigating indoor, using a software running on an android device. One mandatory feature is to know the robot orientation in "real time".

I have one major constraint : the android device should be placed with a screen on the gravity axe (that means : vertical, like for taking pictures with the camera on the device)

This prevents me from using azimut which is the most common measure to get a reference angle. It makes no sense to use :

SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector, event.values);

then

SensorManager.getOrientation(mRotationMatrix, orientation);

since orientation[0] supposed to provide azimut is inconsistent.

I was searching for longtime now, but I didn't find any acceptable solution over here.

An "acceptable solution" is to have a system response within 100ms and with a precision close to 5°. The reference is not necessarily the magnetic North, but it must be stable over the time. It can be a starting position (but there are some drift issues...)

Are there any sensors of other type than TYPE_ROTATION_VECTOR more situable for this use ? I was trying with TYPE_GYROSCOPE but with poor results...

My android device is the Google Tango tablet.

Thanks for any help

解决方案

If you only care about azimuth in any reference frame, then the information provided by Tango is what you want -- specifically, the TangoPoseData provided by Tango.OnTangoUpdateListener.onPoseAvailable (after requesting the frame pair COORDINATE_FRAME_AREA_DESCRIPTION, COORDINATE_FRAME_DEVICE) contains a quaternion expressing the device orientation relative to the area description frame of reference. A quaternion is basically a rotation operation. If you pick a desired vector in the device's frame (for instance, a vector pointing out of the screen), the quaternion will allow you to rotate that vector into the area description (world) frame of reference. That rotated vector is the direction the original vector is pointing in the world, and you can determine azimuth by taking atan2 of the two horizontal components of the vector. For more information on Tango's reference frames, see here.

There should be a simpler answer to this question also. The magnetometer sensors should be able to provide an absolute orientation of the tablet relative to the Earth's magnetic field, which is pointed roughly north -- this is something pretty much any Android device can do. You could construct your own orientation from the three raw magnetometer sensor values, but Android provides a much more convenient way to access the fused sensors: Sensor.TYPE_ROTATION_VECTOR from SensorManager. However, the Tango tablet has a software issue that prevents its magnetometers from working; see here for more details. It's really disappointing that a device designed specifically for navigation would have no way of determining its absolute azimuth.

If SensorManager's TYPE_ROTATION_VECTOR did work on a Tango tablet, you could use SensorManager.getRotationMatrixFromVector to get a 3x3 rotation matrix from the quaternion returned in onSensorChanged, and then get the "azimuth" of the device using SensorManager.getOrientation (as you indicated in your question). However, this approach is somewhat limiting as that approach has gimbal lock when the tablet's screen is facing upward. When you pick your own vector and rotate it into world coordinates using a quaternion then compute azimuth based on two of the three coordinates, that allows you to be much more specific about what exactly you intend for "azimuth" to mean.

这篇关于如何检测Android设备的绝对旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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