Skip to content
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

Add ros1_bridge example (Ubuntu Focal, ROS 2 Humble, ROS 1 Noetic) #778

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ros/humble/ubuntu/focal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Instructions

```bash
# Build ROS 2 humble from source in a focal container
cd ros-core
docker build . -t ros:humble-ros-core-focal

# Install ROS 1 binaries and then build the ros1_bridge with colcon.
cd ../ros1-bridge
docker build . -t ros:humble-ros1-bridge-focal
dit ros:humble-ros1-bridge-focal
echo $CMAKE_PREFIX_PATH
echo $ROS1_INSTALL_PATH
echo $ROS2_INSTALL_PATH

source ${ROS1_INSTALL_PATH}/setup.bash
# Now, source your local workspace with your messages
source install/setup.bash # Assume this sources /opt/ros/humble underlay
# You should see standard ROS message packages and your custom ones below.
ros2 pkg list | grep msgs
```
83 changes: 83 additions & 0 deletions ros/humble/ubuntu/focal/ros-core/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Adapted from ros/foxy/ubuntu/focal/ros-core/Dockerfile
# Usage:
# docker build . -t ros:humble-ros-core-focal
#
# Documentation for ros1_bridge setup: https://github.com/ros2/ros1_bridge?tab=readme-ov-file#building-the-bridge-from-source

# We use focal becaue ROS 1 can be installed with binaries,
# and ROS 2 humble supports compilation as a Tier 3 platform per REP-2000.
# There is another repository that uses a Jammy base image, but requires
# more changes.
# https://github.com/TommyChangUMD/ros-humble-ros1-bridge-builder/issues/21

FROM ubuntu:focal

# setup timezone
RUN echo 'Etc/UTC' > /etc/timezone && \
ln -s /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
apt-get update && \
apt-get install -q -y --no-install-recommends tzdata && \
rm -rf /var/lib/apt/lists/*

# install packages
RUN apt-get update && apt-get install -q -y --no-install-recommends \
dirmngr \
gnupg2 \
&& rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA

# setup sources.list
RUN echo "deb http://snapshots.ros.org/foxy/final/ubuntu focal main" > /etc/apt/sources.list.d/ros2-snapshots.list

# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

ENV ROS_DISTRO humble

# install ros2 packages
# Note - There don't seem to be separate VCS files for core, base, and everything.
# For now, just use upstream's big list.

# https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#install-development-tools-and-ros-tools
RUN apt-get update && apt-get install -y --no-install-recommends \
python3-flake8-docstrings \
python3-pip \
python3-pytest-cov \
ros-dev-tools \
&& rm -rf /var/lib/apt/lists/*

RUN python3 -m pip install -U \
flake8-blind-except \
flake8-builtins \
flake8-class-newline \
flake8-comprehensions \
flake8-deprecated \
flake8-import-order \
flake8-quotes \
"pytest>=5.3" \
pytest-repeat \
pytest-rerunfailures

WORKDIR /ws

RUN mkdir src
RUN vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src
RUN apt-get update && \
rosdep init && \
rosdep update && \
rosdep install --from-paths src --ignore-src -y --skip-keys \
"fastcdr rti-connext-dds-6.0.1 urdfdom_headers"

# Disable testing to make the build faster.
RUN colcon build --install-base /opt/ros/humble --cmake-args -DBUILD_TESTING=OFF

ENV ROS2_INSTALL_PATH=/opt/ros/humble

# setup entrypoint
COPY ./ros_entrypoint.sh /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
6 changes: 6 additions & 0 deletions ros/humble/ubuntu/focal/ros-core/ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# setup ros2 environment
# source "/opt/ros/$ROS_DISTRO/setup.bash" --
exec "$@"
66 changes: 66 additions & 0 deletions ros/humble/ubuntu/focal/ros1-bridge/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Adapted from ros/foxy/ubuntu/focal/ros1-bridge/Dockerfile

# Usage:
# docker build . -t ros:humble-ros1-bridge-focal

FROM ros:humble-ros-core-focal as base

# install ros1 packages
RUN set -eux; \
key='C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654'; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \
mkdir -p /usr/share/keyrings; \
gpg --batch --export "$key" > /usr/share/keyrings/ros1-latest-archive-keyring.gpg; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"

# setup sources.list
RUN echo "deb [ signed-by=/usr/share/keyrings/ros1-latest-archive-keyring.gpg ] http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros1-latest.list

# Install ROS 1 binaries, plus the message dependencies.
# If they don't have ROS 1 message binaries, you will need to set up a catkin workspace to build.
RUN apt-get update && apt-get install -y --no-install-recommends \
ros-noetic-ros-core=1.5.0-1* \
ros-noetic-mavros-msgs \
&& rm -rf /var/lib/apt/lists/*

ENV ROS1_INSTALL_PATH=/opt/ros/noetic

FROM base as final

# The path or URL to the VCS repos.
ARG VCS_MSG_FILE="custom_msgs.repos"
# Which packages to build
ARG CUSTOM_MSG_PKGS="mavros_msgs"


WORKDIR /ws
RUN rm -rf src/* build install log
# This COPY is only necessary if you have a local file.
# If it's in a repo, comment this out and supply it as a build arg.
COPY $VCS_MSG_FILE .
RUN vcs import --input $VCS_MSG_FILE src
# Custom messages may have dependencies.
# Ignore any errors to keep it simple.
RUN apt-get update && \
rosdep update && \
rosdep install --from-paths src --ignore-src -y -r --skip-keys \
"fastcdr rti-connext-dds-6.0.1 urdfdom_headers"
# Build all custom messge packages here in the right order.
RUN . /opt/ros/humble/setup.sh && colcon build --packages-up-to ${CUSTOM_MSG_PKGS}

# Source the local workspace then build just the ros1_bridge.
# This links to all the other message packages at build time.
# Order of sourcing is VERY picky and NOT clear in the ros1_bridge README.
# https://github.com/ros2/ros1_bridge?tab=readme-ov-file#building-the-bridge-from-source
# This shows the source order with custom workspaces
# https://github.com/jayprajapati009/ros1_bridge_tutorial?tab=readme-ov-file#ros1_bridge-setup
RUN . /opt/ros/noetic/setup.sh && . /opt/ros/humble/setup.sh && . install/setup.sh && colcon build --packages-select ros1_bridge

# setup entrypoint
COPY ./ros_entrypoint.sh /

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]

17 changes: 17 additions & 0 deletions ros/humble/ubuntu/focal/ros1-bridge/custom_msgs.repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repositories:
ros2/ros1_bridge:
type: git
url: https://github.com/ros2/ros1_bridge.git
version: master

# MAVROS depends on geographic_msgs, but it's not available on focal.
# Therefore, we add it here.
# mavros_msgs: No definition of [geographic_msgs] for OS version [focal]
ros-geographic-info/geographic_info:
type: git
url: https://github.com/ros-geographic-info/geographic_info.git
version: ros2
mavlink/mavros:
type: git
url: https://github.com/mavlink/mavros.git
version: ros2
6 changes: 6 additions & 0 deletions ros/humble/ubuntu/focal/ros1-bridge/ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# setup ros2 environment
# source "/opt/ros/$ROS_DISTRO/setup.bash" --
exec "$@"