I have a Arduino Nano BLE Sense Rev2, so far working with the new version of BLE sense has not been a fun experience considering the limited tutorials for the on board IMU.
I'm sorry I am no expert in the theory of sensor fusion or AHRS, but I know that if the output drifts or responds slowly, it must be the orientation of either sensors not aligning. I am currently using the SensorFusion Madgwick algorithm to fuse the sensor values.
There was already a thread on this issue on Madgwick sensor fusion with Sense Rev2. But didn't seem to help me. I tried the advice on figuring out the orientation of the IMU and the magnetometer, I found out that the axes lined up the same way as the ICM-20948 shown in the answer (not the notch, but the magnetometer Y and Z being inverted in respect to the IMU). Below is the picture from the Nano BLE Sense Rev2 chip layout, BMI270 and BMM150 datasheet respectively.


In the chip layout, U2 is BMI270 and U7 is BMM150, and the notch is aligned, so the magnetometer Y and Z axis is inverted. So I apply the corrected the value and apply it as per the answer, and the code is as below.
#include "Arduino_BMI270_BMM150.h"
#include "SensorFusion.h"
SF fusion;
float ax, ay, az, gx, gy, gz, mx, my, mz;
float deltat;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Started");
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
}
void loop() {
if (IMU.gyroscopeAvailable()) { IMU.readGyroscope(gx, gy, gz); }
if (IMU.accelerationAvailable()) { IMU.readAcceleration(ax, ay, az); }
if (IMU.magneticFieldAvailable()) { IMU.readMagneticField(mx, my, mz); }
ax *= 9.80665; ay *= 9.80665; az *= 9.80665;
gx *= PI / 180; gy *= PI / 180; gz *= PI / 180;
deltat = fusion.deltatUpdate();
fusion.MadgwickUpdate(gx, gy, gz, ax, ay, az, mx, -my, -mz, deltat);
char data[100];
sprintf(data, "%.2f\t%.2f\t%.2f\n", fusion.getRoll(), fusion.getPitch(), fusion.getYaw());
Serial.println(data);
}
The values reflected the opposite way of the rotation before slowly reaching the desired value, it took like 10 seconds, so I believe something is still wrong.
The best result I got so far is by inverting the accelerometer z axis, and got the most stable results so far, but the yaw drifts for a while after rotating to an angle.
fusion.MadgwickUpdate(gx, gy, gz, ax, ay, -az, mx, my, mz, deltat);
I also doubt this is the right way. I'm not sure whether the alignment is still wrong, maybe the magnetometer needs calibration (idk but I also tried isolating it from any nearby source of metal) or maybe it's just that slow, because I also tried Reefwing AHRS the values responds too slow that I am no longer using it, but it was also explained there that the BMI270/BMM150 library is giving a slow update.
Thanks in advanced.