Eliminate drift in gyro on romi robot

Hi,
I’m trying to eliminate drift on the gyro’s z-axis on my romi robot. I googled it and apparently a magnetometer is required to eliminate the drift. However, the romi robot’s control board’s IMU only comes with a 3-axis accelerometer and gyro. How can I add a magnetometer? Could I replace the built in IMU with this?

Also, how can I manually calibrate my gyro? I’m not using wpilib and I’m instead coding using the Arduino IDE directly via the microcontroller on the control board, along with the Romi 32U4 Arduino library, so I don’t exactly know how to do this. (Note that when I was using wpilib, even when the gyro is calibrated, there was still pretty significant drift when the robot was still, so this won’t fix the root problem)

To calibrate the gyro, most people simply estimate the offsets to be subtracted from each axis.

While the robot is still, add up a few hundred readings of raw data, calculate the three averages and subtract the averages from subsequent readings.

The offsets are temperature dependent, so this method is not stable if the temperature changes.

2 Likes