Find the angle between two 9-DOF IMU sensors regardless of the orientation in space

I have two 9-DOF IMU BNO-055 sensors. I need to get the angles between these sensors (the first sensor is in a stable position, the second moves and changes its position). An example of such an angle, I presented in the image below.

These sensors give me 2 quaternions, which I multiply (q1 * q2^-1) and get a new quaternion.

Quaternion quaternion_invert(Quaternion q) {
    Quaternion res;
    res.w = q.w;
    res.x = -q.x;
    res.y = -q.y;
    res.z = -q.z;
    return quaternion_normalize(res);
}

Quaternion quaternion_mult(Quaternion a, Quaternion b) {
    Quaternion res;
    res.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;
    res.x = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y;
    res.y = a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x;
    res.z = a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w;
    return res;
}

From this quaternion I get the desired angle using the formula:

angles.from_x = 2 * atan2 (quat.x, quat.w) * (180.0 / 3.141592653589793238463);

This works well if the sensors are placed in one position. If this device changes position in space, I stop getting the right angles.

How can I fix it?

An arbitrary change in 3D orientation cannot be represented by just one angle. More information is required.

There are various ways of representing the general transformation relating two quaternions, and these are discussed in many tutorials on the web.

BTW the BNO055 sensors are not very accurate, but you probably know that.

Not to hijack this thread but what is your opinion of the accuracy of the BNO085 sensor?

BNO055 repeatability tests (nothing has changed since): BNO055 Possible use in +/- 1.0 deg pointing system - adafruit industries

As pointed out an an orientation or rotation in 3D is not an angle. Its a unit-quarternion(*) - you simply divide quarternions to give the relative orientation between them, just like multiplying quarternions to compose orientation changes (3D rotation).

(*) You can represent also as a DCM, but that's much clumsier. Unit quaternions have a scaler part and a vector part and the vector part directly provides a vector along the axis of 3D rotation. You cannot dodge the maths for 3D rotations alas, intuition is usually wrong.
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

Note that after doing the division you can extract the axis of rotation and amount of rotation (which may be what you want) from the resultant quaternion. You are multiplying quaternions though.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.