ROS 2 extensions

The ROS 2 extensions, helps fill in common settings for software built with the ROS 2 libraries.

There are three extensions in this family, each for a different version of ROS 2.

Extension

Internal name

ROS 2 version

Snap requirements

ROS 2 Foxy

ros2-foxy

ROS 2 Foxy Fitzroy

core20

ROS 2 Humble

ros2-humble

ROS 2 Humble Hawksbill

core22

ROS 2 Jazzy

ros2-jazzy

ROS 2 Jazzy Jalisco

core24

Experimental extensions enabled

All three extensions require Snapcraft 7.3 or higiher.

Included parts

The extension adds its own part to the project, which pulls in the ROS 2 build packages.

Included parts
snapcraft.yaml
ros2-foxy-extension:
  build-packages:
    - ros-foxy-ros-environment
    - ros-foxy-ros-workspace
    - ros-foxy-ament-index-cpp
    - ros-foxy-ament-index-python
  plugin: make
  source: $SNAPCRAFT_EXTENSIONS_DIR/ros2

Included build environment variables

For the main part of the project, the extension sets the following build environment variables.

Included build environment variables
snapcraft.yaml
build-environment:
  - ROS_VERSION: "2"
  - ROS_DISTRO: foxy

Included runtime environment settings

For all apps that use the extension, it initializes a runtime environment required by ROS 2 before launching the app, similar to sourcing the typical ROS 2 local_setup.bash.

Included runtime environment settings
snapcraft.yaml
command-chain:
  - snap/command-chain/ros2-launch
environment:
  PYTHONPATH: $SNAP/opt/ros/foxy/lib/python3.8/site-packages:$SNAP/usr/lib/python3/dist-packages:${PYTHONPATH}
  ROS_DISTRO: foxy
  ROS_VERSION: "2"

Included package repositories

The extension adds the ROS 2 APT package repository build-time configuration for the snap, which installs the necessary GPG key.

Included package repositories
snapcraft.yaml
package-repositories:
  - components:
      - main
    formats:
      - deb
    key-id: C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    key-server: keyserver.ubuntu.com
    suites:
      - focal
    type: apt
    url: http://repo.ros2.org/ubuntu/main

Example expanded project file

Here are examples of the result project files that use the ROS 2 extensions. They demonstrates the added plugs, packages, variables, and layouts that the extensions add to the project file immediately prior to build.

Each example contains the difference between the original file and the output of the snapcraft expand-extensions command. Some of the text has been altered for ease of reading.

The files are based on the ros2-talker-listener project.

Expanded project file for ros2-talker-listener
 name: ros2-talker-listener
 version: "0.1"
 summary: ROS 2 Talker/Listener Example
 description: |
   This example launches a ROS 2 talker and listener.
 
 confinement: devmode
 base: core20
 
 parts:
   ros-demos:
     plugin: colcon
     source: https://github.com/ros2/demos.git
     source-branch: foxy
     source-subdir: demo_nodes_cpp
     stage-packages:
       - ros-foxy-ros2launch
+    build-environment:
+      - ROS_VERSION: "2"
+      - ROS_DISTRO: foxy
+  ros2-foxy-extension:
+    build-packages:
+      - ros-foxy-ros-environment
+      - ros-foxy-ros-workspace
+      - ros-foxy-ament-index-cpp
+      - ros-foxy-ament-index-python
+    plugin: make
+    source: $SNAPCRAFT_EXTENSIONS_DIR/ros2
 
 apps:
   ros2-talker-listener:
     command: opt/ros/foxy/bin/ros2 launch demo_nodes_cpp talker_listener.launch.py
-    extensions:
-      - ros2-foxy
+    command-chain:
+      - snap/command-chain/ros2-launch
+    environment:
+      PYTHONPATH: $SNAP/opt/ros/foxy/lib/python3.8/site-packages:$SNAP/usr/lib/python3/dist-packages:${PYTHONPATH}
+      ROS_DISTRO: foxy
+      ROS_VERSION: "2"
+
+package-repositories:
+  - components:
+      - main
+    formats:
+      - deb
+    key-id: C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
+    key-server: keyserver.ubuntu.com
+    suites:
+      - focal
+    type: apt
+    url: http://repo.ros2.org/ubuntu/main