C#中使用四元数表示陀螺仪角度
我正在使用 WiiM+ 陀螺仪来计算旋转。
我对沿偏航轴、俯仰轴和横滚轴的转动速率进行积分,并将其存储在名为 angleSum 的向量中,
因此对于每个读数,angleSum(reading) 表示相对于初始方向的 y、p 和 r 旋转。
然后我使用四元数(我完全不熟悉)来表示如下:
q = Quaternion.createfromyawPitchRoll(angleSum.yaw,angleSum.pitch,angleSum.roll*(-1))
但是当我将 Wiimote 旋转 90 度时一个方向并打印出转弯的 qx、qy 和 qz,所有读数都受到转弯的影响(它们都显示 90 度转弯和返回,尽管其中两个的幅度较小)
我的问题非常基本:到底如何做我用这个四元数结构来表示方向?我需要在偏航、俯仰和滚动方面的绝对(或至少相对)方向。
谢谢!
I'm using the WiiM+ gyro to calculate rotation.
I integrate the rates of turn along the yaw, pitch and roll axes and store it in a vector called angleSum
So for each reading, angleSum(reading) represents the y, p and r rotations from the initial orientation.
I then use quaternions (which I'm totally unfamiliar with) to represent like this:
q = Quaternion.createfromyawPitchRoll(angleSum.yaw, angleSum.pitch, angleSum.roll*(-1))
But when I turn my wiimote 90 degrees in a direction and print out q.x, q.y and q.z for the turn, ALL readings are affected by the turn (they all show a 90 degree turn and back, although magnitude is smaller for two of them)
My question is very basic: how exactly do I use this quaternion structure to represent orientation? I need an absolute (or atleast relative) orientation in terms of yaw, pitch and roll.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
四元数是一个四维结构,松散地定义为一个轴和一个旋转分量围绕定义的轴(通常表示为
{x, y, z, w}
)。看看您引用的方法,我假设您以弧度而不是度数提供偏航、俯仰和滚转。这将从表中消除最常见的实施错误。假设您的实现是正确的(看起来是正确的),
qx
、qy
和qz
都将随着任何旋转而发生预期的变化。请记住,您正在定义一个四维对象;四元数与欧拉角不同。如果如果您想要以更人性化的欧拉表示法获得读数,请考虑将四元数转换回偏航、俯仰和滚动。 这里有关于在 XNA 中执行此操作的讨论。
A quaternion is a four-dimensional construct loosely defined as an axis and a rotational component around the defined axis (usually represented as
{x, y, z, w}
). Having a look at the method you've referenced, I'll assume you're supplying yaw, pitch, and roll in radians instead of degrees. That'll remove the most common implementation mistake from the table.Assuming your implementation is correct (and it seems to be),
q.x
,q.y
, andq.z
will all expectedly change with any rotation. Remember, you're defining a four-dimensional object; quaternions are not the same as Euler angles.If you'd like to get a readout in more human-friendly Euler notation, consider converting your quaternion back into yaw, pitch, and roll. Here's a discussion for doing so in XNA.