Realsense with ROS2 - ripl-lab/allan_variance_ros2 GitHub Wiki

RealSense ROS 2 Integration

The following instructions are for recording IMU data from a RealSense D435i camera using ROS 2 on an Ubuntu 22.04 machine.

Skip to step 3 if you already have the dependencies installed.

If you are using the devcontainer, only follow Step 1 on your local system before you start the container and then skip to Step 3 within the container

Prerequisites:

  1. Install RealSense SDK: Install the Intel RealSense SDK, which provides the necessary drivers and tools to interface with the camera. You can find installation instructions on the Intel RealSense GitHub page (https://github.com/IntelRealSense/librealsense). Specifically, follow the instructions for Ubuntu 22.04 in the development branch: https://github.com/IntelRealSense/librealsense/blob/development/doc/installation.md which are also included below.

Installation from debian is possible through the instructions at https://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.md however due to issues with kernal versions, it is recommended to build from source following the instructions below

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
sudo apt-get install libssl-dev libusb-1.0-0-dev libudev-dev pkg-config libgtk-3-dev
sudo apt-get install git wget cmake build-essential
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev at v4l-utils

git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense
git checkout development
./scripts/setup_udev_rules.sh

mkdir build && cd build
cmake ../
cmake ../ -DBUILD_EXAMPLES=true
sudo make uninstall && make clean && make && sudo make -j$(($(nproc)-1)) install
  1. Install RealSense ROS 2 Wrapper: This allows you to use the camera with ROS 2. You can install it from source or binaries. Here are the basic steps to install from source included below: (https://github.com/IntelRealSense/realsense-ros)
   # Source your ROS2 setup (if not already in your .bashrc to be sourced automatically)
   source /opt/ros/humble/setup.bash

   # Add ROS2 repository
   sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
   sudo apt install curl # if you haven't already installed curl
   curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

   # Install ROS2 RealSense packages
   sudo apt install ros-humble-realsense2-*

   # Create a workspace or alternatively use your existing workspace
   mkdir -p ~/ros2_ws/src
   cd ~/ros2_ws/src

   # Clone the RealSense ROS 2 wrapper
   git clone https://github.com/IntelRealSense/realsense-ros.git -b ros2-master

   cd ~/ros2_ws
   sudo apt-get install python3-rosdep -y
   sudo rosdep init
   rosdep update
   rosdep install -i --from-path src --rosdistro $ROS_DISTRO --skip-keys=librealsense2 -y

   # Build the workspace
   colcon build

   # Source the workspace
   source install/local_setup.bash
  1. Launch the RealSense Node: Use the provided launch files to start the RealSense node, which will publish the camera data, including IMU data, to ROS 2 topics.
   # Ensure the workspace is built
   export MAKEFLAGS="-j 2"
   cd ~/ros2_ws && colcon build

   # Source your workspace
   source ~/ros2_ws/install/local_setup.bash

   # Launch the RealSense node
   ros2 launch realsense2_camera rs_launch.py enable_accel:=true enable_gyro:=true unite_imu_method:=2
  1. Check Available Topics: Use the following command to list all available topics and verify that the IMU data topic is being published:
   ros2 topic list
  1. Echo IMU Data: Use the ros2 topic echo command to view the IMU data being published.
   ros2 topic echo /camera/camera/imu
  1. Record IMU Data: Use the ros2 bag record command to record the IMU data to an MCAP file.
   # Record IMU data to an mcap file (ie. for 3000 seconds)
   ros2 bag record /camera/camera/imu -s mcap -d 3000