Need help with imu

I am trying to use an imu to detect orientation along with acceleration. I am using the Arduino uno along with the MPU6050 imu. Is it possible to remove gravity so I can detect forward deceleration? I am using code from this https://github.com/TKJElectronics/KalmanFilter/tree/master/examples/MPU6050 . All I want to know is the roll angle and the amount of forward acceleration or deceleration.

Remove acceleration of gravity -> substract the value of g.

So yes it's possible. Actually it's a little more complicated since both gravity and acceleration are measured together ; and acceleration of gravity's projection along the 3 axis of the IMU depends on its orientation.

What I suggest is, in your algorithm:

  • Estimate the IMU orientation using a complementary filter
  • Using these estimated pitch and roll angles, you'll be able to project g vector along the IMU's axis and remove it, leaving alone the acceleration vector.