Hello guys, I m trying to understand something and I was hoping to find some help.
I am using the sensor FXOS8700-FXAS21002. This sensor has a magnetometer, an accelerometer, and a gyroscope. I am not familiar with this filters, so I found a quick plug and play code here which I tried to understand (downloaded from github, opensource):
https://learn.adafruit.com/nxp-precision-9dof-breakout/orientation-test-usb
From what I understood, this implementation uses Mahony and Madgwick filters, to extract the orientation information from IMU data and get Roll Pitch and Yaw which is of interest to me.
This code has an example for sensor fusion that takes into account the gx,gy,gz (gyroscope) the mx,my,mz (magnetometer) and the ax, ay, az (accelerometer).
The question is : How can I clean out the information from the sensor, and compensate for the dynamic acceleration due to the motion, while a rigid body is moving, and so keep only the acceleration due to the gravity acceleration? I am using a device on which I have plugged the sensor, and with it I want to understand whether the device is kept straight or it tilts sometimes. But as it moves fast on the bench, the angles (Roll-Pitch) change and maybe I am reading a value that is not what I need to analyze. How could I do that?
Here is the code where the parameters are updated at the filter.update. This function is defined in the cpp file of the zip that is downloaded from the github.
// Apply mag offset compensation (base values in uTesla)
float x = mag_event.magnetic.x - mag_offsets[0];
float y = mag_event.magnetic.y - mag_offsets[1];
float z = mag_event.magnetic.z - mag_offsets[2];
// Apply mag soft iron error compensation
float mx = x * mag_softiron_matrix[0][0] + y * mag_softiron_matrix[0][1] + z * mag_softiron_matrix[0][2];
float my = x * mag_softiron_matrix[1][0] + y * mag_softiron_matrix[1][1] + z * mag_softiron_matrix[1][2];
float mz = x * mag_softiron_matrix[2][0] + y * mag_softiron_matrix[2][1] + z * mag_softiron_matrix[2][2];
// Apply gyro zero-rate error compensation
float gx = gyro_event.gyro.x + gyro_zero_offsets[0];
float gy = gyro_event.gyro.y + gyro_zero_offsets[1];
float gz = gyro_event.gyro.z + gyro_zero_offsets[2];
// The filter library expects gyro data in degrees/s, but adafruit sensor
// uses rad/s so we need to convert them first (or adapt the filter lib
// where they are being converted)
gx *= 57.2958F;
gy *= 57.2958F;
gz *= 57.2958F;
// Update the filter
filter.update(gx, gy, gz,
accel_event.acceleration.x, accel_event.acceleration.y, accel_event.acceleration.z,
mx, my, mz);