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

ros1_bridgeでROS NoeticとROS2 Galacticの通信

Last updated at Posted at 2021-10-13

はじめに

ros1_bridgeでROSとROS2の最新ディストリビューションであるNoeticとGalacticを通信させた記事がなかったのでメモ
基本的にgithubのREADME通り
ros1_bridgeについては参考にある記事を参照のこと

環境

OS:ubuntu20.04.3LTS
ROS:Noetic
ROS2:Galactic

同じubuntu20.04にNoeticとGalacticが両方インストールされている環境を想定

概要

ROS Noeticでpublishした/chatterトピックをROS2 Galacticでsubscribeする

ros1_bridgeのインストール

$ sudo apt install ros-galactic-ros1-bridge

ROS 側の準備

std_msg/String型のトピックをpublishするノードを作成、ROS TutorialのPublisher側プログラムを使用

talker.py
# !/usr/bin/env python3
import rospy
from std_msgs.msg import String

def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    r = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        str = "hello world %s"%rospy.get_time()
        rospy.loginfo(str)
        pub.publish(str)
        r.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException: pass

実行

ターミナル1

ROS Noeticでroscoreを起動

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

ターミナル2

ROS NoeticとROS2 Galactic両方の環境をロードしてros1_bridgeを実行

$ source /opt/ros/noetic/setup.bash
$ source /opt/ros/galactic/setup.bash
$ export ROS_MASTER_URI=http://localhost:11311
$ ros2 run ros1_bridge dynamic_bridge

実行画面

created 2to1 bridge for topic '/rosout' with ROS 2 type 'rcl_interfaces/msg/Log' and ROS 1 type 'rosgraph_msgs/Log'
created 1to2 bridge for topic '/chatter' with ROS 1 type 'std_msgs/String' and ROS 2 type 'std_msgs/msg/String'
[INFO] [1633905352.305453175] [ros_bridge]: Passing message from ROS 1 std_msgs/String to ROS 2 std_msgs/msg/String (showing msg only once per type)
[INFO] [1633905352.306387924] [ros_bridge]: Passing message from ROS 2 rcl_interfaces/msg/Log to ROS 1 rosgraph_msgs/Log (showing msg only once per type)

ターミナル3

ROS Noeticでtalkerを実行

$ source /opt/ros/noetic/setup.bash
$ python3 talker.py

実行画面

[INFO] [1633905191.352062]: hello world 1633905191.3518636
[INFO] [1633905191.452340]: hello world 1633905191.452095
[INFO] [1633905191.552324]: hello world 1633905191.5520732
[INFO] [1633905191.652243]: hello world 1633905191.6520474

ターミナル4

ROS2 Galacticでlistenerを実行

$ source /opt/ros/galactic/setup.bash
$ ros2 run demo_nodes_cpp listener

実行画面

[INFO] [1633905246.313638841] [listener]: I heard: [hello world 1633905246.3101022]
[INFO] [1633905246.413807904] [listener]: I heard: [hello world 1633905246.4104435]
[INFO] [1633905246.514000744] [listener]: I heard: [hello world 1633905246.5106533]
[INFO] [1633905246.613886751] [listener]: I heard: [hello world 1633905246.6104968]

参考

0
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
0
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?