ROS2 Tutorials #8: How to communicate between ROS1 & ROS2 with ros1_bridge

How to communicate between ROS1 & ROS2 with ros1_bridge

Written by Alberto Ezquerro

06/10/2019

In this post, you will learn how to communicate between ROS1 & ROS2 with ros1_bridge. You will see how to set up the ros1_bridge package in order to send ROS2 commands to control a TurtleBot2 simulation running in ROS1 Melodic.

Step 1: Grab a copy of the Project (ROSject) on ROSDS

Click here to get your copy of the project used in this post.

Step 2: Launch the TurtleBot2 simulation from the Simulations menu

Launch a TB2 Simulation

Now you should see a Simulation window pop up with the TurtleBot2 simulation.

TurtleBot2 Simulation

Step 2: Source the workspace for ROS1 Melodic

Pick a Shell (terminal tool) from the Tools menu and run the following command:

user:~$ source /opt/ros/melodic/setup.bash
user:~$

Step 3: Source the workspace for ROS2 Dashing

In the same Shell used in Step 2, run the following command:

user:~$ source /opt/ros/dashing/local_setup.bash
ROS_DISTRO was set to 'melodic' before. Please make sure that theenvironment does not mix paths from different distributions.
user:~$

Step 3: Ensure ROS_MASTER_URI is pointing in the right direction:

Still on the same shell, run the following:

user:~$ echo $ROS_MASTER_URI
http://master:11311
user:~$ export ROS_MASTER_URI=http://master:11311
user:~$

Step 4: Communicate between ROS1 & ROS2 with ros1_bridge: start the ros_bridge

Now, start the ros1_bridge and put this terminal on one side – we’re done with it for now.

user:~$ ros2 run ros1_bridge dynamic_bridge
Created 2 to 1 bridge for service /gazebo/clear_body_wrenches
Created 2 to 1 bridge for service /gazebo/clear_joint_forces
Created 2 to 1 bridge for service /gazebo/delete_light
Created 2 to 1 bridge for service /gazebo/delete_model
Created 2 to 1 bridge for service /gazebo/get_joint_properties
Created 2 to 1 bridge for service /gazebo/get_light_properties
Created 2 to 1 bridge for service /gazebo/get_link_properties
...

Step 5: Control the ROS1 TurtleBot2 Simulation from ROS2

Fire up another Shell from the Tools menu and publish to /cmd_vel.

user:~$ source /opt/ros/dashing/local_setup.bash
ROS_DISTRO was set to 'melodic' before. Please make sure that the environment does not mix paths from different distributions.
user:~$ ros2 topic pub /cmd_vel geometry_msgs/Twist "linear:
  x: 0.5
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0"
publisher: beginning loop
publishing #1: geometry_msgs.msg.Twist(linear=geometry_msgs.msg.Vector3(x=0.5, y=0.0, z=0.0), angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0))

In the shell where you’re running the ros1_bridge, you should see messages similar to the following:

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

And, of course, you should see that your robot started to move!

And that was it 😉 . We just controlled a simulation started in ROS1 with ROS2, using the ros1_bridge.

Extra: Video

Prefer to watch a video demonstrating the steps above? We have one for you below! PS: the video uses another simulation, a Parrot Drone, but the concepts are the same.

Related Resources

Feedback

Did you like this post? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS or ROS2 topics, please let us know in the comments area and we will do a video or post about it 🙂

Post edited by Bayode Aderinola

#ROS2 #ROS #ROS2tutorials #Robot

Topics: ros1_bridge | ros2
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

1 Comment

  1. Adi

    Could you also provide a tutorial on installation on our devices please. Installing and setting up for newbies like me is just as hard as actually using these tools

    Reply

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This