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):
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 [u]dynamic acceleration due to the motion,[/u] 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; float y = mag_event.magnetic.y - mag_offsets; float z = mag_event.magnetic.z - mag_offsets; // Apply mag soft iron error compensation float mx = x * mag_softiron_matrix + y * mag_softiron_matrix + z * mag_softiron_matrix; float my = x * mag_softiron_matrix + y * mag_softiron_matrix + z * mag_softiron_matrix; float mz = x * mag_softiron_matrix + y * mag_softiron_matrix + z * mag_softiron_matrix; // Apply gyro zero-rate error compensation float gx = gyro_event.gyro.x + gyro_zero_offsets; float gy = gyro_event.gyro.y + gyro_zero_offsets; float gz = gyro_event.gyro.z + gyro_zero_offsets; // 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);