ROS1 workspace setup with snap not working

Hi so I’m trying to package my ROS1 noetic project with snapcraft but I just cannot get it to work. Heres the snapcraft.yaml file :

name: ss-delivery-robot
version: '1.0'
summary: ROS software for Sirsteward delivery robots
description: |
  This snap package provides the SS Delivery Robot ROS repository.

confinement: devmode
base: core20

parts:
  ss-delivery-robot:
    plugin: catkin
    source-type: local
    #source: https://christopherlajoie@bitbucket.org/sirsteward/ss_delivery_robot.git
    #source: git@bitbucket.org:sirsteward/ss_delivery_robot.git
    source: .
    #source-branch: feature/snapcraft
    stage-packages:
      - ros-noetic-rosbash # for rosrun
      - ros-noetic-roslaunch # for roslaunch

  start-script:
    plugin: dump
    source-type: local
    source: .
    #source-branch: feature/snapcraft
    organize:
      ros_start_script.sh: bin/

  poetry:
    plugin: python
    python-packages: [poetry]
    build-packages:
      - python3-pip
    stage-packages:
      - libyaml-cpp-dev
      - python3-pip
      - python3
    override-build: |
      pip install poetry
      export POETRY_HOME=/home/sirsteward/for_pr/ss_delivery_robot/.venv:/home/sirsteward/ROS_PROJECT/src/ss_delivery_robot/.venv

apps:
  ros-start-script:
    command: bin/ros_start_script.sh
    plugs: [network, network-bind]
    #environment:
      #PATH: $SNAP/opt/ros/noetic/bin:$PATH
      #PYTHONPATH: $SNAP/opt/ros/noetic/lib/python3/dist-packages:$PYTHONPATH
    extensions: [ros1-noetic]

So basically, it’s a multiple-node ros project and I have it cloned in the same folder as the snapcraft.yaml file. As you can see, I import poetry which is used in the project (or at least I try, it seems that the installation doesn’t work even though I put the commands in override-build) and I also import ros_start_script.sh which is used to launch all the nodes wanted, heres what the file look like:

#!/bin/bash
set -e

#sleep 90

# setup ros environment


source "/home/sirsteward/ROS_PROJECT/devel/setup.bash"
#source /var/lib/snapd/hostfs/opt/ros/noetic/setup.bash
#source /snap/ss-delivery-robot/x1/opt/ros/noetic/setup.bash
#cd "/var/lib/snapd/hostfs/home/sirsteward/ROS_PROJECT/src/ss_delivery_robot"
cd "/home/sirsteward/ROS_PROJECT/src/ss_delivery_robot"
source ".env"
if [[ "$MODULES_SELECTOR" == "True" ]]; then
  printf "Modules selector is enabled\n"
  source "robot_modules_selection.sh"
fi
source ".env"
dt=$(date '+%Y-%m-%d_%H:%M:%S')

if [[ "$ENVIRONMENT" != *"DEBUG"* ]]; then
  printf "Starting node manager\n"
  poetry run roslaunch node_manager_pkg node_manager.launch timestamp:=$dt
fi

exec "$@"

Honestly, im not sure where I should source my ROS environment cause from the debugging I have done it seems that the line that isnt commented doesn’t work. When I finish building, install and then launch it with ss-delivery-robot.ros-start-script I get roslaunch not found error.

Im new to using snapcraft and I dont get why Im having such a hard time making it work. I tried shelling into my build and from there I was able to manually install poetry and source roslaunch but even then it couldnt find the node_manager.launch file.

Obviously there is something wrong with the way Im building my app and I want to know what it is

Hello,

Thank you for posting on the forum.

From what I can see, the parts ss-delivery-robot and start-script looks perfect to me. The catkin plugin of snapcraft is only installing file that are listed with install rules in your CMakeLists.txt. Is that node_manager.launch properly installed with CMake?

For the python part: peotry, the python plugin manages pyptoject.toml, so the override-build called is actually overriding the default action of the plugin. From what I can see in your override-build I don’t think it’s necessary, and you should be able to simply remove that section. But in case you want to keep your custom build in addition to the plugin build, you can do:

    override-build: |
      pip install poetry
      snapcraftctl build # the default plugin action that will install your project

Regarding your starting script, I can see that a lot of paths are hardcoded with path on your desktop. By default, snapcraft is building the snap inside a container or a VM. Once snapped, the application should use resources relative to itself ($SNAP). If a snap is strictly confined, it won’t be able to use resources outside of $SNAP. Only resources installed via the snapcraft.yaml can be used and referenced.
So in the starting script, all the references to /home/sirteward/... won’t work.

The

extensions: [ros1-noetic]

that you are already using in your snapcraft.yaml is already taking care of sourcing your workspace as well as your ROS environment. Similarly, no need to source a python venv since they are installed at the root of the snap ($SNAP).

While I am not familiar with poetry, why is it necessary to launch the launchfile with it? why not just calling:

$SNAP/roslaunch node_manager_pkg node_manager.launch timestamp:=$dt

I am also not certain about the last line of your script. Keep in mind that if you want your snap to be able to call a command passed to it, it will happen inside the snap environment. Is it intentional to be able to call any command passed to the snap?

I also recommand for debugging your snap (and see the environment it is executing in) to call the command:

snap run --shell ss-delivery-robot.ros-start-script
cd $SNAP

This way, you can easily see where your files are within your snap.

The section Application debugging of the ROS snap dev guide part 2 can also be a good starting point to debug efficiently your snap.