# Do magnets affect IMU values?

Im in the process of making a robot which requires 12 3x10mm cylindric magnets for the construction. They are 30mm from the center of the robot where I plan to have the IMU.

I was thinking about using MPU-6050. Do magnets affect the values? If yes, is there a solution for it? like maybe I could have a shield or something around the IMU?

If permanent magnets are rigidly mounted at a fixed distance from the IMU, they have no effect on the accelerometers and gyros inside the MPU-6050.

You can optionally connect the MPU-6050 to an external magnetometer. (It's used to cancel out yaw drift). That magnetometer, if you have one, will be affected by magnets. In theory you could shield the magnetometer by wrapping it in mu-metal, but that would also shield the magnetometer from the magnetic field of Earth, making the magnetometer useless -- better to leave out the magnetometer and the shield entirely.

Maybe you will be lucky and the magnets will merely shift the magnetometer values, without making it peg out. If so, there are various ways of calibrating-out this fixed shift, and the IMU could work as well as it would have worked without those magnets. (It's not clear to me if the MPU-6050 in particular supports such calibration).

I'm assuming your magnets have some purpose, yes? Generally people use magnets in ways where the magnetic field in one small region is actually used, and any "stray" magnetic field elsewhere doesn't help. There are several ways to "concentrate" the magnetic field, making it stronger where it is actually useful, and making the stray fields weaker.

Counter-intuitively, it is possible to add more magnets to your system in such a way that the total magnetic field, at the magnetometer, from all the magnets is almost perfectly cancelled out, leaving only the Earth's magnetic field. (This often makes the magnetic field elsewhere stronger).

For example, a Halbach array arranges permanent magnets in a way that makes the field stronger on one side, while cancelling the field to almost zero on the other side.

Hard to tell in this exact case. I looked up the MPU-6050 specs and I am unsure whether it integrates a digital compass to combat gyro drift. On Sparkfun, it refers to it being a '9 axis fusion algorithm' which implies compass (three axis each for gyro, accel, and magento) but elsewhere it only refers to gyro and accel.

I was doing some related work with a Pololu MinIMU-9 which has all nine axis but requires you to implement the IMU integration logic in code. What I found with that part was that placing it within 10 cm of the drive motors was causing the magnometer to be very difficult to use. On one hand you can do a calibration and remove the static magnetic fields from your reading (assuming your IMU routines are coded for this). On the other hand, I was finding that the strength of the static motor fields was so strong that the comparatively weaker Earth's magnetic fields were down in the 'noise'. I was having to tune down the flux sensitivity to handle the drive field so my sensitivity to the Earth's field also dropped.

This fix was to ensure the magnometer was sufficiently far away from the drives that their fields were sufficiently smaller than the Earth's fields. In my case I had to move the IMU sensor about 50 cm away from the motors.

So in summary, 'it depends' :-) It depends on your sensors, the strength of your local magnetic fields, and whether you can calibrate out the local fields in your IMU logic.

You might be able to do "hard iron" calibrations to cancel out the effects of the magnets if they are fixed in relation to the magnetometer. One strategy people use to avoid interference is to make a mast and put the magnetometer at the top of the mast away from the other electronics.

On a semi related note, is there a possibly of permanent damage to the magnemometer and other chips if they are exposed to a magnetic field of between 1000-2000 uT from a stack of small rare earth magnets? I tried doing that to the 9-DOF IMU from adafruit today as a test and it seems to have permanently altered the bias of the magnetometer.

• A strong magnetic field can alter the biases of most low end imu magnetometers, even after the magnetic field is removed. The magnetometer will need to be recalibrated afterwards. The data sheet for the magnetometer will indicate the maximum magnetic field it can sustain without damage.
– jjz
Jul 28 '19 at 5:22