ros2_imu_serial - A ROS2 Package to read 6-DOF IMU data


This project arose as a solution to obtain raw data from IMUs like MPU6050 (which has been used for this project) and implement custom filters like Madgwick Filters to obtain filtered angles to compute Euler angles. Hopefully this solves the lack of USB-serial based solutions for IMUs in ROS2, as most currently working solutions use I2C or UART connections, not providing a standard way for USB-based approaches.

  • Reads IMU data from a serial port
  • Publishes data as standard sensor_msgs/msg/Imu
  • Configurable serial port and baud rate
  • Lightweight and easy to integrate into existing ROS 2 systems
  • Suitable for embedded IMUs, microcontroller-based sensors, and prototyping

v This package provides:

  • A ROS 2 node that:
    • Opens a serial connection to an IMU device
    • Parses incoming sensor data
    • Publishes orientation, angular velocity, linear acceleration, and Euler angles
  • ROS 2 (tested with common distributions such as Humble / Iron)
  • Linux (recommended for serial device support)
  • IMU device that outputs serial data in a supported format
  • Access permissions to the serial device (e.g. /dev/ttyUSB0)

Clone the repository into your ROS 2 workspace:

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
git clone https://github.com/SlyPredator/ros2_imu_serial.git

Build the workspace:

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

Run the IMU serial node:

ros2 launch ros2_imu_serial imu_publisher.launch.py

Topics published by this package include:

  • /imu/data_raw (sensor_msgs/msg/Imu)
  • /imu/euler (sensor_msgs/msg/Imu)

You can inspect the data using:

ros2 topic echo /imu/data_raw
ros2 topic echo /imu/euler
Parameter Type Description Default
serial_port string Serial device path /dev/ttyUSB0
baudrate int Serial communication baud rate 115200
frame_id string TF frame for the IMU data imu_link
publish_rate float Rate of topic publishing in ROS2 50
use_madgwick bool Whether or not to apply Madgwick Filtering true
madgwick_beta float Madgwick Filtering beta value 0.1
publish_euler bool Whether or not to publish Euler angles true

If you encounter permission errors accessing the serial port:

sudo usermod -a -G dialout $USER
newgrp dialout
  • IMU data format and parsing depend on your specific hardware
  • Sensor calibration may be required for accurate results