0

I need to rotate acceleration data with the quaternion result of a ahrs. Initially, I tried to implement a very simple attitude estimator in C# (IMU Attitude Estimation from Angular Velocity rotates by roughly half the expected value. Why?), but that didn't produce the results I need. Hence, I decided to give the ahrs package in Python a try. Before actually feeding the system sensor data, though, I just want to understand the handling. Therefore, I am just rotating a vector (up = [0.,1.,0.]) with a Quaternion by 90 degree around the z axis. What I expect is a vector that points along the negative x-axis. What I get is the positive z-axis. Can anyone explain what I am missing?

# -*- coding: utf-8 -*-
"""
Created on Tue Jul  5 16:17:04 2022

"""

from ahrs.filters import Madgwick
from ahrs import Quaternion
from ahrs import DEG2RAD    # Helper variable to convert angles to radians
import numpy as np


angles = np.array([0.0, 0.0, 90.0])*DEG2RAD
q = Quaternion(rpy=angles)
print(q)
up = [0.,1.,0.]
left = q.rotate(up)
print (left)

Result

!next
[ 0.00000000e+00 -2.22044605e-16  1.00000000e+00]
--Return--
  • What is the result of the print(q)? – James Tursa Jul 20 '22 at 02:08
  • @JamesTursa it's (0.7071 +0.7071i +0.0000j +0.0000k), which looks like it's roughly a 45 degree rotation. Now I recall that the half angle is usually used with quaternions since the rotation comes as q*v*q^(-1), but then if there's a function rot, I believe that should be taken care of... – Lukas Pezenka Jul 20 '22 at 12:54
  • 1
    I am not familiar with ahrs, but what I observe is the 90 is being interpreted as a roll angle and not a yaw angle. Maybe the rpy are interpreted in reverse order right-to-left? Does using a [90 0 0] angles result in 0.7071k and a [-1 0 0] rotated vector? I.e., is a 90 in the first spot being interpreted as a yaw angle? – James Tursa Jul 20 '22 at 16:58
  • @JamesTursa Thank you very much! You're right - rotating with a switched order of angles actually behaves as you expected.. Now that you mention it, I do remember reading about this somewhere. Thank you for your insight, this really helps me get along with my project.! – Lukas Pezenka Jul 22 '22 at 11:36

0 Answers0