This package provides a ROS1 node for reading raw magnetometer data from a Yahboom IMU via serial interface, performing a simple calibration, and publishing the data as a sensor_msgs/MagneticField topic.
Install dependencies:
sudo apt install python3-serial- Clone this package:
cd ~/catkin_ws/src
git clone git@github.com:CJT-Robotics/magnetometer.git
sudo chmod +x ~/catkin_ws/src/magnetometer/src/mag_pub.py- Build the workspace:
cd ~/catkin_ws
catkin build
source devel/setup.bashTo ensure the magnetometer is always accessible under a fixed device name, create a udev rule.
lsusbExample output:
Bus 001 Device 014: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
1a86= idVendor7523= idProduct
sudo nano /etc/udev/rules.d/99-magnetometer.rulesAdd:
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="mag_yahboom", MODE="0666"sudo udevadm control --reload-rules
sudo udevadm triggerReconnect the device. Check:
ls -l /dev/mag_yahboomRun the node:
rosrun magnetometer mag_pub.pyPublished topic:
{namesapce}/imu/mag (sensor_msgs/MagneticField)
On startup, the node performs a calibration for a few seconds.
- Raw values are read from serial
- Packet structure is validated via checksum
- Magnetometer values are extracted
- Offset is subtracted
- Values are scaled
- Ensure correct permissions (
MODE="0666") or add your user todialout - If no data appears, verify:
- correct baud rate (115200)
- correct device path
- serial cable / adapter