I'm using the built-in BMI270 accelerometer+gyroscope and BMM150 magnetometer on the Rev 2 version of the Nano 33 BLE Sense, as a 9 axis IMU, using the MadgwickAHRS library.
Firstly, it seems like the BMI270 chip is on a different axis than printed on the board - the X and Y axes are switched. I've gotten around this by just using different inputs - I swapped the X and Y axes and then rotated the input 90 degrees around the Z axis, by using -gx, gy, gz, -ax, ay, az
instead of gx, gy, gz, ax, ay, az
. When plugging only the accelerometer and gyroscope values into the Madgwick sensor fusion algorithm, the output is reasonable and fairly accurate.
However, using the magnetometer (which has been calibrated) breaks these readings - the heading constantly changes, slowly straying toward arbitrary values, usually between 180 and 270. This is greatly exaggerated by changing the Arduino's pitch or roll away from 0.
I'm using filter.update(-gx, gy, gz, -ax, ay, az, mx, my, mz);
, where "filter" is the Madgwick object. The pitch and roll function somewhat well, though I suspect this is just because the accelerometer + gyroscope overpower the magnetometer's input. (directions defined by: if the arduino is a thin, long plane, I'm piloting it from the top of the processor)
I've tried several different configurations of the magnetometer's input, but none of these have given me reasonable output:
// -my mx mz: drifts
// my -mx mz: drifts
// mx my mz: drifts sometimes
// -mx my mz: seems slightly better? but screws up some headings and when z involved
// -mx my -mz: doesn't fix the above issues
// -mx -my -mz: vaguely ok ish but drifting exaggerated by tilting down
Does the magnetometer just use weird axes that I haven't tested for yet? I'll try using a magnet to test the different axes, and if I find anything notable I'll comment back on this thread.