BMI160 board orientation problem

When designing a device in which I planned to use BMI160 for orientation, I ran into the problem of axis orientation.

Using an example sketch from https://docs.arduino.cc/library-examples/curie-imu/Genuino101CurieIMUOrientationVisualiser
By default, the orientation of the sensor is


The x-axis is directed to the north, the y-axis to the west, and the z-axis to the sky.
When the board is level, I get great roll, pitch, and yaw angles.

But I need to use the board with the sensor in a vertical position like this

But as soon as I turn the board on edge, the zed axis is immediately limited in movement and I get a gimbal lock.
The other axes are also nonsense, not data.
I began to look for information on how to reassign the axes, but I did not find anything - only a licensed solution from Bosch itself in the form of software.
I tried to calibrate offsets, but nothing changes after calibration - as if the axes are not calibrated at all.
I determined that when the board is parallel to the table, then the acceleration along the zed axis is about 1, along the other axes zero
When I turn the board on edge, the x-axis becomes one, the other axes are zeros.
I edited the offsets, but nothing has changed.
a: -0.19 0.06 0.97

    BMI160.autoCalibrateGyroOffset();

    BMI160.autoCalibrateAccelerometerOffset(X_AXIS, 1);
    BMI160.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
    BMI160.autoCalibrateAccelerometerOffset(Z_AXIS, 0);

I can’t understand anything, the datasheet says that you can use the sensor in any orientation, but I can only receive normal data in the horizontal space of the board.
My code takes the raw data from the accelerometer and gyroscope, converts it into gee values for the accelerators and into angular velocities for the gyroscopes.

Then I filter the data through the Madgwick filter, the output of which is a normalized quaternion.
And after the quaternion I convert it to roll, pitch and heading angles.
Is it possible for me to reorient the axes - do I need to change the values in the quaternion?

It turns out that with the rotation of the board from the sensors from the horizontal to the vertical plane, the z-axis became the x-axis, and the x-axis became the z-axis.
The Y-axis is left as is.

Moreover, an example for processing, using transformation matrices - somehow gets a normal orientation at the output ...

I tried to substitute the swapped axes in the filter, but the output was not what I needed.

I used to think that working with accel and gyro sensors was not very difficult.
Connected via the I2C bus, requested the value Ax,Ay,Az, Gx, Gy,Gz and filter whatever you want.
I thought you can arrange the board as you like, at the right time including calibration and zeroing the readings in order to count from the desired position.
And in fact, nothing works.
In general, I can’t understand how I get a quaternion - as a result, I encounter a gimbal lock?
Also I don't understand why I need rotation/transformation matrices to display roll/pitch/heading?
Confusion and porridge in my head ...

I moved your topic to an appropriate forum category @masteriphone.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Any luck? I am trying to use the BMI160 for a similar application and I am stuck!

The bmi160 sensor is a pleasure to work with.
To rotate the axes, you simply indicate which axis you have facing up and put a 1 on the line.

BMI160.autoCalibrateAccelerometerOffset(X_AXIS, 1);
BMI160.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
BMI160.autoCalibrateAccelerometerOffset(Z_AXIS, 0);

In my case, the X axis is facing up.
If this is the Z axis, then put one(1) in the third line, and 0 in the another strings.
It is more difficult to rotate the axes of the mpu9250, lsm303dlh and l3gd20 sensors and others.
The Bosch sensor in this board is a very good sensor and the library for it is well written.

1 Like

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