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
Now you should see a Simulation window pop up with the 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
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
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
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.
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