What we are going to learn
- How to source ROS1 and ROS2 correctly
- How to run ros1_bridge
List of resources used in this post
- ROS Development Studio (ROSDS) —▸ http://rosds.online
- Robot Ignite Academy –▸ https://www.robotigniteacademy.com
- ros1_bridge –▸ https://github.com/ros2/ros1_bridge
- Question asked on ROS Answers –▸ https://answers.ros.org/question/343680/can-i-mix-ros1-and-ros2-packages/
Creating a rosject
In order to learn how to make ROS1 interact with ROS2, we need to have ROS1 and ROS2 installed in our computers. Installing two different distros is not going to be covered in this topic because we are going to use The Construct (https://www.theconstructsim.com/) for this tutorial, where both ROS installations are already available. But if you want to test everything on your own computer, feel free to install ROS1 Noetic and install ROS2 Foxy on your Ubuntu 20.04 computer.
Let’s start by opening The Construct (https://www.theconstructsim.com/) and logging in. You can easily create a free account if you still don’t have one.
Once inside, let’s create My Rosjects and then, Create a new rosject:
For the rosject, let’s select ROS2 Foxy for the ROS Distro, let’s name the rosject as ROS1/2 Node. You can leave the rosject public.
If you mouse over the recently created rosject, you should see a Run button. Just click that button to launch the rosject.
As we mentioned at the beginning of this post, you need to have ROS1 and ROS2 installed on the computer. Thank God we already have that on The Construct.
Let’s open a new terminal by clicking on the Open a new shell window button:
Now, let’s check the ROS distributions that we have installed:
You should see at least foxy and noetic installed.
Let’s now install ros1_bridge, a ROS 2 package that provides bidirectional communication between ROS 1 and ROS 2.
sudo apt-get update sudo apt-get install -y ros-foxy-ros1-bridge
The ros1-bridge package should have been installed. You can check it with:
sudo dpkg -l | grep 'ros1-bridge'
which should output something similar to:
ii ros-foxy-ros1-bridge 0.9.6-1focal.20211014.191041 A simple bridge between ROS 1 and ROS 2
Starting a ROS1 Node
Now it is time to start a simple ROS1 publisher. You may be already familiar with this. For that, let’s first run roscore in the first terminal with:
source /opt/ros/noetic/setup.bash roscore
Please be aware that we first sourced our ROS1 noetic distro.
Now, in another terminal, let’s launch a ros1 publisher:
source /opt/ros/noetic/setup.bash rosrun rospy_tutorials talker
If everything went ok, you should have a /chatter topic now, and the talker should be printing something like the output below:
[INFO] [1636419517.414196]: hello world 1636419517.414014 [INFO] [1636419517.515074]: hello world 1636419517.5148714 [INFO] [1636419517.614426]: hello world 1636419517.614205 [INFO] [1636419517.714437]: hello world 1636419517.7142227 [INFO] [1636419517.814406]: hello world 1636419517.8142045 [INFO] [1636419517.914464]: hello world 1636419517.9142513
You can also confirm that there is a /chatter topic in ROS1 with the following commands in another (third) terminal:
source /opt/ros/noetic/setup.bash rostolic list
The output should be similar to the following:
/chatter /rosout /rosout_agg
Starting a ROS2 Node
So far we have launched a ROS1 node. Let’s open a different terminal (a fourth one), source ROS2 and check the list of topics:
source /opt/ros/foxy/setup.bash ros2 topic list
The topics listed should contain no reference to /chatter, the topic being published by a ROS1 node. The list of topics in ROS2 should be:
Now let’s run ROS1 Bridge. For that, let’s first source both ros1 and ros2. Let’s open a fifth terminal for that:
source /opt/ros/noetic/setup.bash source /opt/ros/foxy/setup.bash ros2 run ros1_bridge dynamic_bridge --bridge-all-topics
If everything went ok after launching ROS1 Bridge, the output should be similar to this:
created 1to2 bridge for topic '/chatter' with ROS 1 type 'std_msgs/String' and ROS 2 type 'std_msgs/msg/String' created 1to2 bridge for topic '/rosout' with ROS 1 type 'rosgraph_msgs/Log' and ROS 2 type 'rcl_interfaces/msg/Log' created 1to2 bridge for topic '/rosout_agg' with ROS 1 type 'rosgraph_msgs/Log' and ROS 2 type 'rcl_interfaces/msg/Log' created 2to1 bridge for topic '/chatter' with ROS 2 type 'std_msgs/msg/String' and ROS 1 type 'std_msgs/String' created 2to1 bridge for topic '/rosout' with ROS 2 type 'rcl_interfaces/msg/Log' and ROS 1 type 'rosgraph_msgs/Log' [INFO] [1636419930.466921521] [ros_bridge]: Passing message from ROS 1 std_msgs/String to ROS 2 std_msgs/msg/String (showing msg only once per type) [INFO] [1636419930.467529301] [ros_bridge]: Passing message from ROS 2 rcl_interfaces/msg/Log to ROS 1 rosgraph_msgs/Log (showing msg only once per type) [INFO] [1636419930.467995035] [ros_bridge]: Passing message from ROS 2 std_msgs/msg/String to ROS 1 std_msgs/String (showing msg only once per type) removed 2to1 bridge for topic '/chatter' [INFO] [1636419930.587503640] [ros_bridge]: Passing message from ROS 1 rosgraph_msgs/Log to ROS 2 rcl_interfaces/msg/Log (showing msg only once per type)
If we now go back to the fourth terminal and list the ROS2 topics again:
source /opt/ros/foxy/setup.bash ros2 topic list
Now we should see a /chatter topic.
/chatter /parameter_events /rosout /rosout_agg
This is really awesome, isn’t it? We are running a publisher in ROS1, and we can see the topic in ROS2.
If we can see the topic, we also expect to see what is being published, right? Let’s try to subscribe to that topic using ROS2 to see what happens. We can run the command below in the same terminal where we listed the ros2 topics:
ros2 topic echo /chatter
If everything worked for you as it should, you should be able to see in ROS2 the messages published in ROS1:
data: hello world 1636420166.362258 --- data: hello world 1636420166.4622662 --- data: hello world 1636420166.5622616 --- data: hello world 1636420166.662261 --- data: hello world 1636420166.7621603
Awesome. Congratulations. You made it. You now have seen, with hands-on, how to make ROS1 and ROS2 topics interact with one another. This is certainly a really basic example, but we hope you find it useful. Feel free to kill the nodes you launched in the different terminals if you want. You can also keep using The Construct to improve your ROS Skills.
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.