0

I am using a BNO055 to get quaternion values. I want to get the rotation quaternion between quaternions and extract only the rotation over the x axis.

I am starting at a initial position (The x axis of the sensor aligned to the edge of a table) and getting initial normalized quaternion values (q1) then, as I roll the sensor I used the quaternions (q2) to calculate the rotation quaternion by multiplying q2*q1.inverse. Finally, to extract the angle of rotation I used the formula: θ = 2acos(q0), where q0 is the w component of the rotation quaternion. If I only roll the sensor, the angle is pretty accurate, however, if I yaw or pitch the sensor, the angle sum up the rotations over the y and z axis. I want in some way to isolate rotations over the y and z axis to only get rotations over the x axis. I tried getting the angle from the x component by using: θ = 2asin(q1), as well converting the rotation quaternion into its Euler-angles representation:

    double sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
    double cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
    angles_roll = atan2(sinr_cosp, cosr_cosp);

Even though, it seemed calculating the right angle, when I pitched or yawed it, it was still summing some angle.

Maybe the approach I am seeking is not the correct one, so I wanted to consult it with you. Perhaps creating a global coordinate system and transforming the quaternion to the global coordinates? But I don't have a clear path for that approach.

0 Answers0