1
1

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 5 years have passed since last update.

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

Last updated at Posted at 2019-09-23

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?