2

I am struggling to get my head around what I believe should be a simple problem.

I am getting a quaternion wxyz from an IMU (inertial measurement unit), I want to check the angle between the quaternion and a given unit vector.

I am very new to understanding quaternions but from doing research I understand the steps to be as follows

  • Let $A$ be the quaternion from the IMU
  • Let $B$ be the quaternion created from my target vector but with a scalar (W) of zero.
  • Calculate $C = A*conj(B)$
  • Calculate $\theta = 2 * atan2(norm(C_{xyz}),C_w)$

This appears to almost work but is sensitive to rotation of the axis not just the direction it is pointed at. I feel this kind of makes sense based on the result C being a transformation to get from A to B, but I don't know how to remove one axis of sensitivity in my result.

Hugoagogo
  • 131
  • Welcome to the site. It would be better if you could type your formulas in MathJax, see here for a tutorial: https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference – Captain Lama Feb 22 '22 at 14:07
  • Sorry, an IMU is an inertial measurement unit. So to get the number I am after is it more a case of I should be somehow extracting a vector from the quaternion and going from there or should I be applying some extra operations to get rid of the axis I don't want to compare. – Hugoagogo Feb 22 '22 at 14:31
  • I am still baffled. Exactly what angle are you supposed to calculate. We can define angles in 4D space, but somehow I suspect that you are looking for an angle between two 3D-vectors. – Jyrki Lahtonen Feb 22 '22 at 14:35
  • Your $C$ is another quaternion. It describes the rotation you get by first doing a 180 degree rotation about the vector yielding the quaternion $B$ followed by the rotation from the IMU. That combined rotation then has an axis and an angle of rotation. $\theta$ seems to be angle of that combined rotation. Is this the angle you wanted to calculate? – Jyrki Lahtonen Feb 22 '22 at 14:41
  • Big picture what I am trying to figure out is how to take the quaternion spat out by my IMU and a vector and figure out how well they are aligned not caring about rotation about the axis. You are right I am more or less trying to get back to the angle between two vectors. But I don't know how to convert my quaternion back to being a vector. Will need to pick this up in the morning, have stayed up way too late trying to crack it. – Hugoagogo Feb 22 '22 at 14:48
  • Sorry about being an algebraist. I really should look at one of the programming books one of these days to be more familiar with your problems. Is the idea to calculate how much the vector $B$ turns when the rotation from IMU is applied to it? Or to calculate the angle between $B$ and the axis of rotation? – Jyrki Lahtonen Feb 22 '22 at 14:55
  • Can you give an example situation where you know what the angle will be? A numerical one? – Jyrki Lahtonen Feb 22 '22 at 14:56
  • For example, if $A_{xyz}$ is a very short vector, it means that the rotation between the frame given by the IMU and the frame of reference is very "small". Like may be the rotation was only a 1 degree turn (when the axis of rotation is nearly irrelevant as nothing much happened). The IMU still gives an estimate for axis. But do you expect a small angle under such circumstances irrespective of the vector $B$? Or is $B$, perhaps, supposed to be a different estimate for the axis of rotation, when the angle can be very large, if the IMU estimate is inaccurate. – Jyrki Lahtonen Feb 22 '22 at 15:05
  • Or may be an example, where the angle your recipe gives is sensible, and another where it is off? – Jyrki Lahtonen Feb 22 '22 at 15:07
  • The formula you gave is seen in this question. It is the angle of the rotation of the combined rotation described in my second comment. – Jyrki Lahtonen Feb 22 '22 at 15:10
  • Or may be something in here? It is really difficult to say. I can imagine that some texts don't make the roles played by vectors and quaternions very clear, which probably contributes to the confusion. Also, some people (even very smart ones!) have a hard time visualizing 3D-rotations, because their book intuition mostly comes from 2D-rotations. – Jyrki Lahtonen Feb 22 '22 at 15:17
  • Still struggling. For lack of a better way to describe what I am after, imagine you have a laser pointer who's rotation in space is defined by the quaternion $A$ and I know the vector required to point the laser a target. I am trying to compute the angular error between the laser and the target where the rotation of the laser about its axis isn't important. My current algoithum is sensitive to the rotation of the laser about its axis such that It can be pointing at the right spot at on the wall, but still return up to 180 degrees error because of rotation about the beam. – Hugoagogo Feb 23 '22 at 01:03
  • A laser pointer has a direction in space in which it points, not a "rotation". A direction requires only two parameters to define, but a quaternion has four. In order to answer this question, we need to know more than "the IMU produces this quaternion". We need know what that quaternion is telling you. How is it defined? – Paul Sinclair Feb 23 '22 at 05:24
  • The library doesn't give much further description beyond being a quaternion defined in $WXYZ$. I understand this includes rotation information, picturing as defining the full rotation of the physical object of the laser pointer, but for what I am after only the direction is important. Is there an easy way to go from describing full rotation to only direction? – Hugoagogo Feb 23 '22 at 08:01

0 Answers0