We’ve not too long ago celebrated the discharge of ROS 2 Humble Hawksbill with a publish detailing tips on how to get began growing for the brand new launch in containers. As well as, we shared an summary of the brand new options included with this new launch, significantly its enhanced security measures.
This week we’re tackling the logical subsequent step in software program growth: packaging. Certainly, as soon as we’re carried out growing our tremendous cool ROS 2 Humble software, we nonetheless need to get it out into the palms of our customers.
On this publish, we’re going to see tips on how to bundle a ROS 2 Humble software as a snap with an ‘howdy world’-like instance.
A ROS 2 Humble snap you mentioned?
Snaps are app packages for desktop, cloud and IoT which are simple to put in, safe, cross‐platform and dependency‐free.
Snaps are the perfect deployment resolution for ROS-based purposes in that they’re a self-contained, sandboxed, cross distribution packaging resolution. To not point out that they natively help ROS to ease your packaging journey. You’ll find additional details about all of the options they provide on the devoted robotics web page!
Firstly, let’s get the software that enables us to create snaps: snapcraft.
sudo snap set up --classic snapcraft
We will even set up LXD which snapcraft makes use of as a backend for clear, confined and reproducible packaging,
sudo snap set up lxd
sudo lxd init --minimal
Be aware that we’ve got initialized LXD with a bunch of default parameters. Head to the LXD documentation when you choose to specify a few of these parameters your self.
We’re all set as much as bundle our first instance, so let’s just do that.
A talker-listener instance
For this instance, we’ll take it simple as we received’t even want to write down any code. As a substitute, we’re going to bundle one of many ROS 2 demo from the GitHub repository. I’ve picked a demo from the ‘demo_nodes_cpp‘ bundle, extra particularly the ‘talker_listener.launch.py‘ demo.
As its identify suggests, this demo launches a ‘talker’ which publishes a string message on a ROS 2 subject. along with a ‘listener’ which reads mentioned message. Each print the message despatched/acquired to the console to simply comply with alongside. And naturally each are launched without delay from a single launch file.
Whereas this instance could appear just a little too easy, it is a perfect first contact with snaps. We’ll see how simple it’s to bundle ROS 2 purposes with snaps.
The snapcraft.yaml file
Snapcraft depends on the ‘snapcraft.yaml’ configuration file to drive the packaging course of. So, allow us to create one,
mkdir -p ~/ros2_ws/first_snap/
after which populate it as follows,
abstract: ROS 2 Humble talker/listener instance
This instance launches a ROS 2 Humble talker and listener.
command: choose/ros/humble/bin/ros2 launch demo_nodes_cpp talker_listener.launch.py
plugs: [network, network-bind]
Imagine it or not, that is all we have to create our snap. However allow us to examine this file extra intently.
Breaking all of it down
We are able to determine 3 distinct blocks within the aforementioned
On the high of the file, there may be some boiler-plate that’s widespread to most snaps. The snap
model and so forth. Nothing uncommon right here. Then comes
base: core22 which is a base snap that may present a runtime surroundings to our software primarily based on Ubuntu 22.04. The final entry on this block is
confinement: strict which states that our software is strictly confined. In different phrases, it can not entry any useful resource on the host machine.
The second block,
apps, specifies the appliance(s) that’s uncovered from the snap. Right here, a single software is listed whose
command could be very acquainted. Moreover, our software additionally lists some
interfaces within the
plugs part. Be aware that Interfaces enable our confined software to entry particular sources of the host machine. On this case, our snap could have entry to network-related interfaces that enable for the ROS 2 subjects to move. Lastly, the
extensions: [ros2-humble] will robotically refill another fields that are widespread to ROS 2 Humble snaps. In case you might be inquisitive about what an extension does, observe which you could ‘increase’ it. Reveal all of its secrets and techniques by issuing the next command,
SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 snapcraft expand-extensions
Finally we’re looking on the third block:
components tag defines the totally different items that make up our ultimate software. They embrace a
supply entry for the supply code resembling native information, a tarball, or as on this instance, a GitHub repository at a selected department. What’s extra, a ‘half’ can embrace
build-packages, that are solely required at construct time in contrast to
stage-packages that are solely wanted at runtime. Most significantly, every half is dealt with by a
plugin. Right here we’re utilizing the
colcon plugin, which makes use of the acquainted construct software in ROS 2. Then once more this plugin has its personal choices, which you’ll be able to evaluate with the command,
snapcraft assist colcon
Now that the
snapcraft.yaml file is outlined, it’s time to construct the snap.
Constructing the ROS 2 Humble snap
To construct the snap, situation the command
snapcraft in a terminal,
$ SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=1 snapcraft
* metallic sound of software program being solid *
Created snap bundle
Snap, reveal your self,
Certainly, there it’s!
How about we set up it now? To take action, sort,
$ sudo snap set up --dangerous ros2-talker-listener_0.1_amd64.snap
ros2-talker-listener 0.1 put in
--dangerousflag since we’re putting in a snap from disk as a substitute of utilizing the retailer.
Okay, however does it
[INFO] [launch]: All log information could be discovered beneath /house/ubuntu/snap/ros2-talker-listener/x6/ros/log/2022-05-24-15-24-50-823207-localhost-24895
[INFO] [launch]: Default logging verbosity is ready to INFO
[INFO] [talker-1]: course of began with pid 
[INFO] [listener-2]: course of began with pid 
[talker-1] 2022-05-24 15:24:51.341 [RTPS_TRANSPORT_SHM Error] Did not create phase ac1bbb6c86049e8a: Permission denied -> Operate compute_per_allocation_extra_size
[listener-2] 2022-05-24 15:24:51.346 [RTPS_TRANSPORT_SHM Error] Did not create phase e75bbd4ac39608ab: Permission denied -> Operate compute_per_allocation_extra_size
[talker-1] 2022-05-24 15:24:51.348 [RTPS_MSG_OUT Error] Permission denied -> Operate init
[listener-2] 2022-05-24 15:24:51.348 [RTPS_MSG_OUT Error] Permission denied -> Operate init
[talker-1] [INFO] [1653420292.379305200] [talker]: Publishing: 'Hi there World: 1'
[listener-2] [INFO] [1653420292.380423139] [listener]: I heard: [Hello World: 1]
[talker-1] [INFO] [1653420293.379072149] [talker]: Publishing: 'Hi there World: 2'
[listener-2] [INFO] [1653420293.379286698] [listener]: I heard: [Hello World: 2]
[talker-1] [INFO] [1653420294.379120962] [talker]: Publishing: 'Hi there World: 3'
[listener-2] [INFO] [1653420294.379682258] [listener]: I heard: [Hello World: 3]
Sure it does! How nice.
What’s even larger is that you can set up and run this snap on one other laptop even when it doesn’t have ROS 2 put in! Heck, you can set up and run this snap on one other Linux distribution from 4 years in the past!
Be aware that the error message from FastDDS, the underlying DDS library, doesn’t stop the appliance from working. In different phrases we are able to safely ignore that for now. If you wish to know extra about how shared-memory performs together with snap, we lined the subject at size in a devoted weblog: “The way to use ROS 2 shared reminiscence in snaps”.
We’ve got seen on this publish tips on how to create a snap for a ROS 2 Humble software. Whereas this demo is pretty trivial, packaging a extra complicated ROS stack isn’t rather more difficult. To display that, take a look on the collection “The way to arrange TurtleBot3 in minutes with snaps” the place I element tips on how to snap the whole Turtlebot3.
Moreover, we’ve seen how one can successfully and simply bundle your ROS 2 software. How about distributing it now? Take a look at how to take action with the shop right here.