Skip to content

ROS2 Jazzy driver for MMC5603NJ 3-axis high-resolution magnetometer (I2C). 20-bit output, auto set/reset, ±30G range.

License

Notifications You must be signed in to change notification settings

mingyo186/mmc5603_compass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mmc5603_compass

ROS2 Jazzy driver for MMC5603NJ 3-axis high-resolution magnetometer over I2C (MEMSIC).

The MMC5603 features 20-bit output resolution with ±30 Gauss fixed range, automatic set/reset for magnetic offset elimination, and continuous measurement mode up to 255 Hz ODR. It offers significantly higher resolution (1024 LSB/Gauss) compared to typical 16-bit magnetometers.

Features

  • Publishes sensor_msgs/MagneticField on mag/data
  • fake_mode for testing without hardware (random Gaussian data)
  • 20-bit resolution (1024 LSB/Gauss)
  • Automatic set/reset for offset elimination
  • Configurable ODR (1–255 Hz), bandwidth (1.2–6.6 ms)
  • Product ID verification (0x10)
  • Hard-iron bias calibration via service call
  • Runtime publish_rate change via ros2 param set

Prerequisites

  • ROS 2 Jazzy
  • Python 3
  • smbus2 (pip install smbus2) — only needed for real hardware

Installation

cd ~/ros2_ws
colcon build --packages-select mmc5603_compass --symlink-install
source install/setup.bash

Usage

Launch (default: fake_mode)

ros2 launch mmc5603_compass mmc5603_launch.py

Direct execution

ros2 run mmc5603_compass mmc5603_node.py --ros-args -p fake_mode:=true

Real hardware (Raspberry Pi)

ros2 launch mmc5603_compass mmc5603_launch.py params_file:=my_params.yaml

YAML override

mmc5603_compass_node:
  ros__parameters:
    fake_mode: false
    i2c_bus: 1
    device_address: 0x30
    odr: 200
    bandwidth: "1.2ms"

Topic echo

ros2 topic echo /mag/data

Parameters

Parameter Type Default Description
fake_mode bool true Use fake driver (no hardware)
i2c_bus int 1 I2C bus number
device_address int 0x30 I2C address (fixed)
publish_rate double 10.0 Publishing rate (Hz)
frame_id string mag_link TF frame ID
odr int 100 Sensor output data rate (1–255 Hz)
bandwidth string 6.6ms Measurement time: 6.6ms, 3.5ms, 2.0ms, 1.2ms
auto_set_reset bool true Automatic magnetic offset elimination
magnetic_field_covariance double 0.0 Diagonal covariance (T²)

Services

Service Type Description
mag/calibrate std_srvs/srv/Trigger Collect samples for 2s, compute hard-iron bias
mag/reset std_srvs/srv/Trigger Clear bias, reinitialise sensor

Package Structure

mmc5603_compass/
├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── .gitignore
├── package.xml
├── config/
│   └── mmc5603_params.yaml
├── launch/
│   └── mmc5603_launch.py
├── nodes/
│   └── mmc5603_node.py
├── mmc5603_compass/
│   ├── __init__.py
│   └── mmc5603_driver.py
└── test/
    └── test_mmc5603_node.py

Test Results

Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.

Test Category Test Result
Topics mag/data publishes sensor_msgs/MagneticField PASS
Services mag/calibrate returns success=True PASS
Services mag/reset returns success=True PASS
Parameters publish_rate runtime change PASS
Shutdown Clean exit PASS
Linting pep257, flake8, copyright, xmllint PASS

License

MIT

About

ROS2 Jazzy driver for MMC5603NJ 3-axis high-resolution magnetometer (I2C). 20-bit output, auto set/reset, ±30G range.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published