Help us understand the problem. What is going on with this article?

Ubuntu16.04にROS2 Crystalをインストール

Ubuntu16.04に既にROS1インストールしているので、ROS2 Crystalをインストールして試したいと思います。

Ubuntu 18.04にROS2 Dashingをインストールは、こちら

ROS2 サポートOSバージョン

ROS2 Distro Release date EOL date Supported Platforms
Ardent Apalone 2017/12 2018/12 Ubuntu 16.04,Mac OS X 10.12 ,Windows 10
Bouncy Bolson 2018/07 2019/07 Ubuntu 18.04,Ubuntu 16.04 ,Mac OS X 10.12,Windows 10
Crystal Clemmys 2018/12 2019/12 Ubuntu 18.04,Ubuntu 16.04 ,Mac OS X 10.12,Windows 10
Dashing Diademata 2019/05 2021/05 Ubuntu 18.04,Mac OS X 10.12,Windows 10,Debian Stretch,OpenEmbedded Thud,webOS OSE

ROS2 インストール

ROS1 起動環境のコメントアウト

.bashrcで設定したROS1の起動スクリプトをコメントアウトします。

# source /opt/ros/kinetic/setup.bash
# source ~/catkin_ws/devel/setup.bash

変更したスクリプトを適用します。

$ source ~/.bashrc

ROS2リポジトリ追加

$ sudo apt update && sudo apt install curl gnupg2 lsb-release
$ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

ツールのインストール

$ sudo apt update && sudo apt install -y build-essential cmake git python3-colcon-common-extensions python3-pip python-rosdep python3-vcstool wget
$ sudo -H python3 -m pip install -U argcomplete flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes git+https://github.com/lark-parser/lark.git@0.7b pytest-repeat pytest-rerunfailures pytest pytest-cov pytest-runner setuptools
$ sudo apt install --no-install-recommends -y libasio-dev libtinyxml2-dev

ROS2コードの取得

$ mkdir -p ~/ros2_ws/src
$ cd ~/ros2_ws
$ wget https://raw.githubusercontent.com/ros2/ros2/release-latest/ros2.repos
$ vcs import src < ros2.repos

依存関係のインストール

$ sudo apt install -y python-rosdep
$ sudo apt-get install python-rospkg
$ sudo rosdep init
$ rosdep update
$ CHOOSE_ROS_DISTRO=crystal
$ rosdep install --from-paths src --ignore-src --rosdistro $CHOOSE_ROS_DISTRO -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 libopensplice69 python3-lark-parser rti-connext-dds-5.3.1 urdfdom_headers"

-std=c++11 コンパイルフラグの追加

orocos_kdlの「unique_ptr’ was not declared in this scope」コンパイルエラーを回避するため、
~/ros2_ws/src/ros2/orocos_kinematics_dynamics/orocos_kdl/CMakeLists.txtに
-std=c++11のコンパイルフラグを追加します。

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

ビルド

$ colcon build --symlink-install --packages-ignore qt_gui_cpp rqt_gui_cpp

.bashrcへ設定追加

source ~/ros2_ws/install/setup.bash

動作テスト

1つ目のターミナルで1秒ごとにメッセージがpublish(送信)されます。

$ ros2 run demo_nodes_cpp talker

[INFO] [talker]: Publishing: 'Hello World: 1'
[INFO] [talker]: Publishing: 'Hello World: 2'
[INFO] [talker]: Publishing: 'Hello World: 3'

2つ目のターミナルで1秒ごとにメッセージがsubscribe(受信)されます。

$ ros2 run demo_nodes_cpp listener

[INFO] [listener]: I heard: [Hello World: 1]
[INFO] [listener]: I heard: [Hello World: 2]
[INFO] [listener]: I heard: [Hello World: 3]

ROS 1とROS 2のメッセージ通信

ROS1 bridgeのインストール

$ source /opt/ros/kinetic/setup.bash
$ source ~/ros2_ws/install/local_setup.bash
$ colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure

ROS1 bridge 動作テスト

ROS 1を起動
Shell A (ROS 1 only):

$ source /opt/ros/kinetic/setup.bash
$ roscore

ros1_bridgeを起動
Shell B (ROS 1 + ROS 2):

$ export ROS_MASTER_URI=http://localhost:11311
$ ros2 run ros1_bridge dynamic_bridge

ROS 1 talkerを起動
Shell C:

$ source /opt/ros/kinetic/setup.bash
$ rosrun rospy_tutorials talker

ROS 2 listenerを起動
Shell D:

$ ros2 run demo_nodes_cpp listener
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away