ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Note that snapcraft currently only supports building workspaces into snaps, not individual ROS packages. This is a known shortcoming and is slated to be fixed this cycle. The easiest workaround for this is to use a rosinstall file, which will cause snapcraft to create a workspace on your behalf instead of requiring you to do it.

To describe how this is done, I'll alter the snap tutorial you're calling to use a rosinstall file. First of all, let's create our snapcraft yaml:

$ mkdir ~/my-snap
$ cd ~/my-snap
$ snapcraft init
Created snap/snapcraft.yaml.
Go to https://docs.snapcraft.io/the-snapcraft-format/8337 for more information about the snapcraft.yaml format.

Edit the snap/snapcraft.yaml and make it look like this:

name: ros-talker-listener
version: '0.1'
summary: ROS Talker/Listener Example
description: |
  This example launches a ROS talker and listener.

confinement: devmode
base: core18

parts:
  ros-tutorials:
    plugin: catkin
    source: .
    rosinstall-files: [ros_tutorials.rosinstall]
    catkin-packages: [roscpp_tutorials]
    build-packages: [lsb-release]  # I needed this in LXD, you may not

apps:
  ros-talker-listener:
    command: roslaunch roscpp_tutorials talker_listener.launch

Note the use of rosinstall-files. Let's create a ros_tutorials.rosinstall file alongside the snap/ directory:

$ touch ~/my-snap/ros_tutorials.rosinstall

Make that file look like the following:

- git: {local-name: ros_tutorials, uri: 'https://github.com/ros/ros_tutorials.git', version: melodic-devel}

Save, and build the snap. Note the installation of wstool and the workspace merging happening before fetching dependencies and whatnot:

$ snapcraft
<snip>
Pulling ros-tutorials 
Installing wstool...
<snip>
Initializing workspace (if necessary)...
Merging /root/parts/ros-tutorials/src/ros_tutorials.rosinstall
Updating workspace...
<snip>
Installing apt dependencies...
<snip>
Building ros-tutorials
<snip>
Snapped ros-talker-listener-test_0.1_amd64.snap

Note that snapcraft currently only supports building workspaces into snaps, not individual ROS packages. This is a known shortcoming and is slated to be fixed this cycle. The easiest workaround for this is to use a rosinstall file, which will cause snapcraft to create a workspace on your behalf instead of requiring you to do it.

To describe how this is done, I'll alter the snap tutorial you're calling using to use a rosinstall file. First of all, let's create our snapcraft yaml:

$ mkdir ~/my-snap
$ cd ~/my-snap
$ snapcraft init
Created snap/snapcraft.yaml.
Go to https://docs.snapcraft.io/the-snapcraft-format/8337 for more information about the snapcraft.yaml format.

Edit the snap/snapcraft.yaml and make it look like this:

name: ros-talker-listener
version: '0.1'
summary: ROS Talker/Listener Example
description: |
  This example launches a ROS talker and listener.

confinement: devmode
base: core18

parts:
  ros-tutorials:
    plugin: catkin
    source: .
    rosinstall-files: [ros_tutorials.rosinstall]
    catkin-packages: [roscpp_tutorials]
    build-packages: [lsb-release]  # I needed this in LXD, you may not

apps:
  ros-talker-listener:
    command: roslaunch roscpp_tutorials talker_listener.launch

Note the use of rosinstall-files. Let's create a ros_tutorials.rosinstall file alongside the snap/ directory:

$ touch ~/my-snap/ros_tutorials.rosinstall

Make that file look like the following:

- git: {local-name: ros_tutorials, uri: 'https://github.com/ros/ros_tutorials.git', version: melodic-devel}

Save, and build the snap. Note the installation of wstool and the workspace merging happening before fetching dependencies and whatnot:

$ snapcraft
<snip>
Pulling ros-tutorials 
Installing wstool...
<snip>
Initializing workspace (if necessary)...
Merging /root/parts/ros-tutorials/src/ros_tutorials.rosinstall
Updating workspace...
<snip>
Installing apt dependencies...
<snip>
Building ros-tutorials
<snip>
Snapped ros-talker-listener-test_0.1_amd64.snap