└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Tutorial: Using `ros1_bridge` Package for ROS1 (Noetic) and ROS2 (Humble) 2 | 3 | In this tutorial, you will learn how to use the [`ros1_bridge`](https://github.com/ros2/ros1_bridge) package to enable communication between ROS1 (Noetic) and ROS2 (Humble). This is useful when transitioning from ROS1 to ROS2, as it allows nodes from both ecosystems to exchange messages seamlessly. 4 | 5 | ## Dependencies 6 | 7 | 1. Ubuntu 20.04 8 | 2. ROS Noetic 9 | 3. ROS2 Humble (Built with source) 10 | 4. ros1_bridge (Built with source) 11 | 12 | ## Installation 13 | 14 | 1. Setup a Ubuntu 20.04 system. [Link](https://releases.ubuntu.com/focal/) 15 | 2. Install ROS Noetic. [Link](https://wiki.ros.org/noetic/Installation/Ubuntu) 16 | 3. Build ROS2 Humble Hawksbill from source. [link](https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#using-the-ros-1-bridge) 17 | (3rd step will take an hour, get some food) 18 | 19 | ## ros1_bridge Setup 20 | 21 | For setting up the ros1_bridge package, create a `bridge_ws` workspace to build the package from source. 22 | 23 | ```sh 24 | mkdir -p ~/bridge_ws/src 25 | cd ~/bridge_ws/src 26 | ``` 27 | 28 | ```sh 29 | git clone https://github.com/ros2/ros1_bridge.git 30 | ``` 31 | 32 | Before building the ROS1 bridge, ensure that everything else is built using standard Colcon arguments. It is not recommended to have the ROS1 environment sourced during this step, as doing so can add additional libraries to the path and potentially cause conflicts. Building your ROS2 workspace without sourcing ROS1 environment variables will help maintain a clean and isolated environment for your ROS2 packages. 33 | 34 | ```sh 35 | cd ~/bridge_ws 36 | colcon build --symlink-install --packages-skip ros1_bridge 37 | ``` 38 | 39 | Source the ROS1 environment now, 40 | 41 | ```sh 42 | source /opt/ros/noetic/setup.bash 43 | # the path may vary as per you installation 44 | ``` 45 | 46 | To ensure that the ROS1 bridge includes support for the necessary message/service packages, it's essential to add the relevant ROS1 and ROS2 workspaces that contain these packages to your environment's PATH. This can be achieved by explicitly specifying dependencies on the message/service packages in the `package.xml`` file of the bridge package. By doing this, Colcon will automatically include them in the path when building the bridge. Alternatively, you can manually source the relevant workspaces to make these packages accessible before building the bridge. This ensures that the bridge is aware of and capable of bridging the specified message/service packages between ROS1 and ROS2. 47 | 48 | Currently we source it manually, 49 | 50 | ```sh 51 | source ~/ros2_humble/install/setup.bash 52 | # the path may vary as per you installation 53 | ``` 54 | 55 | **Note:** Whenever you source ROS1 after sourcing ROS2 or vice-versa, you might observe the follwoing output in the terminal. 56 | (relax and ignore) 57 | 58 | ```text 59 | ROS_DISTRO was set to 'noetic' before. Please make sure that the environment does not mix paths from different distributions. 60 | ``` 61 | 62 | Finally, built the ros1_bridge, it make take around 12 minutes to build. 63 | (time to get a coffee) 64 | 65 | ```sh 66 | colcon build --symlink-install --packages-select ros1_bridge --cmake-force-configure 67 | ``` 68 | 69 | ## Example 1 70 | 71 | Let's try out an example where we initiate a ROS1 Talker (publisher) and a ROS2 Listener (subscriber) using `ros1_bridge`. 72 | 73 | **Terminal-1:** First lets start a ROS1 `roscore`, 74 | 75 | ```sh 76 | source /opt/ros/noetic/setup.bash 77 | roscore 78 | ``` 79 | 80 | **Terminal-2:** The dynamic bridge, once started, functions by monitoring the availability of ROS1 and ROS2 topics. When it identifies a matching topic in both ecosystems, it initiates the bridging process for messages on that specific topic. This allows communication and message exchange between ROS1 and ROS2 nodes, enabling interoperability between the two systems. Let's start the dynamic bridge. 81 | 82 | ```sh 83 | # source the ROS1 environment first 84 | source /opt/ros/noetic/setup.bash 85 | ``` 86 | 87 | ```sh 88 | # now, source the ROS2 environment 89 | source ~/ros2_humble/install/setup.bash 90 | ``` 91 | 92 | ```sh 93 | # source the bridge_ws 94 | source ~/bridge_ws/install/setup.bash 95 | ``` 96 | 97 | ```sh 98 | # connect the ROS_MASTER_URI 99 | export ROS_MASTER_URI=http://localhost:11311 100 | ros2 run ros1_bridge dynamic_bridge 101 | ``` 102 | 103 | The last command will start outputting the currently available topics in ROS1 and ROS2 in a regular interval. 104 | 105 | **Terminal-3:** Here, we will initiate the ROS1 talker 106 | 107 | ```sh 108 | source /opt/ros/noetic/setup.bash 109 | rosrun rospy_tutorials talker 110 | ``` 111 | 112 | **Terminal-4:** Here, we will initiate the ROS2 listener 113 | 114 | ```sh 115 | source ~/ros2_humble/install/setup.bash 116 | ros2 run demo_nodes_cpp listener 117 | ``` 118 | 119 | If the ROS2 node (Terminal-4) starts printing the messages published by ROS1 node (Terminal-3). The ros1_bridge is working successfully. 120 | 121 | ## Example 2 122 | 123 | Now, let's try out an example where we initiate a ROS2 Talker (publisher) and a ROS1 Listener (subscriber) using `ros1_bridge`. 124 | 125 | **Terminal-1:** First lets start a ROS1 `roscore`, 126 | 127 | ```sh 128 | source /opt/ros/noetic/setup.bash 129 | roscore 130 | ``` 131 | 132 | **Terminal-2:** Let's start the dynamic bridge. 133 | 134 | ```sh 135 | # source the ROS1 environment first 136 | source /opt/ros/noetic/setup.bash 137 | ``` 138 | 139 | ```sh 140 | # now, source the ROS2 environment 141 | source ~/ros2_humble/install/setup.bash 142 | ``` 143 | 144 | ```sh 145 | # source the bridge_ws 146 | source ~/bridge_ws/install/setup.bash 147 | ``` 148 | 149 | ```sh 150 | # connect the ROS_MASTER_URI 151 | export ROS_MASTER_URI=http://localhost:11311 152 | ros2 run ros1_bridge dynamic_bridge 153 | ``` 154 | 155 | The last command will start outputting the currently available topics in ROS1 and ROS2 in a regular interval. 156 | 157 | **Terminal-3:** Here, we will initiate the ROS2 talker 158 | 159 | ```sh 160 | source ~/ros2_humble/install/setup.bash 161 | ros2 run demo_nodes_py talker 162 | ``` 163 | 164 | **Terminal-4:** Here, we will initiate the ROS1 listener 165 | 166 | ```sh 167 | source /opt/ros/noetic/setup.bash 168 | rosrun roscpp_tutorials listener 169 | ``` 170 | 171 | ## Example 3 172 | 173 | In this example, we will demonstrate how the bridge can pass larger and more complex messages between ROS1 and ROS2. We'll set up a scenario where a ROS2 node publishes images from a camera, and on the ROS1 side, we'll use rqt_image_view to visualize these images in a graphical user interface (GUI). Additionally, a ROS1 publisher can send a message to toggle an option in the ROS2 node. 174 | 175 | **Terminal-1:** First lets start a ROS1 `roscore`, 176 | 177 | ```sh 178 | source /opt/ros/noetic/setup.bash 179 | roscore 180 | ``` 181 | 182 | **Terminal-2:** Let's start the dynamic bridge. 183 | 184 | ```sh 185 | source /opt/ros/noetic/setup.bash 186 | source ~/ros2_humble/install/setup.bash 187 | source ~/bridge_ws/install/setup.bash 188 | # connect the ROS_MASTER_URI 189 | export ROS_MASTER_URI=http://localhost:11311 190 | ros2 run ros1_bridge dynamic_bridge 191 | ``` 192 | 193 | The last command will start outputting the currently available topics in ROS1 and ROS2 in a regular interval. 194 | 195 | **Terminal-3:** Here, we will initiate the ROS1 GUI 196 | 197 | ```sh 198 | source /opt/ros/noetic/setup.bash 199 | rqt_image_view /image 200 | ``` 201 | 202 | **Terminal-4:** Here, we will initiate the ROS2 image publisher from the `image_tools` 203 | 204 | ```sh 205 | source ~/ros2_humble/install/setup.bash 206 | ros2 run image_tools cam2image 207 | ``` 208 | 209 | ## References 210 | 211 | [1] 212 | 213 | [2] 214 | 215 | [3] 216 | 217 | This tutorial should help you get started with using the ros1_bridge package to enable communication between ROS1 (Noetic) and ROS2 (Humble) nodes. You can extend this knowledge to adapt more complex ROS1 nodes to ROS2 or vice versa as needed for your projects. 218 | (time to open links in a new tab) 219 | --------------------------------------------------------------------------------