Notes on IMU (magnetometer) installation and calibration - robotique-udes/zeus_rover GitHub Wiki
Metals containing iron and electric motors in motion will cause magnetic interference so it is important to keep the IMU as far as possible from them.
Centering the IMU from the right and left side on the robot will minimize the interference if it is symetric since they will cancel each other out.
Make sure there is no iron within 15cm of the IMU.
If the IMU is installed sufficiently far away from any source of interference, it is possible to calibrate the IMU while having it detatched from the robot. Otherwise, the calibration will have to be done with the IMU attacthed to the robot.
A good way to analyze the magnetic interference on the robot is to use the "PhiPhox" phone app and use your phone's magnetometer in the "norm" mode and then move your phone near the robot while the wheels are turning.
It's a good idea to redo the calibration when using the robot in a new location far away from the previous one since the earth's magnetic field could be different in that location
Twisting the high current cables can minimize their magnetic interference.
If it is too hard to calibrate the IMU in all three axis when attatched to the rover, try only calibrating it on two axis (ground plane). However, it won't be possible to do ellipsoid callibration.