Android 方向传感器的奇怪行为
目前,我正在尝试使用 getRotation() 方法使用方向传感器值旋转 3D 立方体。当 Android 设备旋转超过一定范围时,会观察到一些意外行为。例如,如果我让设备“站立”,“滚动”的价值就会变得疯狂。
我也遇到了类似于所谓的万向节锁的现象。唯一的区别是,即使在将传感器值应用于 3D 旋转之前,我也遇到了这个问题。当我尝试通过仅围绕“俯仰”轴旋转设备来更改“俯仰”值时,“偏航”值也会根据俯仰的旋转而变化。对我来说这似乎完全不合理。
有人可以帮助我吗?我被这个问题困扰了一个月。
Currently, I'm trying to rotate 3D Cube using orientation sensor values, using getRotation() method. Some unexpected behaviors are observed when the android device is rotated above some bounds. For instance, if I make the device 'stand up', the value of the 'roll' just becomes crazy.
Also I'm experiencing the phenomenon similar to so-called gimbal-lock. The only difference is I'm experiencing the very problem even before applying the sensor values to the 3D rotation. When I try to change the 'pitch' value by rotating the device around only 'pitch' axis, the 'yaw' value also changes according to the rotation of the pitch. It seems completely unreasonable to me.
Could somebody help me?? I'm stuck in this problem for a month.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是偏航、俯仰和滚转的常见问题。只要您使用偏航、俯仰和滚转(欧拉角),就无法摆脱它。 此视频解释了原因。
我在运动传感应用程序中使用旋转矩阵而不是欧拉角。有关旋转矩阵的介绍,我建议:
方向余弦矩阵 IMU:理论
旋转矩阵的工作原理就像一个魅力。
四元数也很受欢迎,据说是最稳定的。
[此答案是从此处复制的。]
This is a common problem with yaw, pitch and roll. You cannot get rid of it as long as you are using yaw, pitch and roll (Euler angles). This video explains why.
I use rotation matrices instead of Euler angles in my motion sensing application. For an introduction to rotation matrices I recommend:
Direction Cosine Matrix IMU: Theory
Rotation matrices work like a charm.
Quaternions are also very popular and said to be the most stable.
[This answer was copied from here.]
使用四元数来计算 YPR 对于解决任何问题都没有多大帮助。万向节锁定问题(接近+/-90的俯仰角可以驱动偏航和滚转——实际上是在北极的偏航滚转——在底层四元数的轻微变化/噪声下变得疯狂)。
但是,如果您使用 Yaw Pitch 和 Roll 值来执行 3D 对象的旋转,则在万向节锁定位置附近不应表现出任何奇怪的行为。只是偏航和滚转出现了模糊性,偏航和滚转的巨大变化并不意味着实际方向变得疯狂——只是方向对接近 90 度的偏航滚转的巨大变化不敏感。
但是,还要注意HTML5 的手机和浏览器无法按照 Android 惯例正确实现偏航、俯仰和滚动。这是一个很好的博客供参考:
http://www.sensorplatforms.com/理解导向约定移动平台/
Using quaternions to compute YPR won't do much to solve any problem. The problem of gimbal lock (which near pitch of +/-90 can drive yaw and roll -- actually yaw-roll at the north pole -- to go crazy under slight changes/noise in the underlying quaternion).
However, if you use Yaw Pitch and Roll values to perform a rotation of a 3D object shouldn't exhibit any odd behavior near the gimbal lock position. It's just that an amibguity in yaw and roll arise and large variations in yaw and roll do not imply the actual orientation is going crazy -- just that the orientation is insensitive to large changes in yaw-roll near pitch of 90.
BUT, also note that phones and browsers for HTML5 do not properly implement yaw, pitch and roll per conventions for Android. Here is a good blog for reference:
http://www.sensorplatforms.com/understanding-orientation-conventions-mobile-platforms/
这是一个基本示例,这将返回重力矢量。请注意,您可以更改传感器类型和采样速度,更多详细信息此处
Here is a basic example, this will return the vector of gravity. Note that you can change the sensor type and the speed of sampling, more details here
好吧,如果你在手机上运行。
四元数是最好的,你应该使用它
对于旋转矩阵和欧拉角,你很容易遇到一个叫做万向节锁的术语。由于用户的暴力行为,这种情况经常发生。
万向节锁定是指在三维、三万向节机构中失去一个自由度,当三个万向节中的两个的轴被驱动成平行配置时发生,“锁定”系统以简并二向旋转。次元空间。
旋转矩阵和欧拉角有利于缓慢移动的机器人动作。
有关四元数串联和将点转换为新系统的详细信息,
您可以参考wiki链接
https://en.wikipedia.org/wiki/Quaternion
Well if you running on the phone.
Quaternions are the best, and you should use it
For rotation matrix and euler angle, you can easily came across such term called gimbal lock. It happens frequently with user violent action.
Gimbal lock is the loss of one degree of freedom in a three-dimensional, three-gimbal mechanism that occurs when the axes of two of the three gimbals are driven into a parallel configuration, "locking" the system into rotation in a degenerate two-dimensional space.
Rotation matrix and euler angle are good for slow moving robot action.
For details on quaternions concatnations and convert point to new system,
you can refer to wiki link
https://en.wikipedia.org/wiki/Quaternion