How to remove gravity from IMU sensor

I have IMU (Pololu) sensor connected to arduino nano and python file reads the measurements from it. and the task is :

1- remove the gravity.

2- Track the motion of the sensor along 2 axes. Use python turtle to visualise the change in position. If the accelerometer is attached to the breadboard, use the Y and Z axes.
Use the canvas_move_to ( x_mm , y_mm ) function to set the position of the sensor in the gui. Can you think of two reasons why the result is bad?

I attached python file and arduino code

How can I solve this task ??

IMU python code.pdf (31 KB)

Arduino code.pdf (33.7 KB)

See this discussion, which explains why your approach probably won't work.

Hi jremington,

Thanks for your reply.

I am still a beginner in robotics and to be honest , the article is a complex to me. However, I appreciate if there is a code explanation to go through it and understand the concept.

Even if the accuracy will be poor, it is a task in my course and I have to complete it :)

Even if the accuracy will be poor, it is a task in my course and I have to complete it

Well, I would say you have completed the requirement. You should even get extra credit for explaining why this approach doesn’t work well!

The best you can do is estimate orientation using complementary/Kalman filtering, then given that subtract off the gravity vector. What's left is a rather noisy estimate of linear acceleration, which can be integrated once for velocity or twice for position. Howver the errors multiply rapidly doing this so you won't be able to use this for navigation really.

Note that this involves maintaining a slowly varying estimate of gravity vector (and possibly magnetic vector) to correct drift in the gyro (which provides the rapid orientation information).

This has to be done in 3D throughout, or the results can be meaningless if the rotation angles are large.

Thanks Mark for your response.. where should I implement this in the code? Would you please write an example? Many thx

I love that CH Robotics link. The important thing to me is the table of errors near the bottom. That says that if your device has a 1 degree error then the position error becomes KILOMETERS in just a few minutes. And that's for something sitting stationary on a desktop.

If the axes you choose to measure are rotation around X and Y axes (that is, tilt) then you can get very good results from any 2-axis or 3-axis accelerometer. The more complex units with gyros (6DOF) will be even better.