2

I would like to reset/remove offset quaternion data from real-time IMU sensor recordings. E.g. I get [-0.754, -0.0256, 0.0321, 0.324] (XYZW) when I start recordings. I would like to reset this to be [0, 0, 0, 1] when I start recording, as I am using it to rotate a 3D object which initial quaternion values are [X: 0, Y: 0, Z: 0, W: 1].

I tried subtracting all quaternion data from the first as so:

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)

However, it doesn't seem to be the right solution. I am a bit confused of why W should be 1. Can you help me?

The 3D model are from ThreeJS libraries.

2 Answers 2

3

Try this out:

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
Sign up to request clarification or add additional context in comments.

2 Comments

isn't glob_quat just the identity quaternion? If so, wouldn't quaternion_multiply(glob_quat, quat_first) just be equal to quat_first (which is the conjugate of quat)?
from testing it seems like my comment is correct. I suppose if glob_quat was not the identity quaternion, then maybe that extra multiplication would be necessary. also as a general comment you never increment counter. Thanks!
0

Nice description of usage of equation rotation about axis set as quaterion can be found here:
http://wiki.alioth.net/index.php/Quaternion

quote

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… 

That mean You need to select different axis to achieve the setting to [0,0,0,1] as desired.

1 Comment

I am not trying to rotate quaternions to a specific angle but thanks for the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.