# How can the dynamic effects of motor current on a digital compass be characterized and compensated for?

Digital compasses (magnetometers) require a hard/soft iron calibration in order to be accurate. This compensates for the magnetic disturbances caused by nearby metal objects -- the robot's chassis.

(image from http://diydrones.com)

However, digital compasses are also susceptible to the electric fields caused by the relatively high amount of current drawn by motors.

In order to get an accurate compass reading, what is the best way to measure (and compensate for) the interference caused by changing motor current levels?

• I never found the motors to actually disturb the magnetic readings very much. I would do some measurements first, and then decide if its worth compensating. Nov 15, 2012 at 21:02
• What kind of robot was this, and what size, out of curiosity? And does "not very much" mean less than 0.5 degree or less than 3 degrees of error?
– Ian
Nov 15, 2012 at 22:25
• Four wheeled robot, around 15 kg mass, 80W brushed motors. IMU around 20 cm distance from the motors. Error in the orientation estimate due to motors running was below 1 degree. There was a small ripple on the data. Didn't measure it, but I think less than 1%. Nov 16, 2012 at 7:53

Generally, this is not possible. This is because motors usually rotate very rapidly, creating rapidly fluctuating magnetic fields. Whether the disturbance is enough depends on how large the motors are.

For example, because I mounted an IMU (Inertial Measurement Unit) with magnetometers near some motors, and was forced to turn off the magnetometers to avoid the measurement affecting the state estimation.

In practice, the solutions most likely to solve your problem is:

• move the compass/magnetometer away from from the motors
• use shielding material (basically material with high magnetic permeability). They do not block magnetic fields, but because they provide a path of low magnetic resistance, they attact the magnetic field (lines from north to south) to pass through their interior, so that the magnetic field intensity is lower elsewhere.

The best shape for magnetic shields is thus a closed container surrounding the shielded volume. The effectiveness of this type of shielding depends on the material's permeability, which generally drops off at both very low magnetic field strengths and at high field strengths where the material becomes saturated. So to achieve low residual fields, magnetic shields often consist of several enclosures one inside the other, each of which successively reduces the field inside it. - Wikipedia/Magnetic shielding

You can thus wrap the motors in shielding material, such as:

• Giron
• MagnetShield
• PaperShield
• Magnetic Shielding Foil
• Mag-Stop Plates
• MetGlas
• JointShield
• Finemet (for kHz frequency fields)
• CobalTex

A good site for comparison of these materials is LessEMF.com Magnetic Field Shielding

It is theoretically possible to correct for the magnetic disturbance without shielding. We do need to be aware that there are two possible sources - a rotating permanent magnet and/or current in the coils. If we have feedback of the rotor position, we can correct for the permanent magnet or coil position. If you perform some experiments, recording current and rotor position, you should be able to fit a model of the magnetic field. Fitting is necessary because the actual field strength is very hard to calculate because of how the magnetic field looks depends on the size and shape of both the magnet and coils.

In practice, it is difficult to do this - unless the motor is turning very slowly and your sensor and model is accurate enough. First, if the frequency is high, it can cause problems because of synchronization issues and communication delays. If you cannot synchronize the data obtained from the motor feedback (position and current) and that from your magnetometers, you will increase your uncertainty. Even if the frequency is low, you need to have good control of the accuracy of:

• the magnetometer
• the model
• the inputs to the model (position and current)

If any of the above are not accurate enough, the residue magnetic field (assumed to be the earth's magnetic field) could be very inaccurate.

In general, accuracy can be decreased by:

• frequency
• motor field strength (since for the equation $residue magnetic field = raw measurement - motor model$, if the two terms on the right hand side are large, even at 1% accuracy, taking the difference could result in large left hand side uncertainties)
• sensor resolutions
• I would expect the rotation-dependent interference to average out over time, so that it would be just the stator interference and that of the wiring. Is that not the case?
– Ian
Nov 15, 2012 at 23:00
• The exact form of smoothing is undefined. The sampling, which affects how it smooths out, is implementation-dependent. For example, does it take multiple samples and average to one value? Is there a low-pass filter (to remove very high frequency noise)? If you really wanted to, it may be possible to correct based on this, but it gets complicated very fast. In fact, because a sensor might do this, the observed disturbance may also be velocity-dependent, so your model is even more complex. Nov 15, 2012 at 23:14