Skip to content

Commit

Permalink
ROS1 Bridge ported to ROS2 humble (#248)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description

<!--- Describe your changes in detail -->
This PR updates the dockerfile for ros1_bridge to support humble
inspired by:
https://github.com/TommyChangUMD/ros-humble-ros1-bridge-builder/tree/main.
Due to base image change from 20.04 to 22.04 because of Humble, ROS1
side of the installation and dependencies needed to be installed
"manually" which is captured in this Dockerfile. Also:

- It still uses USDOT's fork of the ros1_bridge which is updated to most
recent in here: usdot-fhwa-stol/ros1_bridge#27.
It needed few more extra functions from above 3rd party repo to
successfuly build for CARMA
- Currently it uses `ros:humble-ros-base-jammy` as the base image
instead of `usdotfhwastoldev/carma-base:develop-humble` image, which I
believe is leaner without all the extra dependencies that carma-base
has.

## Related GitHub Issue
NA
<!--- This project only accepts pull requests related to open GitHub
issues or Jira Keys -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please DO NOT name partially fixed issues, instead open an issue
specific to this fix -->
<!--- Please link to the issue here: -->

## Related Jira Key
[ARC-156](https://usdot-carma.atlassian.net/browse/ARC-156)
<!-- e.g. CAR-123 -->

## Motivation and Context
CARMA migration to ROS2 Humble
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
Built using dockerhub using carma-msgs Dockerifle
And tested in cdasim xil carma cloud use case 
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Defect fix (non-breaking change that fixes an issue)
- [X] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that cause existing functionality
to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [X] I have added any new packages to the sonar-scanner.properties file
- [X] My change requires a change to the documentation.
- [X] I have updated the documentation accordingly.
- [X] I have read the
[**CONTRIBUTING**](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)
document.
- [X] I have added tests to cover my changes.
- [X] All new and existing tests passed.


[ARC-156]:
https://usdot-carma.atlassian.net/browse/ARC-156?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
MishkaMN authored Nov 6, 2024
1 parent 04ea195 commit d5bb481
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 48 deletions.
101 changes: 85 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,92 @@
ARG DOCKER_ORG=usdotfhwastoldev
ARG DOCKER_TAG=develop
FROM ${DOCKER_ORG}/carma-base:${DOCKER_TAG} as base_image
SHELL ["/bin/bash", "-c"]
FROM ros:humble-ros-base-jammy as base-install

ARG DEBIAN_FRONTEND="noninteractive"
ARG GIT_BRANCH=develop-humble

# Make sure bash catches errors (no need to chain commands with &&, use ; instead)
SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-c"]

###########################
# 1.) Bring system up to the latest ROS desktop configuration
###########################
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install ros-humble-desktop

###########################
# 2.) Temporarily remove ROS2 apt repository
###########################
RUN mv /etc/apt/sources.list.d/ros2-latest.list /root/
RUN apt-get update

###########################
# 3.) comment out the catkin conflict
###########################
RUN sed -i -e 's|^Conflicts: catkin|#Conflicts: catkin|' /var/lib/dpkg/status
RUN apt-get install -f

###########################
# 4.) force install these packages
###########################
RUN apt-get download python3-catkin-pkg
RUN apt-get download python3-rospkg
RUN apt-get download python3-rosdistro
RUN dpkg --force-overwrite -i python3-catkin-pkg*.deb
RUN dpkg --force-overwrite -i python3-rospkg*.deb
RUN dpkg --force-overwrite -i python3-rosdistro*.deb
RUN apt-get install -f

###########################
# 5.) Install the latest ROS1 desktop configuration
# see https://packages.ubuntu.com/jammy/ros-desktop-dev
# note: ros-desktop-dev automatically includes tf tf2
###########################
RUN apt-get -y install ros-desktop-dev --allow-downgrades --allow-remove-essential --allow-change-held-packages

###########################
# 6.) Restore the ROS2 apt repos and set compilation options.
# And install ROS2 dependencies for ros1_bridge
###########################
RUN mv /root/ros2-latest.list /etc/apt/sources.list.d/

RUN apt-get -y update && apt-get install -y \
ros-humble-rmw \
ros-humble-rmw-implementation \
ros-humble-rmw-fastrtps-cpp \
ros-humble-rmw-cyclonedds-cpp \
wait-for-it

######################################
# 7.) Compile custom message
######################################

RUN mkdir -p /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs
COPY . /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/

# Since Noetic is not supported on Linux 22.04, this manually installs the dependency packages
# This is outside checkout.bash to not accidentally modify during release process and
# not to introduce indirect dependency between install and checkout scripts
RUN vcs import --input /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/docker/noetic-dependencies.repos \
/home/carma/.base-image/ros1_msgs_ws/src/

RUN mkdir -p /home/carma/.base-image/ros2_msgs_ws/src/carma_msgs
COPY . /home/carma/.base-image/ros2_msgs_ws/src/carma_msgs/
RUN mkdir -p /home/carma/.base-image/workspace/src
RUN /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/docker/checkout.bash -b develop-humble -r \
/home/carma/.base-image/workspace
RUN /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/docker/install.sh

###########################
# 8.) Clean up
###########################
RUN apt-get -y clean all; apt-get -y update

###########################
# 9.) Metadata
###########################
ARG VERSION="NULL"
ARG VCS_REF="NULL"
ARG BUILD_DATE="NULL"
ARG GIT_BRANCH=develop

LABEL org.label-schema.schema-version="1.0" \
org.label-schema.name="carma-msgs" \
Expand All @@ -17,14 +96,4 @@ LABEL org.label-schema.schema-version="1.0" \
org.label-schema.url="https://highways.dot.gov/research/research-programs/CARMA" \
org.label-schema.vcs-url="https://github.com/usdot-fhwa-stol/carma-msgs" \
org.label-schema.vcs-ref=${VCS_REF} \
org.label-schema.build-date=${BUILD_DATE}

RUN mkdir -p ~/.base-image/ros1_msgs_ws/src/carma_msgs
RUN mkdir -p /home/carma/src
COPY . /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/
RUN mkdir -p ~/.base-image/ros2_msgs_ws/src/carma_msgs
COPY . /home/carma/.base-image/ros2_msgs_ws/src/carma_msgs/

RUN /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/docker/checkout.bash -b ${GIT_BRANCH} -r /home/carma/.base-image/workspace

RUN /home/carma/.base-image/ros1_msgs_ws/src/carma_msgs/docker/install.sh
org.label-schema.build-date=${BUILD_DATE}
2 changes: 1 addition & 1 deletion carma_cmake_common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(carma_cmake_common NONE)
project(carma_cmake_common CXX)

find_package(ros_environment REQUIRED)

Expand Down
2 changes: 1 addition & 1 deletion carma_debug_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cmake_minimum_required(VERSION 3.5)
project(carma_debug_msgs)

## Compile as C++14, supported in ROS Noetic and newer
## Compile as c++14, supported in ROS Noetic and newer
add_compile_options(-std=c++14)

find_package(carma_cmake_common REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion carma_debug_ros2_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_debug_ros2_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_driver_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_driver_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_localization_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_localization_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_perception_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_perception_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_planning_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_planning_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion carma_v2x_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(carma_v2x_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_check_ros_version(2)
Expand Down
2 changes: 1 addition & 1 deletion cav_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cmake_minimum_required(VERSION 3.5)
project(cav_msgs)

## Compile as C++14, supported in ROS Noetic and newer
## Compile as c++14, supported in ROS Noetic and newer
add_compile_options(-std=c++14)

find_package(carma_cmake_common REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion cav_srvs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cmake_minimum_required(VERSION 3.5)
project(cav_srvs)

## Compile as C++14, supported in ROS Noetic and newer
## Compile as c++14, supported in ROS Noetic and newer
# add_compile_options(-std=c++14)

find_package(carma_cmake_common REQUIRED)
Expand Down
6 changes: 3 additions & 3 deletions docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ echo "Final image name: $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING"
cd ..
if [[ $COMPONENT_VERSION_STRING = "develop" ]]; then
sed "s|usdotfhwastoldev/|$USERNAME/|g; s|usdotfhwastolcandidate/|$USERNAME/|g; s|usdotfhwastol/|$USERNAME/|g; s|:[0-9]*\.[0-9]*\.[0-9]*|:$COMPONENT_VERSION_STRING|g; s|checkout.bash|checkout.bash -d|g" \
Dockerfile | docker build -f - --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
Dockerfile | docker build -f - -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
--build-arg VERSION="$COMPONENT_VERSION_STRING" \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` .
elif [[ $COMPONENT_VERSION_STRING = "SNAPSHOT" ]]; then
docker build --network=host --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
docker build --network=host -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
--build-arg ROS1_PACKAGES="$ROS1_PACKAGES" \
--build-arg ROS2_PACKAGES="$ROS2_PACKAGES" \
--build-arg VERSION="$COMPONENT_VERSION_STRING" \
Expand All @@ -143,7 +143,7 @@ else
#The addition of --network=host was a fix for a DNS resolution error that occured
#when running the platform inside an Ubuntu 20.04 virtual machine. The error and possible soliutions are
# discussed here: https://github.com/moby/moby/issues/41003
docker build --network=host --no-cache -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
docker build --network=host -t $USERNAME/$IMAGE:$COMPONENT_VERSION_STRING \
--build-arg VERSION="$COMPONENT_VERSION_STRING" \
--build-arg VCS_REF=`git rev-parse --short HEAD` \
--build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` .
Expand Down
47 changes: 30 additions & 17 deletions docker/install.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
#!/bin/bash
set -e

# ROS 1 msgs setup
# Prepare workspace for ROS Noetic dependencies and Autoware messages
mkdir -p /home/carma/.base-image/ros1_msgs_ws/src/autoware.ai

# Copy Autoware.ai messages into ROS1 workspace
cp -R /home/carma/autoware.ai/messages /home/carma/.base-image/ros1_msgs_ws/src/autoware.ai/
cp -R /home/carma/autoware.ai/jsk_common_msgs /home/carma/.base-image/ros1_msgs_ws/src/autoware.ai/
cp -R /home/carma/autoware.ai/jsk_recognition /home/carma/.base-image/ros1_msgs_ws/src/autoware.ai/

# ROS 2 msgs setup
mkdir -p ~/.base-image/ros2_msgs_ws/src/autoware.ai
# ROS1 CARMA message and dependency setup
cd /home/carma/.base-image/ros1_msgs_ws
unset ROS_DISTRO
export ROS_VERSION=1
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to \
pcl_msgs \
autoware_msgs cav_msgs cav_srvs j2735_v2x_msgs can_msgs carma_debug_msgs autoware_lanelet2_msgs carma_cooperative_perception_interfaces

# ROS2 CARMA message setup
mkdir -p /home/carma/.base-image/ros2_msgs_ws/src/autoware.ai
cp -R /home/carma/autoware.ai/messages /home/carma/.base-image/ros2_msgs_ws/src/autoware.ai/
cp -R /home/carma/autoware.ai/jsk_common_msgs /home/carma/.base-image/ros2_msgs_ws/src/autoware.ai/
cp -R /home/carma/autoware.ai/jsk_recognition /home/carma/.base-image/ros2_msgs_ws/src/autoware.ai/

# Cleanup autoware repo once messages have been moved
# Clean up Autoware repository after moving messages
rm -rf /home/carma/autoware.ai/

# ROS1 message setup
cd ~/.base-image/ros1_msgs_ws && source /opt/ros/noetic/setup.bash && colcon build --packages-up-to autoware_msgs cav_msgs cav_srvs j2735_v2x_msgs can_msgs carma_debug_msgs autoware_lanelet2_msgs carma_cooperative_perception_interfaces

# ROS2 message setup
cd ~/.base-image/ros2_msgs_ws && source /opt/ros/humble/setup.bash && colcon build --packages-up-to autoware_msgs autoware_lanelet2_msgs can_msgs carma_debug_ros2_msgs carma_driver_msgs carma_localization_msgs carma_msgs carma_perception_msgs carma_planning_msgs carma_v2x_msgs j2735_v2x_msgs carma_cooperative_perception_interfaces
cd /home/carma/.base-image/ros2_msgs_ws
source /opt/ros/humble/setup.bash
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to \
autoware_msgs autoware_lanelet2_msgs can_msgs carma_debug_ros2_msgs carma_driver_msgs carma_localization_msgs \
carma_msgs carma_perception_msgs carma_planning_msgs carma_v2x_msgs j2735_v2x_msgs carma_cooperative_perception_interfaces

# Build the bridge
source /opt/ros/noetic/setup.bash
source /opt/ros/humble/setup.bash
source ~/.base-image/ros1_msgs_ws/install/local_setup.bash
source ~/.base-image/ros2_msgs_ws/install/local_setup.bash
cd ~/.base-image/workspace/src
cd ../
sudo apt-get update
colcon build --event-handlers console_direct+ --packages-select ros1_bridge --cmake-force-configure
sudo chmod -R ugo+x ~/.base-image/workspace/install
source /home/carma/.base-image/ros1_msgs_ws/install/local_setup.bash
source /home/carma/.base-image/ros2_msgs_ws/install/local_setup.bash
cd /home/carma/.base-image/workspace/

MEMG=$(printf "%.0f" $(free -g | awk '/^Mem:/{print $2}')); \
NPROC=$(nproc); MIN=$((MEMG<NPROC ? MEMG : NPROC)); \
echo "Please wait... running $MIN concurrent jobs to build ros1_bridge"; \
time MAKEFLAGS="-j $MIN" colcon build --event-handlers console_direct+ \
--cmake-args -DCMAKE_BUILD_TYPE=Release --packages-select ros1_bridge --cmake-force-configure
sudo chmod -R ugo+x /home/carma/.base-image/workspace/install
5 changes: 5 additions & 0 deletions docker/noetic-dependencies.repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repositories:
pcl_msgs:
type: git
url: https://github.com/ros-perception/pcl_msgs.git
version: noetic-devel
2 changes: 1 addition & 1 deletion j3224_v2x_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

cmake_minimum_required(VERSION 3.5)
project(j3224_v2x_msgs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)

find_package(carma_cmake_common REQUIRED)
carma_package()
Expand Down

0 comments on commit d5bb481

Please sign in to comment.