将 IMU 的四元数值重置为 X:0,Y:0,Z:0,W:1

Reset quaternion values from IMU to X:0,Y:0,Z:0,W:1

我想 reset/remove 从实时 IMU 传感器记录中偏移四元数数据。例如。当我开始录制时,我得到 [-0.754, -0.0256, 0.0321, 0.324] (XYZW)。我想在开始录制时将其重置为 [0, 0, 0, 1],因为我正在使用它来旋转初始四元数值为 [X: 0, Y: 0, Z: 0, W: 1].

我尝试从第一个中减去所有四元数数据:

counter = 0

quat = getting_sensor_data_from_somewhere()
while True:

   if counter == 1:
      offset = quat

   calib_data = [x1 -x2 for x1, x2 in zip(quat, offset)

但是,这似乎不是正确的解决方案。我有点困惑为什么 W 应该是 1。你能帮我吗?

3D模型来自ThreeJS库。

关于设置为四元数的轴方程旋转的用法的很好的描述可以在这里找到:
http://wiki.alioth.net/index.php/Quaternion

引用

A quaternion is a set of four values (W X Y Z) that are used in Oolite to specify a rotation in 3D space. To specify a particular rotation you need to think about the axis about which the rotation is made and the angle or amount by which the model is to be rotated.

For a given axis (x y z) and angle (α), the quaternion representing a rotation of a degrees around the axis from the origin (0,0,0) to (x,y,z) is:

W = cos (0.5 × α)
X = x × sin (0.5 × α)
Y = y × sin (0.5 × α)
Z = z × sin (0.5 × α)

So a rotation of 90 degrees about the z axis (0 0 1) would be:

W = cos 45 ° = 0.707…
X = 0 × sin 45 ° = 0
Y = 0 × sin 45 ° = 0
Z = 1 × sin 45 ° = 0.707… 

这意味着您需要 select 不同的轴才能根据需要实现 [0,0,0,1] 的设置。

试试这个:

def quaternion_multiply(quaternion1, quaternion0):
    import numpy as np
    w0, x0, y0, z0 = quaternion0
    w1, x1, y1, z1 = quaternion1
    return np.array([-x1 * x0 - y1 * y0 - z1 * z0 + w1 * w0,
                     x1 * w0 + y1 * z0 - z1 * y0 + w1 * x0,
                     -x1 * z0 + y1 * w0 + z1 * x0 + w1 * y0,
                     x1 * y0 - y1 * x0 + z1 * w0 + w1 * z0], dtype=np.float64)

glob_quat = [1,0,0,0]
counter = 0

quat = getting_sensor_data_from_somewhere() # W,X,Y,Z order
while True:

   if counter == 0:
       quat_first = [quat[0], -quat[1], -quat[2], -quat[3]]
       offset = quaternion_multiply(glob_quat, quat_first)

   quat_calib = quaternion_multiply(offset, quat)
   
   # Now first quat will always be [1, 0, 0, 0]
   # Shift places if W is at the end instead of in the start