Search code examples
drakeros2

Pulling ROS2 packages in via bazel WORKSPACE mech in drake-ros_*


Question related to Drake-ros's #142 - I am unable to pull in the rviz_2d_overlay_plugins in drake_ros_viz via the bazel WORKSPACE mech. I have tried both focal and jammy rolling/humble distributions. I see the following error -

ERROR: no such package '@ros2//': Failed to setup @ros2 repository: './run.bash /home/arrowhead/.cache/bazel/_bazel_arrowhead/90cc0dfb7c9efd65bbcc1ee9dd934f8e/external/bazel_ros2_rules/ros2/scrape_distribution.py -i geometry_msgs -i rclcpp -i rclpy -i tf2_ros -i tf2_ros_py -i visualization_msgs -i rviz_2d_overlay_plugins -o distro_metadata.json' exited with 1
--- captured stderr ---
Traceback (most recent call last):
  File "/home/arrowhead/.cache/bazel/_bazel_arrowhead/90cc0dfb7c9efd65bbcc1ee9dd934f8e/external/bazel_ros2_rules/ros2/scrape_distribution.py", line 54, in <module>
    main()
  File "/home/arrowhead/.cache/bazel/_bazel_arrowhead/90cc0dfb7c9efd65bbcc1ee9dd934f8e/external/bazel_ros2_rules/ros2/scrape_distribution.py", line 46, in main
    distro = scrape_distribution(
  File "/home/arrowhead/.cache/bazel/_bazel_arrowhead/90cc0dfb7c9efd65bbcc1ee9dd934f8e/external/ros2/resources/ros2bzl/scraping/__init__.py", line 90, in scrape_distribution
    packages, dependency_graph = build_dependency_graph(
  File "/home/arrowhead/.cache/bazel/_bazel_arrowhead/90cc0dfb7c9efd65bbcc1ee9dd934f8e/external/ros2/resources/ros2bzl/scraping/__init__.py", line 50, in build_dependency_graph
    raise RuntimeError(msg)
RuntimeError: Cannont find package 'rviz_2d_overlay_plugins'

I see the package on ROS Index here and my relevant WORKSPACE Bazel bit is given below.

ros2_archive(
    name = "ros2",
    include_packages = [
        "geometry_msgs",
        "rclcpp",
        "rclpy",
        "tf2_ros",
        "tf2_ros_py",
        "visualization_msgs",
        "rviz_2d_overlay_plugins"
    ],

    sha256_url = "https://build.ros2.org/view/Hci/job/Hci__nightly-cyclonedds_ubuntu_jammy_amd64/lastSuccessfulBuild/artifact/ros2-humble-linux-jammy-amd64-ci-CHECKSUM",  # noqa
    strip_prefix = "ros2-linux",
    url = "https://build.ros2.org/view/Hci/job/Hci__nightly-cyclonedds_ubuntu_jammy_amd64/lastSuccessfulBuild/artifact/ros2-humble-linux-jammy-amd64-ci.tar.bz2",  # noqa
)

Solution

  • Primary Suggestion: You may want to consider installing ROS Humble directly onto your Jammy OS, and then use ros2_local_repository rather than ros2_archive:
    https://github.com/RobotLocomotion/drake-ros/blob/06dc6aa7d0237f4edb74130bcce8e9e78689d50c/bazel_ros2_rules/ros2/defs.bzl#L221-L239

    Then you should be able to use a locally installed ROS 2 version, and install the package you want, either to /opt/ros or in a workspace that you're chaining.

    FTR, in Anzu at TRI, we use ros2_archive presently for the following reasons (some of which are my opinions):

    • We wanted to use ROS 2 Humble on Focal, possibly mixing multiple different versions along different checkouts.
    • I want things to update only when I (we) precisely want. (For high confidence reproducibility, also to denoise apt upgrade)
      • For reproduciblity, I want us to maintain the ability to have decent reproducibility without aggressive containerization.

    This means you should consolidate your development solely onto Jammy. If you are already containerizing, then that should hopefully not be too large of a jump.

    Alternative: If you really want to maintain archives, is to build your own extension archive including the packages you want. Here's an example kinda-hack that I had shimmed into Anzu:
    https://github.com/EricCousineau-TRI/repro/tree/4079be209bfbc282d4580b5b2979faa148e1f394/ros/drake_ros_example_layered_archive