Glossary

Magnetometer

Magnetometer – definition

A magnetometer is a sensor that measures the local magnetic field vector. In mobile robotics, it is commonly used as a three-axis electronic compass. Its output helps estimate a robot’s heading relative to magnetic north after calibration and compensation for local disturbances.

Magnetometers used in robotics may use magnetoresistive, Hall-effect, or fluxgate sensing elements. For UGV applications, compact MEMS magnetometers are a common option. They measure magnetic flux density along the sensor’s X, Y, and Z axes. ROS 2 represents this data with the sensor_msgs/msg/MagneticField message type, where magnetic-field values are expressed in tesla (T). Source: ROS 2 sensor_msgs documentation.

On a UGV such as Leo Rover or Raph Rover, a magnetometer can provide an absolute heading reference that complements wheel odometry and gyroscope measurements. It does not provide position. It also cannot reliably determine heading without appropriate calibration, frame alignment, tilt compensation, and magnetic-interference assessment.

Magnetic field measurements in ROS 2

In ROS 2, a magnetic-field measurement is normally published as a stream of sensor_msgs/msg/MagneticField messages. The message contains a standard ROS message header, the magnetic-field vector, and a 3×3 covariance matrix.

std_msgs/Header header
geometry_msgs/Vector3 magnetic_field
float64[9] magnetic_field_covariance

The magnetic_field vector is expressed in tesla. A value of 50e-6 represents 50 microtesla (µT). The Earth’s field is typically in the approximate range of 25 to 65 µT at the surface, depending on geographic location. Source: NOAA National Centers for Environmental Information, World Magnetic Model.

ROS coordinate conventions should follow REP 103. For body-fixed mobile robot frames, REP 103 uses X forward, Y left, and Z up. Geographic frames use the East-North-Up (ENU) convention unless another convention is explicitly documented. Source: REP 103 – Standard Units of Measure and Coordinate Conventions.

A typical ROS 2 sensor pipeline publishes raw or calibrated data under a topic such as:

ros2 topic echo /magnetometer/magnetic_field
ros2 topic hz /magnetometer/magnetic_field
ros2 interface show sensor_msgs/msg/MagneticField

The publication frequency depends on the selected sensor and driver configuration. It must be verified in the hardware datasheet and at runtime with ros2 topic hz. A navigation filter should use timestamps from the message header, not assumed fixed sampling intervals.

Heading estimation and tilt compensation

A two-dimensional compass heading can be calculated from horizontal magnetic-field components only when the sensor is level. For a UGV operating on slopes, ramps, loose terrain, or uneven construction surfaces, the magnetic vector must first be rotated using roll and pitch estimated by an IMU.

For a robot frame with X forward and Y left, a heading that increases clockwise from magnetic north can be calculated from the tilt-compensated horizontal components:

heading = atan2(My, Mx)

Where Mx and My are calibrated magnetic-field components in the selected horizontal robot frame. Sign conventions depend on the frame definition and sensor mounting orientation. The resulting value is magnetic heading, not true-north heading.

To obtain a true-north reference, the local magnetic declination must be applied. Declination changes with location and time. The NOAA World Magnetic Model provides coefficients and reference software for this calculation. The current WMM2025 model is specified for the 2025-2030 period. Source: NOAA WMM documentation.

Calibration and magnetic interference

Magnetometer calibration is essential on mobile platforms because the sensor measures both the Earth field and magnetic fields generated by the robot. Motors, motor drivers, battery cables, DC-DC converters, steel fasteners, payloads, and nearby structures can distort the measurement.

Two error classes are normally considered during calibration:

  • Hard-iron distortion – a fixed or slowly varying offset caused by permanent magnetization or static current-carrying components.
  • Soft-iron distortion – scaling and axis deformation caused by ferromagnetic materials near the sensor.

Raw samples plotted in three dimensions should approximate a sphere when the sensor is rotated through multiple orientations. Hard-iron effects shift this sphere. Soft-iron effects transform it into an ellipsoid. A calibration process estimates an offset vector and a correction matrix:

m_calibrated = A × (m_raw - b)

Here, b is the hard-iron offset and A is the soft-iron correction matrix. Calibration should be repeated after relocating the sensor, changing a metal payload, modifying power wiring, or attaching a new sensor mast.

Use on Leo Rover and Raph Rover

Leo Rover can run ROS 2 on its built-in Raspberry Pi compute unit, depending on the installed software image and ROS distribution. A magnetometer can be connected through an IMU module, USB sensor, I2C interface, or an external compute and sensor payload. The sensor should be mounted away from drive motors, battery wiring, and high-current electronics. Leo Rover uses four-wheel differential drive, so yaw estimation is particularly relevant for dead reckoning and navigation-stack orientation.

Raph Rover can be configured with larger sensor payloads and more extensive compute hardware. This makes it suitable for integrations that combine a magnetometer with GNSS/RTK, LiDAR, cameras, and a higher-grade IMU. A magnetometer remains a heading aid, not a substitute for GNSS heading, visual localization, LiDAR localization, or SLAM in magnetically disturbed environments.

For both platforms, a practical architecture is to fuse wheel odometry, gyroscope angular velocity, accelerometer data, and optionally magnetometer-derived yaw in an Extended Kalman Filter. The robot_localization package supports state estimation from multiple ROS sensor topics, but the covariance values and frame configuration must reflect actual sensor uncertainty. Source: robot_localization documentation.

Limitations in autonomous navigation

A magnetometer can improve long-term yaw observability, but it is vulnerable to environmental interference. Reinforced concrete, vehicles, steel fences, power infrastructure, laboratory equipment, and magnetic soil can create local anomalies. Sudden heading changes that do not match gyroscope or wheel-odometry motion should be treated as suspect measurements.

For ROS 2 navigation, magnetic heading is usually most useful as one input to sensor fusion. Nav2 does not require a magnetometer. A UGV can navigate using other localization sources, including SLAM, LiDAR localization, visual odometry, GNSS, or fused wheel and inertial odometry. Source: Nav2 documentation.

See also