7
5

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.

ROS2講座15 RealsenseD435を使う

Last updated at Posted at 2023-08-06

環境

この記事は以下の環境で動いています。

項目
CPU Core i5-8250U
Ubuntu 22.04
ROS2 Humble

概要

ROS対応センサーの代表格であるRealsenseを使用します。

Realsense D435

D435.png
Intel Webサイトより

realsenseはIntel製のセンサーモジュールで、RGB画像が取得できるだけでなく、距離情報も取得できる点でロボットに適しています。
測距方式は色々あるのですが、D435はステレオカメラでの視差情報から距離を求めています。また赤外線プロジェクターが点いているために、暗所でも測距可能です。

正面左から順に4つのデバイスを搭載しています。

  • 赤外線カメラ(右眼)
  • 赤外線プロジェクター
  • 赤外線カメラ(左眼)
  • カラーカメラ

realsense_cameraの実行

インストール

ROS1時代はソースからビルドが必須でしたが、最近はバイナリを配布するようになったために以下のコマンドでインストールできます。

realsense用ドライバのインストール
sudo apt install ros-humble-librealsense2 ros-humble-realsense2-camera

launchファイル

realsense2-camera内のlaunchではlaunchファイル中にパラメーターを含めているために煩雑な記述になっていますが、yamlからパラメーターを読むようにすれば以下のような簡易な記述になります。

espresso_frame_device_launch/launch/realsense.launch.py
import os
import yaml
from launch import LaunchDescription
import launch_ros.actions
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    return LaunchDescription([
        launch_ros.actions.Node(
            package='realsense2_camera',
            namespace='/device/head_camera',
            name='realsense_node',
            executable='realsense2_camera_node',
            parameters=[os.path.join(get_package_share_directory(
                'espresso_frame_device_launch'), 'config', 'realsense.yaml')],
            emulate_tty=True,
            output='screen',
        ),
    ])

パラメーターファイル

パラメーター例をいかに挙げます。複数のストリームを細かく制御できるためにパラメーター数が多いですが、大雑把に分けて以下の4つに別れます。

  • センサー(rgb_camera/depth_module)設定のパラメーター
  • realsenseとの接続のパラメーター
  • 出力ストリーム(color/depth/pointcloud...)のパラメーター
  • その他のパラメーター

詳細な説明はgithubのREADMEにありますので、ここでは紹介程度に説明します。

espresso_frame_device_launch/config/realsense.yaml
/**:
  ros__parameters:
    # Parameters that can be modified during runtime
    depth_module.profile: "640,480,15"
    depth_module.enable_auto_exposure: true
    rgb_camera.profile: "640,480,15"
    rgb_camera.enable_auto_exposure: true
    enable_depth: true
    enable_color: true
    enable_infra1: false
    enable_infra2: false
    enable_fisheye1: false
    enable_fisheye2: false
    enable_gyro: false
    enable_accel: false
    enable_pose: false
    enable_sync: false
    tf_publish_rate: 0.0

    # Parameters that cannot be changed in runtime:
    serial_no: ""
    usb_port_id: ""
    device_type': ""
    reconnect_timeout: 6.0
    wait_for_device_timeout: -1.0
    rosbag_filename: ""
    initial_reset: false
    unite_imu_method: 0
    clip_distance: -1.0
    publish_tf: true
    diagnostics_period: 0.0

    # Post-Processing Filters 
    align_depth.enable: false
    colorizer.enable: false
    pointcloud.enable: true
    pointcloud.stream_filter: 2
    pointcloud.allow_no_texture_points: false
    pointcloud.ordered_pc: false
    pointcloud.stream_index_filter: 0
    hdr_merge.enable: false
    depth_module.exposure.1: 7500
    depth_module.gain.1: 16
    depth_module.exposure.2: 1
    depth_module.gain.2: 16

    # Other
    camera_name: "head_camera"
    json_file_path: ""
    gyro_fps: 0
    accel_fps: 0
    pose_fps: 200
  • depth_module/rgb_cameraはそれぞれrealsenseハードウェアでの赤外線カメラ/カラーカメラの設定です。
    • profileはカメラの画素数とfpsの設定です。0,0,0とするとデフォルトの値(D435では1280x720)が選ばれますが、あまり大きい画素数を指定するとCPU負荷が高いのでロボット用途では少し下げるのが良いでしょう。rs-enumerate-devicesコマンドで指定可能な値の一覧を表示します。
    • enable_auto_exposureは露出の自動調整をする指定です。trueでは自動露出を行います。基本的に自動で充分ですが、色を厳密に測定するなどの用途では露出やWBを固定にする必要があります。
  • enable_xxxでは出力ストリームの設定です。
  • serial_nousb_port_iddevice_typeはOpenするRealsenseの指定です。複数のRealsenseを説ぞ奥している場合は、ここで指定して見分けます。
  • PointCloudを使用する場合はpointcloud.enabletrueにする必要があります。

実行

実行
source /opt/ros/humble/setup.bash
ros2 launch espresso_frame_device_launch realsense.launch.py

Rvizで設定すると画像とPointCloudが見えます。

realsense.png

目次ページへのリンク

ROS2講座の目次へのリンク

7
5
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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?