0

BN055 Vertical Orientation
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BN055 Vertical Orientation

by ppecch on Mon Jun 14, 2021 12:31 pm

Hi I'm currently working on a thrust vector gimbal for model rockets, using the Adafruit BNO055 and I need to position the IMU vertically, is this possible and how do you write the code the remap the axes? I'm using quaternions and PID algorithm to control the servos which works great in the horizontal position but if I orient the IMU as per my picture it miss aligns that gimbal. I'm assuming if I swap the X and Z axes that would do the trick but I have no clue how to approach this. Any assistance would be appreciated.
Attachments
IMG_2632.jpg
IMG_2632.jpg (80.05 KiB) Viewed 304 times

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by dastels on Mon Jun 14, 2021 2:44 pm

From the FAQ https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/faqs
Does the device make any assumptions about its initial orientation?
You can customize how the axes are oriented (i.e. swap them around, etc.) but the Adafruit Arduino library doesn't expose it right now. Check out section 3.4 Axis Remap of the BNO055 datasheet for info on the registers to adjust its orientation: https://www.adafruit.com/datasheets/BST ... 000_12.pdf

Another thing to be aware of is that until the sensor calibrates it has a relative orientation output (i.e. orientation will be relative to where the sensor was when it powered on).

A system status value of '0' in NDOF mode means that the device has not yet found the 'north pole', and orientation values will be relative not absolute. Once calibration and setup is complete (system status > '0') the heading will jump to an absolute value since the BNO has found magnetic north (the system calibration status jumps to 1 or higher). See the Device Calibration page in this learning guide for further details.

dastels
 
Posts: 6858
Joined: Tue Oct 20, 2015 3:22 pm

Re: BN055 Vertical Orientation

by ppecch on Mon Jun 14, 2021 3:09 pm

Yes, in my loop I run the script below and go through the motions to calibrate the system.

