I use a well-known algorithms RTIMULib or RTIMULib2.
Adapted to the Arduino environment.
Launched the source code in the vscode + platformio environment on an esp32 microcontroller with a bno055 sensor.
The sensor axes are positioned like this
// bno055 sensor.
//
// | Z axis
// |
// | / Y axis
// ____|__/____
// / | / /| X axis
// / |/____//________
// /__________* //
// |____________|/
I receive data from the sensor using the reading function, which contains the following transmission lines for the accelerometer and gyroscope axes.
I rewrote the library files to work with the sensor via the SPI bus.
RTIMUBNO055.cpp
// sort out accel data;
m_imuData.accel.setX(sign[0] * m_imuData.accel.x());
m_imuData.accel.setY(sign[1] * m_imuData.accel.y());
m_imuData.accel.setZ(sign[2] * m_imuData.accel.z());
// sort out gyro axes
m_imuData.gyro.setX(sign[3] * m_imuData.gyro.x());
m_imuData.gyro.setY(sign[4] * m_imuData.gyro.y());
m_imuData.gyro.setZ(sign[5] * m_imuData.gyro.z());
handleGyroBias();
// calibrateAverageCompass();
calibrateAccel();
// now update the filter
updateFusion();
Gyro data scaled in rad/sec
I scale the accelerometer data to 9.8 m/s^2
I don't have the magnetometer sensor connected yet, so I'm not using it yet.
I won't post the whole main.c file, those who know the library RTIMULib2 will understand.
#include "RTIMUSettings.h"
#include "IMUDrivers/RTIMU.h"
#include "CalLib.h"
#include "RTFusionRTQF.h"
#define SERIAL_PORT_SPEED 115200
RTIMU *imu;
RTIMUSettings settings;
int sign[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
void setup()
{
Serial.begin(SERIAL_PORT_SPEED);
imu = RTIMU::createIMU(&settings);
imu->IMUInit();
imu->setSlerpPower(0.0002);
imu->setCompassEnable(false);
} // SETUP
void loop()
{
if (!imu->IMURead())
return;
RTIMU_DATA data = imu->getIMUData();
Serial.print("Orientation: ");
Serial.print(-data.fusionPose.x() * RTMATH_RAD_TO_DEGREE);
Serial.print(" ");
Serial.print(data.fusionPose.y() * RTMATH_RAD_TO_DEGREE);
Serial.print(" ");
Serial.println(-data.fusionPose.z() * RTMATH_RAD_TO_DEGREE);
} // LOOP
I added an array sign[9] to change the signs of the axes from the main.c
In general, a question about the strange behavior of the RTQF and KALMANSTATE4 algorithms.
GUI on Processing from GitHub - VoxMi/MPU-9150 with minor modifications.
The RTQF algorithm, when the device is first turned on, for some reason has a rotation around Y axis and begins to align it to the normal position of the sensor.
But it's as if the Z axis has gravity pointing upward.
The KALMANSTATE4 algorithm works perfectly when first turned on, all the axes are correct and there is no additional rotation.
I tried changing/deleting some lines from the source files, it seems like the function
predict()
affects the result of the axis flip.
But I can't understand more.
In general, the algorithms work, but the nature of the orientation flip when running the RTQF algorithm is unclear
Source code RTQF
and
KALMANSTATE4
I have already used the first version of the library RTIMULib in this way with Flight Gear avia simulator.
More info in forum.


