|
| 1 | +--- |
| 2 | +title: Bridging ROS 1 and ROS 2 |
| 3 | +slug: Ros1Bridge |
| 4 | +description: Connect ROS 1 Noetic and ROS 2 Humble nodes with ros1_bridge, built from source in a Pixi project. |
| 5 | +--- |
| 6 | + |
| 7 | +[`ros1_bridge`](https://github.com/ros2/ros1_bridge) passes topics and services between ROS 1 and ROS 2, for example between a robot running ROS 1 Noetic and a computer running ROS 2 Humble. It isn't packaged, but builds from source in a Pixi project. Tested on Linux (aarch64) and macOS (Apple silicon). |
| 8 | + |
| 9 | +:::caution[Keep Noetic and Humble in separate environments] |
| 10 | +Both distributions have packages with the same names (`std_msgs`, `rosgraph_msgs`, ...). In one environment, their Python modules and CMake files overwrite each other, which breaks `roscore` and building the bridge. |
| 11 | +::: |
| 12 | + |
| 13 | +## Set up |
| 14 | + |
| 15 | +One Pixi project with two environments, `noetic` and `humble`. The `humble` environment uses `noetic` as an underlay, like sourcing `/opt/ros/noetic` before `/opt/ros/humble` on Ubuntu. |
| 16 | + |
| 17 | +`pixi.toml`: |
| 18 | + |
| 19 | +```toml |
| 20 | +[workspace] |
| 21 | +name = "ros1-bridge" |
| 22 | +channels = ["https://prefix.dev/robostack-noetic", "https://prefix.dev/robostack-humble", "https://prefix.dev/conda-forge"] |
| 23 | +platforms = ["linux-64", "linux-aarch64", { platform = "osx-arm64", macos = "14.0" }] |
| 24 | + |
| 25 | +[feature.noetic.dependencies] |
| 26 | +ros-noetic-ros-base = "*" |
| 27 | +ros-noetic-rospy-tutorials = "*" |
| 28 | + |
| 29 | +[feature.humble.dependencies] |
| 30 | +ros-humble-ros-base = "*" |
| 31 | +ros-humble-demo-nodes-cpp = "*" |
| 32 | +ros-humble-rmw-implementation-cmake = "*" |
| 33 | +compilers = "*" |
| 34 | +cmake = "*" |
| 35 | +ninja = "*" |
| 36 | +pkg-config = "*" |
| 37 | +colcon-common-extensions = "*" |
| 38 | + |
| 39 | +[feature.humble.activation] |
| 40 | +scripts = ["noetic-underlay.sh"] |
| 41 | + |
| 42 | +[environments] |
| 43 | +noetic = { features = ["noetic"], no-default-feature = true } |
| 44 | +humble = { features = ["humble"], no-default-feature = true } |
| 45 | +``` |
| 46 | + |
| 47 | +`noetic-underlay.sh`, next to it: |
| 48 | + |
| 49 | +```sh |
| 50 | +NOETIC="$PIXI_PROJECT_ROOT/.pixi/envs/noetic" |
| 51 | +export ROS1_INSTALL_PATH="$NOETIC" |
| 52 | +export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}$NOETIC/lib/pkgconfig" |
| 53 | +export ROS_PACKAGE_PATH="$NOETIC/share" |
| 54 | +export ROS_MASTER_URI="${ROS_MASTER_URI:-http://localhost:11311}" |
| 55 | +export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}$NOETIC/lib/python3.12/site-packages" |
| 56 | +export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:+$CMAKE_PREFIX_PATH:}$CONDA_PREFIX:$NOETIC" |
| 57 | +``` |
| 58 | + |
| 59 | +## Build |
| 60 | + |
| 61 | +```sh |
| 62 | +pixi install -a |
| 63 | +git clone https://github.com/ros2/ros1_bridge.git ws/src/ros1_bridge |
| 64 | +cd ws |
| 65 | +pixi run -e humble colcon build --cmake-args -G Ninja -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DPython3_FIND_VIRTUALENV=ONLY \ |
| 66 | + -DCMAKE_CXX_STANDARD=23 -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON |
| 67 | +``` |
| 68 | + |
| 69 | +`CMAKE_INSTALL_RPATH_USE_LINK_PATH` lets the bridge find the ROS 1 libraries without `LD_LIBRARY_PATH`, and C++23 is needed for clang on macOS. |
| 70 | + |
| 71 | +The bridge supports the message types present in both environments; `ros-base` gives about 130 (`std_msgs`, `geometry_msgs`, `sensor_msgs`, `nav_msgs`, ...). For more, add the message packages to both features (e.g. `ros-noetic-tf2-msgs` and `ros-humble-tf2-msgs`) and build again. |
| 72 | + |
| 73 | +## Run |
| 74 | + |
| 75 | +Each command in its own terminal, in `ws`: |
| 76 | + |
| 77 | +```sh |
| 78 | +pixi run -e noetic roscore |
| 79 | +pixi run -e humble bash -c "source install/setup.bash && ros2 run ros1_bridge dynamic_bridge --bridge-all-topics" |
| 80 | +pixi run -e noetic rosrun rospy_tutorials talker |
| 81 | +pixi run -e humble ros2 run demo_nodes_cpp listener |
| 82 | +``` |
| 83 | + |
| 84 | +The listener prints the messages of the ROS 1 talker. To use an existing ROS 1 master, e.g. on a robot, set `ROS_MASTER_URI` instead of running `roscore`. |
| 85 | + |
| 86 | +On macOS, set `ROS_HOSTNAME=localhost` for the ROS 1 nodes when everything runs on one machine, and `ROS_LOCALHOST_ONLY=1` if ROS 2 nodes on the same machine don't see each other. |
0 commit comments