ROS is distributed via Open Robotics’ own Debian archive, along with many community-supported tools. It’s possible to get your own application into their archive as well, but it requires that the application is open-source.
You’re also left with the question of how to update ROS and your application on a robotic platform that has already been shipped. With snapcraft it’s just one command to bundle a specific ROS version along with your application into a snap that works anywhere and can be automatically updated.
Ready to get started? By the end of this guide, you’ll understand how to make a snap of your app that can be published in the Snap Store, showcasing it to millions of Linux users.
For a brief overview of the snap creation process, including how to install snapcraft and how it’s used, see Snapcraft overview. For a more comprehensive breakdown of the steps involved, take a look at Creating a snap.
Snaps are defined in a single YAML file placed in the root folder of your project. The following example shows the entire snapcraft.yaml file for an example project, ros-talker-listener. Don’t worry, we’ll break this down.
name: test-ros-talker-listener version: '0.1' summary: ROS Talker/Listener Example description: | This example launches a ROS talker and listener. base: core18 confinement: devmode parts: ros-tutorials: plugin: catkin source: https://github.com/ros/ros_tutorials.git source-branch: melodic-devel source-space: roscpp_tutorials/ apps: run: command: roslaunch roscpp_tutorials talker_listener.launch
snapcraft.yaml file starts with a small amount of human-readable metadata, which usually can be lifted from the GitHub description or project README.md. This data is used in the presentation of your app in the Snap Store.
name: test-ros-talker-listener version: '0.1' summary: ROS Talker/Listener Example description: | This example launches a ROS talker and listener.
name must be unique in the Snap Store. Valid snap names consist of lower-case alphanumeric characters and hyphens. They cannot be all numbers and they also cannot start or end with a hyphen.
Versions carry no semantic meaning in snaps and this version is arbitrary. It’s also possible to write a script to calculate the version, or to take a tag or commit from a git repository.
summary can not exceed 79 characters. You can use a chevron ‘>’ in the
description key to declare a multi-line description.
The base keyword defines a special kind of snap that provides a run-time environment with a minimal set of libraries that are common to most applications. They’re transparent to users, but they need to be considered, and specified, when building a snap.
To get started we won’t confine this application. Unconfined applications, specified with
devmode, can only be released to the hidden “edge” channel where you and other developers can install them.
Parts define how to build your app. Parts can be anything: programs, libraries, or other assets needed to create and run your application. In this case we have one: ros-tutorials. Parts can point to local directories, remote git repositories, or tarballs.
Snapcraft builds on top of the
catkin tool, familiar to any ROS1 developer, to create snaps for people to install on Linux.
Important note: Most ROS1 developers run out of the
devel space. As a result, it’s easy to forget the importance of good install rules, i.e. rules for installing every component of the package necessary to run, or every component necessary to use a given library.
The Catkin packages you’re building must have good install rules, or the snapcraft CLI won’t know which components to place into the snap. Make sure you install binaries, libraries, header files, launch files, etc.
parts: ros-tutorials: plugin: catkin source: https://github.com/ros/ros_tutorials.git source-branch: melodic-devel source-space: roscpp_tutorials/
For more details on Catkin-specific metadata, see The catkin plugin.
Apps are the commands and services exposed to end users. If your Apps are the commands you want to expose to users and any background services your application provides. Each key under
apps is the command name that should be made available on users’ systems.
command specifies the path to the binary to be run. This is resolved relative to the root of your snap contents and automatically searches in the
bin sub directories of your snap.
apps: run: command: roslaunch roscpp_tutorials talker_listener.launch
If your command name matches the snap
name, users will be able run the command directly. If the names differ, then apps are prefixed with the snap
test-xsv.command-name, for example). This is to avoid conflicting with apps defined by other installed snaps.
If your application is intended to run as a service you simply add the line
daemon: simple after the command keyword. This will automatically keep the service running on install, update and reboot.
You can request an alias on the Snapcraft forum if your command name and snap name do not match but you don’t want your command prefixed. These aliases are set up automatically when your snap is installed from the Snap Store.
You can download the example repository with the following command:
$ git clone https://github.com/snapcraft-docs/ros-talker-listener
After you’ve created the snapcraft.yaml, you can build the snap by simply executing the snapcraft command in the project directory:
$ snapcraft Using 'snapcraft.yaml': Project assets will be searched for from the 'snap' directory. Launching a VM. [...] Snapped test-ros-talker-listener_0.1_amd64.snap
The resulting snap can be installed locally. This requires the
--dangerous flag because the snap is not signed by the Snap Store. The
--devmode flag acknowledges that you are installing an unconfined application:
$ sudo snap install test-ros-talker-listener_*.snap --devmode --dangerous
You can then try it out:
$ test-ros-talker-listener.run [...]
Removing the snap is simple too:
$ sudo snap remove test-ros-talker-listener
You can also clean up the build environment, although this will slow down the next initial build:
$ snapcraft clean
By default, when you make a change to snapcraft.yaml, snapcraft only builds the parts that have changed. Cleaning a build, however, forces your snap to be rebuilt in a clean environment and will take longer.
To share your snaps you need to publish them in the Snap Store. First, create an account on the dashboard. Here you can customise how your snaps are presented, review your uploads and control publishing.
You’ll need to choose a unique “developer namespace” as part of the account creation process. This name will be visible by users and associated with your published snaps.
Make sure the
snapcraft command is authenticated using the email address attached to your Snap Store account:
$ snapcraft login
You can publish your own version of a snap, provided you do so under a name you have rights to. You can register a name on dashboard.snapcraft.io, or by running the following command:
$ snapcraft register myrossnap
Be sure to update the
name: in your
snapcraft.yaml to match this registered name, then run
Use snapcraft to push the snap to the Snap Store.
$ snapcraft upload --release=edge myrossnap_*.snap
If you’re happy with the result, you can commit the snapcraft.yaml to your GitHub repo and turn on automatic builds so any further commits automatically get released to edge, without requiring you to manually build locally.
Congratulations! You’ve just built and published your first ROS snap. For a more in-depth overview of the snap building process, see Creating a snap.
Last updated 8 days ago. Help improve this document in the forum.