Convert Adafruit BNO055 Quaternion Angles to Euler Angles

Hello all. I'm having trouble converting quaternion angles to euler angles. The sensor I'm using can be found here. In the FAQ section of that link they mention, "For absolute orientation, quaternions should always be used, and they can be converted to Euler angles at the last moment via the .toEuler() helper function in quaternion.h", however, they don't provide any examples for doing this.

I'm not sure how to use the .toEuler() helper function. Can someone point me in the right direction for how to use this function?

I've attached my sketch this post. It's basically an example that came with the IMU I'm using.

Thanks for the help.

test.ino (1.94 KB)

You don't need to convert the quaternion to Euler angles. You can simply read the Euler angles out of the BNO055. This is already in your code, but you commented out the print statements.

You might spend a few minutes glancing through the code and the documentation, before posting.

jremington:
You don't need to convert the quaternion to Euler angles. You can simply read the Euler angles out of the BNO055. This is already in your code, but you commented out the print statements.

You might spend a few minutes glancing through the code and the documentation, before posting.

It's disappointing when you ask a question on a site that is supposed to facilitate learning and you get an insulting response. You assume that I didn't notice that you can pull raw Euler data from the sensor. I am well aware of this. After all, I commented it out.

It is my understanding that Quaternion data is more accurate than Euler data and, as the quote I posted from the FAQ mentions, I am interested in absolute orientation which, again, as the FAQ mentions, should always be done with Quaternions.

Euler angles come with limitations in which the angles are not always continuous for all situations. By pulling Quaternion data first and then converting them to Euler angles, I should be able to remedy this. That is my goal and also the reason why I asked how to implement the .toEuler helper function.

In the future, don't assume that people are completely oblivious.

By pulling Quaternion data first and then converting them to Euler angles, I should be able to remedy this

No, you can't. Given a starting point, there are orientations that simply can't be uniquely represented by Euler angles.

However, if you want to try, it is simple enough to code the three lines required.

Hi, jremington,
you seem to be knowlegeable on this subject, could you give me a hint on how to impement Adafruit library quaternion.h ? I think this library has everything to use quaternions and turn those into angles for a stable navigation.
truely appreciate,
Johannes

Q's to E's:

``````float yaw   = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);
float pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
float roll = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);[/quote]
``````

how to impement Adafruit library quaternion.h

What do you want to do with the library? It is just a collection of basic mathematical operations.

In general, "stable navigation" can't be done using an angular representation of absolute orientation, because of gimbal lock or related problems. That is why everyone uses a quaternion for that purpose.

If you look in the repo for that library you'll see utility/quaternion.h and the constructor and
toEuler method are all you need.