void loop() {

//BNO055 Calibration//

uint8_t system, gyro, accel, mag = 0;
bno.getCalibration(&system, &gyro, &accel, &mag);
Serial.print("CALIBRATION: Sys = ");
Serial.print(system, DEC);
Serial.print(" Gyro = ");
Serial.print(gyro, DEC);
Serial.print(" Accel = ");
Serial.print(accel, DEC);
Serial.print(" Mag = ");
Serial.println(mag, DEC);

I find the Bosch datasheet overly confusing and doesn't do a good job of clarify how to remap the axes. I was hoping someone in the community had an example code to share?

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by dastels on Mon Jun 14, 2021 3:41 pm


dastels
 
Posts: 6858
Joined: Tue Oct 20, 2015 3:22 pm

Re: BN055 Vertical Orientation

by ppecch on Mon Jun 14, 2021 4:04 pm

Thanks Dave, I'll have a look at these resource and if I can get it working I'll post the modifications on this forum for others to reference.

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by sj_remington on Mon Jun 14, 2021 4:10 pm

If you are using the raw sensor data, in the code you may simply permute the indices in all the subsequent mathematical formulas as follows:
x, y, z -> z, x, y -> y, z, x
That preserves the handedness of the coordinate system, which is essential when obeying navigational conventions.

For example, the conventional formula for pitch and roll Euler angles from accelerometer data can be remapped to:
Code: Select all | TOGGLE FULL SIZE
  roll = atan2(y, z) * 57.3; //about x
  pitch = atan2((- x) , sqrt(y * y + z * z)) * 57.3;  //about y
 
 // replace x, y, z -> z, x, y
 
  roll = atan2(x, y) * 57.3; //about z
  pitch = atan2((- z) , sqrt(x * x + y * y)) * 57.3;  //about x
 
//  replace x, y, z -> y, z, x
 
  roll = atan2(y, z) * 57.3; //about y
  pitch = atan2((- x) , sqrt(y * y + z * z)) * 57.3;  //about z

sj_remington
 
Posts: 95
Joined: Mon Jul 27, 2020 4:51 pm

Re: BN055 Vertical Orientation

by ppecch on Mon Jun 14, 2021 4:27 pm

sj_remington » Ok that makes sense, I'm pulling the quaternions from the IMU and my calculations are below, can I use the same approach?

Code: Select all | TOGGLE FULL SIZE
  float yy = quat.y() * quat.y();
  float roll = -1*atan2(2 * (quat.w() * quat.x() + quat.y() * quat.z()), 1 - 2 * (quat.x() * quat.x() + yy));
  float pitch = asin(2 * quat.w() * quat.y() - quat.x() * quat.z());
  float yaw = atan2(2 * (quat.w() * quat.z() + quat.x() * quat.y()), 1 - 2 * (yy + quat.z() * quat.z()));
 
  float rollDeg  = 57.2958 * roll;
  float pitchDeg = 57.2958 * pitch;
  float yawDeg   = 57.2958 * yaw;

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by sj_remington on Mon Jun 14, 2021 7:48 pm

Yes, if you are very careful to redefine the sensor axes and the definitions of pitch and roll in the way I've outline above, using strict cyclic permutation, it works.

X, Y and Z are arbitrary labels (or they will be, if the sensor is properly calibrated). However, my experience with the BNO055 has been that the automatic calibration is far from satisfactory, and I gave up on it long ago.

However, you should be able to convince yourself that cyclic axis permutation works, just by playing with the sensor on the bench. If you swap just two axes, a lot of signs have to change.

By the way, at one point I tried to take advantage of the axis redefinition options built in to the BNO055 firmware, and could not get the correct answers. I was convinced that the firmware is wrong, at least for my case. Perhaps if you choose a different option it would work correctly.

sj_remington
 
Posts: 95
Joined: Mon Jul 27, 2020 4:51 pm

Re: BN055 Vertical Orientation

by gammaburst on Mon Jun 14, 2021 8:33 pm

My two cents:

I found the two axis remap registers easy to use *after* I abandoned using Adafruit's or SparkFun's libraries, and *after* I noticed the confusing twist in the orientation diagrams in the BNO datasheet. Note the "P1 (default)" value and its diagram that's rotated 90 degrees from the diagram on the previous page - correct but confusing. Also beware possibly mixed-up axes in Adafruit's sensor library (I forget the details).

Instead of using a sensor library, I created this BNO055 startup procedure and sent the simple I2C commands myself. My method may or may not be adequate for your project.
viewtopic.php?f=25&t=108290&p=541754#p541754

dastels: your PDF link is trying to point to a long-outdated version 1.2 of the BNO055 datasheet. Everyone, be sure to use current version 1.4, dated June 2016.

More tips:
Yes Bosch's datasheet is inadequate and confusing.
Flipping axes around trying to "get things right" does work but is VERY confusing (to me).
Beware of broken Euler angles from the BNO055! Read its quaternion instead.
Beware the 4g limit on acceleration if you use a fusion mode such as quaternion.
Beware BNO055 fusion mode auto-recalibrates itself at unexpected times and sometimes poorly.

gammaburst
 
Posts: 579
Joined: Thu Dec 31, 2015 12:06 pm

Re: BN055 Vertical Orientation

by jps2000 on Tue Jun 15, 2021 12:29 am

Maybe you need just a fast gyro for your purposes
https://v2rockethistory.com/gyroscope-guides-rocket/

jps2000
 
Posts: 638
Joined: Fri Jun 02, 2017 4:12 pm

Re: BN055 Vertical Orientation

by ppecch on Tue Jun 15, 2021 6:45 pm

sj_remington » so I'm pulling the quaternions from the IMU and using a rotation matrix

And this the conversation for XYZ are as follows:

Code: Select all | TOGGLE FULL SIZE
imu::Quaternion quat = bno.getQuat(); //Request Quaternions From Sensor
 
  float roll = atan2(2*(quat.y() * quat.z()) + 2*(quat.w() * quat.x()), pow(quat.w(),2) - pow(quat.x(),2) - pow(quat.y(),2) - pow(quat.z(),2));
  float pitch = -1*asin(2*(quat.x() * quat.z()) - 2*(quat.w() * quat.y()));
  float yaw = atan2(2*(quat.x() * quat.y()) + 2*(quat.w() * quat.z()), pow(quat.w(),2) + pow(quat.x(),2) - pow(quat.y(),2) - pow(quat.z(),2));
 
  float rollDeg  = 57.2958 * roll;
  float pitchDeg = 57.2958 * pitch;
  float yawDeg   = 57.2958 * yaw;


Then if I cycle the permutation to XZY I get the following:

Code: Select all | TOGGLE FULL SIZE
imu::Quaternion quat = bno.getQuat(); //Request Quaternions From Sensor
 
  float roll = atan2(-2*(quat.y() * quat.z()) + 2*(quat.w() * quat.x()), pow(quat.w(),2) - pow(quat.x(),2) + pow(quat.y(),2) - pow(quat.z(),2));
  float pitch = asin(2*(quat.x() * quat.y()) - 2*(quat.w() * quat.y()));
  float yaw = atan2(-2*(quat.x() * quat.z()) + 2*(quat.w() * quat.y()), pow(quat.w(),2) + pow(quat.x(),2) - pow(quat.y(),2) - pow(quat.z(),2));
 
  float rollDeg  = 57.2958 * roll;
  float pitchDeg = 57.2958 * pitch;
  float yawDeg   = 57.2958 * yaw;


Then I position the IMU vertically and its not working as expected. Any suggestions?

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by sj_remington on Tue Jun 15, 2021 7:47 pm

XZY is not a valid cyclic permutation.

I don't understand what you tried to do with the quaternion, but you should not need to change any of those formulas.

Instead, the labels of the axes about which yaw, pitch and roll are defined change (following the cyclic permutation).

The formulas depend on how those angles are defined in the first place. There are six conventions for Euler angles, and six for Tait-Bryan. See https://en.wikipedia.org/wiki/Euler_angles Which convention are you using?

Don't forget that the order in which the rotations are applied is central to the definition.

sj_remington
 
Posts: 95
Joined: Mon Jul 27, 2020 4:51 pm

Re: BN055 Vertical Orientation

by ppecch on Tue Jun 15, 2021 9:30 pm

Well I was attempting to use the the quaternion matrix.

I started with ...

xyz.JPG
XYZ
xyz.JPG (16.47 KiB) Viewed 191 times


to this...

xzy.JPG
xzy
xzy.JPG (16.29 KiB) Viewed 191 times


Clearly its been a struggle

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Re: BN055 Vertical Orientation

by sj_remington on Wed Jun 16, 2021 12:16 am

the quaternion matrix

That matrix may indeed represent one of the many possible ways to derive Euler angles from a quaternion. But which particular definition of Euler angles?

What I am saying is that if you relabel the axes, you can relabel the yaw, pitch and roll angles accordingly, as long as you stick to the rules (XYZ -> XZY violates them). But you also need to know how those angles are defined.

I recommend that you take a step back and learn the basic rules for quaternion operations: it is high school trigonometry and algebra (really!). Since quaternions have become central to the graphics engines used for games, you will find the operations clearly explained in many tutorials on the web.

In the long run you will learn that Euler angles are NOT the way to go for the sort of application you have in mind.

Edit: it occurred to me that the BNO055 provides Euler angles. If you mentally remap the default BNO055 orientation axes, following the rules for cyclic permutation, the angles output by the BNO055 must also be cyclically permuted by the same operation.

sj_remington
 
Posts: 95
Joined: Mon Jul 27, 2020 4:51 pm

Re: BN055 Vertical Orientation

by ppecch on Wed Jun 16, 2021 1:51 pm

sj_remington wrote:
the quaternion matrix

That matrix may indeed represent one of the many possible ways to derive Euler angles from a quaternion. But which particular definition of Euler angles?

What I am saying is that if you relabel the axes, you can relabel the yaw, pitch and roll angles accordingly, as long as you stick to the rules (XYZ -> XZY violates them). But you also need to know how those angles are defined.

I recommend that you take a step back and learn the basic rules for quaternion operations: it is high school trigonometry and algebra (really!). Since quaternions have become central to the graphics engines used for games, you will find the operations clearly explained in many tutorials on the web.

In the long run you will learn that Euler angles are NOT the way to go for the sort of application you have in mind.

Edit: it occurred to me that the BNO055 provides Euler angles. If you mentally remap the default BNO055 orientation axes, following the rules for cyclic permutation, the angles output by the BNO055 must also be cyclically permuted by the same operation.


sj_remington >> I appreciate the advice, Ill need to go back and wrap my head around the math, its still not complete clear to me.

ppecch
 
Posts: 16
Joined: Mon Jun 14, 2021 12:11 pm

Please be positive and constructive with your questions and comments.