BSXlite may be helpful for your application, you can refer to BSXlite for your application.
Bosch Sensortec’s sensor fusion software BSX is a complete 9-axis fusion solution which combines the measurements from 3-axis gyroscope, 3-axis geomagnetic sensor and a 3-axis accelerometer to provide a robust absolute orientation vector. The sensor fusion software BSX provides orientation information in form of quaternion or Euler angles.
The algorithm fuses the sensor raw data from 3-axis accelerometer, 3-axis geomagnetic sensor and 3-axis gyroscope in an intelligent way to improve each sensor’s output. This includes algorithms for offset calibration of each sensor, monitoring of the calibration status and Kalman filter fusion to provide distortion-free and refined orientation vectors. Since Bosch Sensortec 9-axis fusion software is developed together with the sensor hardware, optimized performance in terms of dynamics and immunity to distortion effects is achieved.