A magnetometer is a sensor that measures magnetic field strength and direction, allowing a robot to estimate its heading like a digital compass. In robotics, this helps a mobile robot, drone, or rover know which way it is facing even when wheel slip or drift affects other sensors. The sensor usually reports magnetic field components along three axes, which can be combined to find the direction of magnetic north.
This information is important for navigation, mapping, and stable autonomous motion.
Key Facts
- A 3-axis magnetometer measures magnetic field components Bx, By, and Bz.
- Horizontal heading can be estimated by heading = atan2(By, Bx), then converted to degrees.
- Magnetic field magnitude is B = sqrt(Bx^2 + By^2 + Bz^2).
- Declination correction converts magnetic heading to true heading: true heading = magnetic heading + declination.
- Hard iron distortion adds a constant offset to measured field values, such as Bmeasured = Btrue + Boffset.
- Soft iron distortion stretches or compresses the measured field pattern and often requires scale and rotation calibration.
Vocabulary
- Magnetometer
- A sensor that measures the strength and direction of a magnetic field along one or more axes.
- Heading
- The direction a robot is facing, usually measured as an angle from north in degrees.
- Magnetic declination
- The angle difference between magnetic north and true geographic north at a location.
- Hard iron distortion
- A constant magnetic offset caused by nearby permanent magnets or DC currents in the robot.
- Soft iron distortion
- A distortion caused by materials that bend or concentrate magnetic field lines, changing the measured shape and scale of the field.
Common Mistakes to Avoid
- Using atan(By divided by Bx) instead of atan2(By, Bx) is wrong because it can place the heading in the wrong quadrant.
- Ignoring magnetic declination is wrong because magnetic north and true north are usually not the same direction.
- Calibrating the sensor near motors, batteries, or steel tools is wrong because those objects can distort the measured field and produce a bad offset.
- Assuming a magnetometer works perfectly during acceleration or tilt is wrong because the horizontal components must often be tilt compensated using an accelerometer or IMU.
Practice Questions
- 1 A robot measures Bx = 30 microtesla and By = 40 microtesla on a flat surface. Find the magnetic heading using heading = atan2(By, Bx) in degrees.
- 2 A magnetometer reads Bx = 18 microtesla, By = 24 microtesla, and Bz = 40 microtesla. Calculate the total magnetic field magnitude B = sqrt(Bx^2 + By^2 + Bz^2).
- 3 A robot gives stable compass readings on a wooden table but becomes inaccurate when its motors turn on. Explain whether this is more likely hard iron distortion, soft iron distortion, or electrical interference, and describe one calibration or design fix.