Skip to content

Commit

Permalink
[setup] Migrate to use ROS Debian packages (#278)
Browse files Browse the repository at this point in the history
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Co-authored-by: Eric Cousineau <eric.cousineau@tri.global>
  • Loading branch information
3 people authored Nov 27, 2023
1 parent fe146c0 commit d7aa28f
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bazelized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
if: "! contains(github.event.pull_request.labels.*.name, 'status: defer ci')"
runs-on: ubuntu-22.04
container:
image: ros:rolling-ros-base-jammy
image: ros:humble-ros-base-jammy
# This is required for running lldb.
# See https://stackoverflow.com/a/73613377/7829525
options: --cap-add=SYS_PTRACE --security-opt seccomp=unconfined
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/bazelized_drake_ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ jobs:
sudo apt-get install -y libconsole-bridge-dev
sudo rm -rf /var/lib/apt/lists/*
# CI for drake_ros.
- name: Install drake_ros's dependencies
run: yes | sudo ./setup/install_prereqs.sh
working-directory: drake_ros
- name: Build drake_ros
run: bazel build //...
run: export ROS_DISTRO=humble; bazel build //...
working-directory: drake_ros
- name: Test drake_ros
run: bazel test //...
run: export ROS_DISTRO=humble; bazel test //...
working-directory: drake_ros
- name: Clean up drake_ros
run: bazel clean
Expand Down
1 change: 1 addition & 0 deletions drake_ros/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ ros_py_test(
name = "import_test",
srcs = ["test/import_test.py"],
main = "test/import_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [":drake_ros_py"],
)
13 changes: 7 additions & 6 deletions drake_ros/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ load("@bazel_ros2_rules//deps:defs.bzl", "add_bazel_ros2_rules_dependencies")

add_bazel_ros2_rules_dependencies()

load("@bazel_ros2_rules//ros2:defs.bzl", "ros2_archive")
load("@bazel_ros2_rules//ros2:defs.bzl", "ros2_local_repository")
load("//:required_packages.bzl", "DRAKE_ROS_REQUIRED_PACKAGES")
load("//:required_packages.bzl", "DRAKE_ROS_TEST_DEPENDENCIES")

DRAKE_ROS_ALL_DEPENDENCIES = \
DRAKE_ROS_REQUIRED_PACKAGES + DRAKE_ROS_TEST_DEPENDENCIES

# Use ROS 2
ros2_archive(
ros2_local_repository(
name = "ros2",
include_packages = DRAKE_ROS_REQUIRED_PACKAGES + DRAKE_ROS_TEST_DEPENDENCIES, # noqa
sha256_url = "https://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci-CHECKSUM", # noqa
strip_prefix = "ros2-linux",
url = "http://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci.tar.bz2", # noqa
include_packages = DRAKE_ROS_ALL_DEPENDENCIES,
workspaces = ["/opt/ros/humble"],
)

# Depend on Drake
Expand Down
6 changes: 6 additions & 0 deletions drake_ros/drake_ros/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ros_py_test(
name = "core_test",
srcs = ["test/core_test.py"],
main = "test/core_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":drake_ros_py",
":test_pub_and_sub_cc_py",
Expand All @@ -86,6 +87,7 @@ ros_py_test(
name = "tf2_test",
srcs = ["test/tf2_test.py"],
main = "test/tf2_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":drake_ros_py",
"@drake//bindings/pydrake",
Expand All @@ -99,6 +101,7 @@ ros_py_test(
name = "viz_test",
srcs = ["test/viz_test.py"],
main = "test/viz_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":drake_ros_py",
"@drake//bindings/pydrake",
Expand All @@ -112,6 +115,7 @@ ros_py_test(
name = "geometry_conversions_test",
srcs = ["test/geometry_conversions_test.py"],
main = "test/geometry_conversions_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":drake_ros_py",
"@drake//bindings/pydrake",
Expand All @@ -126,6 +130,7 @@ ros_py_test(
name = "odr_py_test",
srcs = ["test/odr_py_test.py"],
main = "test/odr_py_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [":drake_ros_py"],
)

Expand Down Expand Up @@ -157,6 +162,7 @@ ros_py_test(
name = "ros_message_type_caster_test",
srcs = ["test/ros_message_type_caster_test.py"],
main = "test/ros_message_type_caster_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":ros_message_type_caster_test_via_all_py",
":ros_message_type_caster_test_via_specific_types_py",
Expand Down
1 change: 1 addition & 0 deletions drake_ros/required_packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DRAKE_ROS_REQUIRED_PACKAGES = [
"tf2_eigen",
"tf2_ros",
"visualization_msgs",
"rmw_cyclonedds_cpp",
]

DRAKE_ROS_TEST_DEPENDENCIES = [
Expand Down
30 changes: 30 additions & 0 deletions drake_ros/setup/install_prereqs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -eux -o pipefail

apt update && apt install locales
locale-gen en_US en_US.UTF-8
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

apt install software-properties-common
add-apt-repository universe

apt update && apt install curl -y
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

apt update

apt install ros-dev-tools
rosdep init || true
rosdep update

SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIRECTORY
rosdep install --from-paths ../ --rosdistro=humble

apt install ros-humble-test-msgs ros-humble-tf2-ros-py ros-humble-rmw-cyclonedds-cpp ros-humble-tf2-py

# Required for bazel_ros2_rules
apt install python3 python3-toposort
5 changes: 4 additions & 1 deletion drake_ros_examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
py_test(
load("@ros2//:ros_py.bzl", "ros_py_test")

ros_py_test(
name = "drake_ros_py_import_test",
srcs = ["test/drake_ros_py_import_test.py"],
main = "test/drake_ros_py_import_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@drake_ros_repo//:drake_ros_py",
],
Expand Down
8 changes: 3 additions & 5 deletions drake_ros_examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load("@bazel_ros2_rules//deps:defs.bzl", "add_bazel_ros2_rules_dependencies")

add_bazel_ros2_rules_dependencies()

load("@bazel_ros2_rules//ros2:defs.bzl", "ros2_archive")
load("@bazel_ros2_rules//ros2:defs.bzl", "ros2_local_repository")

# N.B. We do *not* name this as `drake_ros` to avoid module shadowing.
# See https://github.com/bazelbuild/bazel/issues/17691
Expand Down Expand Up @@ -52,12 +52,10 @@ ROS_PACKAGES = DRAKE_ROS_REQUIRED_PACKAGES + [
drake_ros_fail_if_missing_required_packages(ROS_PACKAGES)

# Use ROS 2
ros2_archive(
ros2_local_repository(
name = "ros2",
include_packages = ROS_PACKAGES,
sha256_url = "https://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci-CHECKSUM", # noqa
strip_prefix = "ros2-linux",
url = "http://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci.tar.bz2", # noqa
workspaces = ["/opt/ros/humble"],
)

load("@drake_ros_repo//:drake.bzl", "DRAKE_SUGGESTED_VERSION")
Expand Down
2 changes: 2 additions & 0 deletions drake_ros_examples/examples/hydroelastic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ros_cc_binary(
":hydroelastic_share",
],
local_defines = ["BAZEL"],
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@bazel_tools//tools/cpp/runfiles",
"@drake//common:find_resource",
Expand Down Expand Up @@ -52,6 +53,7 @@ ros_py_test(
":hydroelastic",
],
main = "test/hydroelastic_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@ros2//resources/bazel_ros_env:bazel_ros_env_py",
],
Expand Down
3 changes: 3 additions & 0 deletions drake_ros_examples/examples/iiwa_manipulator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load("@ros2//:ros_py.bzl", "ros_py_test")
ros_cc_binary(
name = "iiwa_manipulator",
srcs = ["iiwa_manipulator.cpp"],
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//examples/manipulation_station",
Expand All @@ -26,6 +27,7 @@ ros_py_binary(
name = "iiwa_manipulator_py",
srcs = ["iiwa_manipulator.py"],
main = "iiwa_manipulator.py",
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//bindings/pydrake",
Expand All @@ -42,6 +44,7 @@ ros_py_test(
":iiwa_manipulator_py",
],
main = "test/iiwa_manipulator_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@ros2//resources/bazel_ros_env:bazel_ros_env_py",
],
Expand Down
3 changes: 3 additions & 0 deletions drake_ros_examples/examples/multirobot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ros_cc_binary(
data = [
"@drake//manipulation/models/iiwa_description:models",
],
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//common:find_resource",
Expand All @@ -34,6 +35,7 @@ ros_py_binary(
"@drake//manipulation/models/iiwa_description:models",
],
main = "multirobot.py",
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//bindings/pydrake",
Expand All @@ -50,6 +52,7 @@ ros_py_test(
":multirobot_py",
],
main = "test/multirobot_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@ros2//resources/bazel_ros_env:bazel_ros_env_py",
],
Expand Down
3 changes: 3 additions & 0 deletions drake_ros_examples/examples/rs_flip_flop/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load("@ros2//:ros_py.bzl", "ros_py_test")
ros_cc_binary(
name = "rs_flip_flop",
srcs = ["rs_flip_flop.cpp"],
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//systems/analysis:simulator",
Expand All @@ -23,6 +24,7 @@ ros_py_binary(
name = "rs_flip_flop_py",
srcs = ["rs_flip_flop.py"],
main = "rs_flip_flop.py",
rmw_implementation = "rmw_cyclonedds_cpp",
visibility = ["//visibility:public"],
deps = [
"@drake//bindings/pydrake",
Expand All @@ -40,6 +42,7 @@ ros_py_test(
":rs_flip_flop_py",
],
main = "test/rs_flip_flop_test.py",
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
"@ros2//resources/bazel_ros_env:bazel_ros_env_py",
],
Expand Down
37 changes: 28 additions & 9 deletions drake_ros_examples/setup/install_prereqs.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#!/bin/bash
set -euo pipefail
set -eux -o pipefail

cat_without_comments() {
sed -e 's|#.*||g;' "$(dirname $0)/$1"
}
apt update && apt install locales
locale-gen en_US en_US.UTF-8
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

apt_install () {
apt-get -q install --no-install-recommends "$@"
}
apt install software-properties-common
add-apt-repository universe

apt-get update
apt_install $(cat_without_comments packages-ros2.txt)
apt update && apt install curl -y
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

apt update

apt install ros-dev-tools ros-humble-rmw-cyclonedds-cpp ros-humble-rviz2 ros-humble-ros2cli-common-extensions

rosdep init || true
rosdep update

SCRIPT_DIRECTORY=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIRECTORY/../..
rosdep install --from-paths drake_ros --rosdistro=humble
# TODO(eric.cousineau): This currently fails with
# `Cannot locate rosdep definition for [drake_ros]`. Should fix.
# rosdep install --from-paths drake_ros_examples --rosdistro=humble

# Required for bazel_ros2_rules
apt install python3 python3-toposort
16 changes: 4 additions & 12 deletions ros2_example_bazel_installed/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,12 @@ ROS2_PACKAGES = [
# "rmw_fastrtps_cpp",
]

ros2_archive(
name = "ros2" if not ROS2_DISTRO_PREFIX else "ros2_ignored",
include_packages = ROS2_PACKAGES,
sha256_url = "https://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci-CHECKSUM", # noqa
strip_prefix = "ros2-linux",
# Note: If you want an exact / unchanging version, you will need to mirror
# the archive according to versions you want.
# TODO(hidmic,cottsay): Make release-pinned snapshots of this repository
# once `drake-ros` itself has versions.
url = "http://repo.ros2.org/ci_archives/nightly-cyclonedds/ros2-humble-linux-jammy-amd64-ci.tar.bz2", # noqa
RESOLVED_PREFIX = (
ROS2_DISTRO_PREFIX if ROS2_DISTRO_PREFIX else "/opt/ros/humble"
)

ros2_local_repository(
name = "ros2" if ROS2_DISTRO_PREFIX else "ros2_ignored",
name = "ros2",
include_packages = ROS2_PACKAGES,
workspaces = [ROS2_DISTRO_PREFIX],
workspaces = [RESOLVED_PREFIX],
)
1 change: 1 addition & 0 deletions ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ cmd_test(
ros_py_binary(
name = "simple_talker",
srcs = ["simple_talker.py"],
rmw_implementation = "rmw_cyclonedds_cpp",
deps = [
":ros2_example_apps_msgs_py",
"@ros2//:rclpy_py",
Expand Down
33 changes: 18 additions & 15 deletions ros2_example_bazel_installed/setup/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,27 @@ dpkg_install_from_curl \
https://github.com/bazelbuild/bazel/releases/download/6.4.0/bazel_6.4.0-linux-x86_64.deb \
9276a1e11f03e9f7492f009803c95bddc307993c9ab3c463721c9f6cdaa2ccc1

# TODO(hidmic): install distributions from debians when Drake supports 22.04
# If the user did not explicitly specify their installation prefix, install
# ROS 2 Humble.
if [[ -z "${ROS2_DISTRO_PREFIX:-}" ]]; then
# Install dependencies for ROS 2 Rolling on Jammy tarball
ROS2_APT_SOURCE="deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main"
if ! grep "${ROS2_APT_SOURCE}" /etc/apt/sources.list.d/ros2.list; then
echo ${ROS2_APT_SOURCE} | tee /etc/apt/sources.list.d/ros2.list
fi
apt update && apt install locales
locale-gen en_US en_US.UTF-8
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

apt install software-properties-common
add-apt-repository universe

apt update && apt install curl -y
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null

apt update && apt install python3-rosdep
[[ -d /etc/ros/rosdep ]] || rosdep init
as-user rosdep update --rosdistro=rolling
apt update

# TODO(hidmic): be very explicit about what installation mechanisms we allow
# NOTE: since no ROS distributions has been sourced or specified yet,
# force Python version to 3.x (which is standard in ROS 2 distributions)
SETUP_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
apt install $(env ROS_PYTHON_VERSION=3 rosdep resolve \
$(cat ${SETUP_DIR}/prereq-rosdep-keys.txt) 2>/dev/null | grep -v '^#') libssl-dev
apt install ros-humble-desktop
apt install ros-humble-rmw-cyclonedds-cpp
apt install ros-dev-tools
fi

# Install Python dependencies
Expand Down
Loading

0 comments on commit d7aa28f

Please sign in to comment.