From https://github.com/ros2/ros1_bridge
First we start a ROS 1 roscore:
# Shell A (ROS 1 only):
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
roscore
Then we start the dynamic bridge which will watch the available ROS 1 and ROS 2 topics. Once a matching topic has been detected it starts to bridge the messages on this topic.
# Shell B (ROS 1 + ROS 2):
# Source ROS 1 first:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
# Source ROS 2 next:
. <install-space-with-bridge>/setup.bash
# For example:
# . /opt/ros/dashing/setup.bash
export ROS_MASTER_URI=http://localhost:11311
ros2 run ros1_bridge dynamic_bridge
The program will start outputting the currently available topics in ROS 1 and ROS 2 in a regular interval.
The following part is not necessary but only check if the communication is succeed. And you could check it via rqt on Ros2
Now we start the ROS 1 talker.
# Shell C:
. /opt/ros/melodic/setup.bash
# Or, on OSX, something like:
# . ~/ros_catkin_ws/install_isolated/setup.bash
rosrun rospy_tutorials talker
The ROS 1 node will start printing the published messages to the console.
Now we start the ROS 2 listener from the demo_nodes_cpp (for example) ROS 2 package.
# Shell D:
. <install-space-with-ros2>/setup.bash
ros2 run demo_nodes_cpp listener
The ROS 2 node will start printing the received messages to the console.
When looking at the output in shell B there will be a line stating that the bridge for this topic has been created:
created 1to2 bridge for topic '/chatter' with ROS 1 type 'std_msgs/String' and ROS 2 type 'std_msgs/String'
At the end stop all programs with Ctrl-C. Once you stop either the talker or the listener in shell B a line will be stating that the bridge has been torn down:
removed 1to2 bridge for topic '/chatter'
For more details, you could check the origin https://github.com/ros2/ros1_bridge for review.