ICM20948 correcting the rotation axis of the gyroscope

Hi, I am using the ICM20948 9DoF motion sensor breakout on my Pi2Go-Mk2 robot and I would like to be able to correct the rotation axis of the gyroscope. I think I should be able to use the accelerometer data of it to do that. As the 🤖 robot is a cart, which is always plane (or how do you say that?, in the same horizontal level on 2 wheels and a ball), I get fixed readings for the accelerometer: X = 1.00 Y = 0.05 Z= 0.00 (stationary, of course).

I could be lazy and try to adjust the breakout (using an extender) so the Y-reading is also 0.00 , but how would I do this in Python code? My aim is to have the robot make rotations in degrees ° as exactly as possible. It is pretty accurate already, but if I make a few 90° rotations, I can see that there is a deviation. I think this is because of the orientation.

🤖 Any help or ideas are much appreciated! 👍

Well, considering that:
-1- I am not that interested in the mathematical details of the gyroscope
-2- I just like the robot to make accurate, reproducible, turns

A correction factor will do fine! This is an even more lazy option, but it works and that’s what counts in the end 😉.

Ive just got the same motion sensor with the intention of putting it to the same use as you describe. Ive imported the python library and tried running the attached example code. I get reading back that change as i would expect when I wave the thing around but the magnitude of the numbers makes no sense to me. Would you mind posting some of your python code and an example of the figures that it returns?

2020-01-09 21_21_29-Spyder (Python 3.7)

Many thanks

For making exact turns or measuring them, you only need the gyroscope reading. First you have to find out the main axis the rotation is happening, there are markings on the ICM to help you, but obviously it is the axis you get the biggest reading from.

The reading is in degrees per second, with that in mind you can build your code by cutting it in small time sections. That is at least what I did and it worked for me. 1/100 of a second was accurate enough for me.

You have to excuse me for the time subroutine, which may seem odd, but I couldn’t find an other way to get my microseconds. (1/1000000 sec).

This is the code I wrote which made the robot make an exact 90° turn: