Your submission was sent successfully! Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

Part 1 - exercise: Add additional application to the snap

This exercise requires having followed the part 1.

Let’s do a little exercise. Right now, our talker-listener only has one application. How about you add another one? Having the ROS 2 topic tools inside our snap would be great for some introspection.


Modify the snapcraft.yaml file:

  • Add a new app entry for ros2topic
  • Add the corresponding dependencies

Build and install the new snap.


By the end of this exercise, you will have a new command available:

ros2-talker-listener.ros2topic hz /chatter

  • Note that the ROS 2 topic tools are only going to work with message types that are included in the snap.


The solution
  • Add ros2topic as a stage-package to have it available at run time:
    plugin: colcon
    source-branch: humble
    source-subdir: demo_nodes_cpp
-   stage-packages: [ros-humble-ros2launch]
+   stage-packages: [ros-humble-ros2launch, ros-humble-ros2topic]

We add our dependency (ros-humble-ros2topic) to the stage-packages list. Stage-packages are packages that are required to run the part. Here we decided to add our dependency to our already existing ros-demos part for simplicity. Alternatively, we could have created an additional empty part simply to add our stage-packages dependency.

  • Add an additional app:
    command: opt/ros/humble/bin/ros2 launch talker-listener
    daemon: simple
    plugs: [network, network-bind]
    extensions: [ros2-humble]
+ ros2topic:
+   command: opt/ros/humble/bin/ros2 topic
+   plugs: [network, network-bind]
+   extensions: [ros2-humble]

We added another application entry to our snap. We kept the plugs and extensions and simply exposed the ros2 topic command.

  • Build and install the new snap:
sudo snap install ros2-talker-listener_0.1_*.snap --dangerous

Make sure everything works:

$ ros2-talker-listener.ros2topic hz /chatter
average rate: 1.000 min: 0.999s max: 1.000s std dev: 0.00049s window: 3

This page was last modified 5 months ago. Help improve this document in the forum.