Repository navigation
Docs: bridge ROS 1 and ROS 2 with ros1_bridge #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| --- | ||
| title: Bridging ROS 1 and ROS 2 | ||
| slug: Ros1Bridge | ||
| description: Connect ROS 1 Noetic and ROS 2 Humble nodes with ros1_bridge, built from source in a Pixi project. | ||
| --- | ||
|
|
||
| [`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). | ||
|
|
||
| :::caution[Keep Noetic and Humble in separate environments] | ||
| 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. | ||
| ::: | ||
|
|
||
| ## Set up | ||
|
|
||
| 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. | ||
|
|
||
| `pixi.toml`: | ||
|
|
||
| ```toml | ||
| [workspace] | ||
| name = "ros1-bridge" | ||
| channels = ["https://prefix.dev/robostack-noetic", "https://prefix.dev/robostack-humble", "https://prefix.dev/conda-forge"] | ||
| platforms = ["linux-64", "linux-aarch64", { platform = "osx-arm64", macos = "14.0" }] | ||
|
|
||
| [feature.noetic.dependencies] | ||
| ros-noetic-ros-base = "*" | ||
| ros-noetic-rospy-tutorials = "*" | ||
|
|
||
| [feature.humble.dependencies] | ||
| ros-humble-ros-base = "*" | ||
| ros-humble-demo-nodes-cpp = "*" | ||
| ros-humble-rmw-implementation-cmake = "*" | ||
| compilers = "*" | ||
| cmake = "*" | ||
| ninja = "*" | ||
| pkg-config = "*" | ||
| colcon-common-extensions = "*" | ||
|
|
||
| [feature.humble.activation] | ||
| scripts = ["noetic-underlay.sh"] | ||
|
|
||
| [environments] | ||
| noetic = { features = ["noetic"], no-default-feature = true } | ||
| humble = { features = ["humble"], no-default-feature = true } | ||
| ``` | ||
|
|
||
| `noetic-underlay.sh`, next to it: | ||
|
|
||
| ```sh | ||
| NOETIC="$PIXI_PROJECT_ROOT/.pixi/envs/noetic" | ||
| export ROS1_INSTALL_PATH="$NOETIC" | ||
| export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}$NOETIC/lib/pkgconfig" | ||
| export ROS_PACKAGE_PATH="$NOETIC/share" | ||
| export ROS_MASTER_URI="${ROS_MASTER_URI:-http://localhost:11311}" | ||
| export PYTHONPATH="${PYTHONPATH:+$PYTHONPATH:}$NOETIC/lib/python3.12/site-packages" | ||
| export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:+$CMAKE_PREFIX_PATH:}$CONDA_PREFIX:$NOETIC" | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| ```sh | ||
| pixi install -a | ||
| git clone https://github.com/ros2/ros1_bridge.git ws/src/ros1_bridge | ||
| cd ws | ||
| pixi run -e humble colcon build --cmake-args -G Ninja -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DPython3_FIND_VIRTUALENV=ONLY \ | ||
| -DCMAKE_CXX_STANDARD=23 -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON | ||
| ``` | ||
|
|
||
| `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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Run | ||
|
|
||
| Each command in its own terminal, in `ws`: | ||
|
|
||
| ```sh | ||
| pixi run -e noetic roscore | ||
| pixi run -e humble bash -c "source install/setup.bash && ros2 run ros1_bridge dynamic_bridge --bridge-all-topics" | ||
| pixi run -e noetic rosrun rospy_tutorials talker | ||
| pixi run -e humble ros2 run demo_nodes_cpp listener | ||
| ``` | ||
|
|
||
| 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`. | ||
|
|
||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried using
pixi-build-rosinstead?Also, wouldn't it make more sense to package it before writing a tutorial for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude (AI assistant) here, replying on behalf of @Tobias-Fischer. I tried
pixi-build-rosnow (macOS arm64, latest Humble and Noetic). It builds and the bridge works in both directions, but it needs more workarounds than the colcon build:noeticenvironment withenventries (ROS1_INSTALL_PATH,PKG_CONFIG_PATH,PYTHONPATH, ...), and mapsxmlrpcpp(which would become the non-existentros-humble-xmlrpcpp) to nothing.envhave to be normalised ($(cd ... && pwd)): with$RECIPE_DIR/../..the generator finds each ROS 1 service twice and the generated code doesn't compile.rosidl_runtime_cpp/traits.hppin C++23 mode (no transitive<locale>include), so the compilers need pinning to 21 viabuild-variants.pixi rundoesn't passDYLD_*variables, so I had to add the rpath to the installed binaries withinstall_name_toolby hand.So it works, but the result is a package tied to one workspace's Noetic environment, and the setup is longer and more fragile than the colcon build. A real package (in the monorepo) would need Noetic and Humble in one host prefix without clashing files, so I'd keep the tutorial with colcon for now.
🤖 Claude (AI assistant), on behalf of @Tobias-Fischer