Create a communication bridge between ROS 1 and ROS 2

A ROS 1 and ROS 2 bridge allows communication between nodes of ROS 1 and ROS 2. Can happen that some packages are available in ROS 1 and not in ROS 2, a communication bridge can be useful.

For this tutorial we assume that you already have ROS 1 (indigo) and ROS 2 installed. If you don't have ROS 1 installed refer to ROS

For this tutorial you will need 4 different shells opened and running at the same time.

Do you need more computing capacity in your robots? Stay tuned

The bridge is currently implemented in C++ simply because there is no Python API for ROS 2 yet. Therefore it is limited to all the message types available at compile time.

A new package will be created.

ros2_ws/
    src/
        bridge/
            cmake/
                find_ros1_package.cmake
            src/
                bridge_1_to_2.cpp
                bridge_2_to_1.cpp
            CMakeLists.txt
            package.xml

First we start a ROS 1 roscore:

# Shell #1:
# load setup.bash
. /opt/ros/indigo/setup.bash
# launch the ROS 1 core
roscore

# Shell #2:
. /opt/ros/indigo/setup.bash
rosrun rospy_tutorials talker

The ROS 1 talker will start publishing and printing messages.

Now we start the ROS 2 listener.

# Shell #3:
cd ~/ros2_ws/
. ./install/setup.bash
listener

# Shell #4:
. /opt/ros/indigo/setup.bash
# Load the ROS 2 workspace
cd ~/ros2_ws/
. ./install/setup.bash
# launch the bridge
bridge_1_to_2

As you can see the ROS 1 talker is publishing messages. The published messages are passed by the bridge_1_to_2 from ROS 1 to ROS 2. Finally the ROS 2 listener is listening the messages passed by the bridge.

ROS 1 AND ROS 2 BRIDGE

First we start a ROS 1 roscore:

# Shell #1:
# load setup.bash
. /opt/ros/indigo/setup.bash
# launch the ROS 1 core
roscore

# Shell #2:
cd ~/ros2_ws/
. ./install/setup.bash
talker

The ROS 2 talker will start publishing and printing messages.

Now we start the ROS 1 listener.

# Shell #3:
. /opt/ros/indigo/setup.bash
rosrun rospy_tutorials listener

# Shell #4:
. /opt/ros/indigo/setup.bash
# Load the ROS 2 workspace
cd ~/ros2_ws/
. ./install/setup.bash
# launch the bridge
bridge_1_to_2

As you can see the ROS 2 talker is publishing messages. The published messages are passed by the bridge_2_to_1 from ROS 2 to ROS 1. Finally the ROS 1 listener is listening the messages passed by the bridge.

ROS 2 AND ROS 1 BRIDGE