Hello together, I knew that in ROS1 there is a way to build a snap containing only roscore and build other packages as snaps than on top of the Ros runtime snap. Is this also possible? The Idea is to have a ROS2 foxy as a base snap and than for example an overlay snap "simple talker listener " as a snap which uses the Plug from ROS2 packed in the first snap?
Hi @Mohamedaminhamdad,
I believe you are talking about the βcontent-sharingβ functionality of snaps applied to ROS 2 applications. This feature is not supported for ROS 2 at the moment but good news we are working on it! Weβll make sure to announce it both on the Ubuntu blog and here on the ROS Discourse so stay tune.
Hey Jeremie,
what I meant is to overlay a workspace (Snap Listener/Talker) on top of a general ROS2 distribution (Snap 2) using plugs and slots. Iβve tried to do so. Thatβs what Iβve done so far, but still It didnβt work:
I have a snap containing ros2 foxy as a stand-alone ros-base. Iβve done that by building ros2 foxy using the colcon plugin and snapping the install folder, using the following snapcraft file.
name: ros-base
version: '0.1'
summary: Basic ROS2 listener component
description: |
Basic ROS2 listener component based on core20
grade: stable
confinement: strict
base: core20
parts:
dump:
plugin: colcon
stage-packages: [
ros-foxy-ros2launch,
ros-foxy-ros-core,]
build-environment:
- ROS_VERSION: '2'
- ROS_DISTRO: foxy
slots:
ros-base:
interface: content
content: executables
read: [/]
private: false
After that I tried to build an overlay snap (simple Hello World talker node) using the following snapcraft file,
name: overlay
version: '0.1'
summary: Basic ROS2 listener component
description: |
Basic ROS2 listener component based on core20
grade: stable
confinement: strict
base: core20
parts:
dump:
plugin: colcon
source: src
build-packages: [make, gcc, g++]
stage-packages: [ros-foxy-ros2launch, ros-foxy-common-interfaces]
override-build: |
snapcraftctl build
build-environment:
- ROS_VERSION: '2'
- ROS_DISTRO: foxy
wrapper-scripts:
plugin: dump
source: ./wrappers/
organize:
./wrapping.wrapper.sh : usr/bin/ros2-custom-ws
apps:
app4:
command: usr/bin/ros2-custom-ws
plugs:
ros-base:
interface: content
content: executables
target: $SNAP/mohamed
private: false
My wrapper file looks like that:
#!/bin/bash
ROS_BASE=$SNAP/mohamed
export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/blas
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/lapack
source $SNAP/mohamed/opt/ros/foxy/setup.bash
$SNAP/opt/ros/snap/lib/py_pubsub/talker
After connecting both snaps slots and plugs I can run the overlay snap using the following command: overlay.app4 Howevere, when doing so, I get the following error:
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Traceback (most recent call last):
File "/snap/overlay/x1/opt/ros/snap/lib/py_pubsub/talker", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3254, in <module>
def _initialize_master_working_set():
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3237, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3266, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 584, in _build_master
ws.require(__requires__)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 901, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 787, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'py-pubsub==0.0.0' distribution was not found and is required by the application
My workspace for my overlay ros snap looks like that:
βββ snap
β βββ snapcraft.yaml
βββ src
β βββ py_pubsub
β βββ launch
β β βββ publisher_launch.py
β βββ package.xml
β βββ py_pubsub
β β βββ __init__.py
β β βββ publisher_member_function.py
β βββ resource
β β βββ py_pubsub
β βββ setup.cfg
β βββ setup.py
β βββ test
β βββ test_copyright.py
β βββ test_flake8.py
β βββ test_pep257.py
βββ wrappers
βββ wrapping.wrapper.sh
after modifying the wrapper and sourcing the ./local_setup.bash.
#!/bin/bash
ROS_BASE=$SNAP/mohamed
export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3.8/dist-packages
export PYTHONPATH=$PYTHONPATH:$ROS_BASE/usr/lib/python3/dist-packages
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/lib/$TRIPLET
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROS_BASE/usr/lib/$TRIPLET
source $SNAP/mohamed/opt/ros/foxy/setup.bash
source $SNAP/local_setup.bash && $SNAP/py_pubsub/lib/py_pubsub/talker
The distribution py_pubsub is found. Howevere, now i get the following error:
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Traceback (most recent call last):
File "/snap/overlay/x1/py_pubsub/lib/py_pubsub/talker", line 33, in <module>
sys.exit(load_entry_point('py-pubsub==0.0.0', 'console_scripts', 'talker')())
File "/snap/overlay/x1/py_pubsub/lib/py_pubsub/talker", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/snap/overlay/x1/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 2, in <module>
from rclpy.node import Node
File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 42, in <module>
from rclpy.client import Client
File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/client.py", line 22, in <module>
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module>
rclpy_implementation = _import('._rclpy')
File "/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/__init__.py", line 28, in _import
return importlib.import_module(name, package='rclpy')
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libspdlog.so.1: cannot open shared object file: No such file or directory
The C extension '/snap/overlay/x1/mohamed/opt/ros/foxy/lib/python3.8/site-packages/rclpy/_rclpy.cpython-38-x86_64-linux-gnu.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions
Hi @Mohamedaminhamdad,
The ROS Discourse isnβt really the place to address help queries. Since youβve also open a thread on the Snapcraft forum I will take the discussion over there.