0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DockerでROS2 Realsense D405 動かす

Last updated at Posted at 2022-10-18

ROS2 FoxyでRealsense D405を動かすことを目的とした.
環境はDockerで構築した.
Nvidia Dockerはすでにインストールされているものとする.

環境構築

ROS2 base imageの構築

まず,Realsense rosを入れるための,ROS2の環境を作る.
Base Imageはcuda11.3としたが,これはPytorchのサポートを考慮したためである.
develなのは,機能が十分揃っているイメージだからである.

Dockerfile

Dockerfile
FROM nvidia/cudagl:11.3.0-devel-ubuntu20.04
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y sudo curl git gnupg2 lsb-release software-properties-common

# ロケールのセットアップ
RUN sudo apt-get install -y locales && \
    dpkg-reconfigure locales && \
    locale-gen ja_JP ja_JP.UTF-8 && \
    update-locale LC_ALL=ja_JP.UTF-8 LANG=ja_JP.UTF-8
ENV LC_ALL   ja_JP.UTF-8
ENV LANG     ja_JP.UTF-8
ENV LANGUAGE ja_JP.UTF-8

RUN sudo apt-get update && \
    sudo apt-get upgrade -y

# RUN DEBIAN_FRONTEND=noninteractive && sudo apt install -y curl git gnupg2 lsb-release software-properties-common
RUN sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg

COPY ./bash /root/
WORKDIR /root/
RUN ["/bin/bash", "/root/add_repo.bash"]

ENV ROS_DISTRO foxy

RUN sudo apt-get update && \
    sudo apt-get upgrade -y 

RUN export ROS_DISTRO=foxy && \
    apt-get install -y ros-$ROS_DISTRO-desktop \
    python3-colcon-common-extensions python3-rosdep python3-argcomplete && \
    rosdep init && \
    rosdep update

RUN mkdir -p /root/colcon_ws/src
WORKDIR /root/colcon_ws
## 環境設定
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> ~/.bashrc

build

docker build -f ./Dockerfile -t foxy:base .

Realsense インストール

先程構築したImageをベースにして,次のImageを作る.

Dockerfile

librealsense2-devもインストールしないと,colcon buildが通らなかった.

Realsense.Dockerfile
FROM foxy:base

# Realsenseのインストール
# Install Librealsense
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
RUN sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u
RUN sudo apt-get install -y librealsense2-dkms librealsense2-utils librealsense2-dev
RUN sudo apt-get install -y ros-$ROS_DISTRO-xacro \
    ros-$ROS_DISTRO-diagnostic-updater

RUN sudo apt-get update && \
    sudo apt-get upgrade -y

docker image作成

docker build -f ./Realsense.Dockerfile -t realsense:foxy .

実行のためのdocker-compose.yaml

docker-compose.yaml
version: '3'

networks:
  ros:
    driver: bridge

services:
  realsense-ros:
    image: realsense:foxy
    hostname: realsense-ros-server
    container_name: realsense-foxy-container
    environment:
      - "ROS_HOSTNAME=pcl_publisher"
      - "ROS_DOMAIN_ID=100"
      - "DISPLAY=$DISPLAY"
      - "QT_X11_NO_MITSHM=1"
    user: "1002:"
    privileged: true
    volumes: 
      - "/home/$USER:/home/$USER"
      - "/etc/group:/etc/group:ro"
      - "/etc/passwd:/etc/passwd:ro"
      - "/etc/shadow:/etc/shadow:ro"
      - "/etc/sudoers.d:/etc/sudoers.d:ro"
      - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
    working_dir: "/home/$USER/weld_ros2/realsense_ws/"
    networks:
      - ros
    tty: true
    restart: always
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]

user:のところは、1002としていたが、そこの数値は人によって変わるため、自分のPCの値を入れること。

# UIDの確認法
echo $UID
echo $GID
# user: "1002:1003"などと記入。

realsense ros packageをbuildする

docker compose up -d
docker container exec -it realsense-foxy-container bash
colcon build # コンテナ内

実行

docker compose up -d # コンテナを停止させていた場合
docker container exec -it realsense-foxy-container bash
source /opt/ros/foxy/setup.bash
. install/local_setup.bash
ros2 launch realsense2_camera rs_launch.py pointcloud.enable:=true
# 別ターミナル
rviz2

ros2 command not foundのようなエラーが出たら,
source /opt/ros/$ROS_DISTRO/setup.bash
を実行する.

もしvideo0 permission deniedって言われたら,sudo chmod 777 /dev/video0

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?