2
\$\begingroup\$

I'm working with an MPU9250 and using the Madgwick Filter. For what I know I need to subtract the GRAVITY from my X, Y, Z Acceleration values, basically, some kind of gravity compensation to get linear acceleration values. I was using the following code (q is my quaternion generated by the Madgwick filter):

 g[0] = 2 * (q[1] * q[3] - q[0] * q[2])
 g[1] = 2 * (q[0] * q[1] + q[2] * q[3])
 g[2] = q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]

Then, to compensate the gravity, I subtract gx, gy, gz from my ax, ay, az values respectively. I'm not sure if this is the correct approach to solve this problem and I would like a bit of help. After stripping the gravity values, I need to get velocity. I don't need position so I'm not going to double integrate the acceleration values. By the way, I have to mention that this will be used to measure speed and acceleration/deceleration of football players while running, so I don't need this to be extremely precise.

PS: I read about using a Low-Pass filter to subtract gravity, but I'm not sure if I should be doing that.

\$\endgroup\$
  • \$\begingroup\$ Have you read this post yet? stackoverflow.com/questions/12617200/… \$\endgroup\$ – Rekamanon Nov 6 '19 at 13:21
  • \$\begingroup\$ Yes I did, but that guy used a Kalman Filter, the Madwick algorithm gets me a different quaternion and thats my question. Im not sure if I should be rotating the quaternion. The guy on that question was using a 6DOF IMU and I have a 9DOF IMU, so thats why I am able to use the Madgwick Filter with my Magnetometer inputs. Also what I really want to understand are these three lines of code In my post and why they work (well, that is what this guy said) \$\endgroup\$ – LittnerDiAzure Nov 6 '19 at 13:37
  • \$\begingroup\$ I'd try a steep low pass filter, with a cutoff of less than 0.2Hz. \$\endgroup\$ – Scott Seidman Nov 6 '19 at 14:02
  • \$\begingroup\$ Can the low pass filter remove the gravity from the accelerometer values? Should I apply it to the accelerometer raw data? \$\endgroup\$ – LittnerDiAzure Nov 6 '19 at 14:10
  • \$\begingroup\$ Yes. Apply it to the raw signal. \$\endgroup\$ – Scott Seidman Nov 6 '19 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.