Disclosure: read the post until the end, a surprise awaits you!
Moving from ROS 1 to ROS 2 can be a little overwhelming.
It is a lot of (new) concepts, tools and a large codebase to get familiar with. And just like many of you, I am getting started with ROS 2.
One of the central pieces of the ROS ecosystem is its Command Line Interface (CLI). It allows for performing all kind of actions; from retrieving information about the codebase and/or the runtime system, to executing code and of course helping debugging in general. It’s a very valuable set of tools that ROS developers use on a daily basis. Fortunately, pretty much all of those tools were ported from ROS 1 to ROS 2.
To those already familiar with ROS, the ROS 2 CLI wording will sound very familiar. Commands such as
roslaunch is ported to
ros2 topic while
rosparam is now
Noticed the pattern already ? Yes that’s right ! The keyword ‘
ros2‘ has become the unique entry-point for the CLI.
So what ? ROS CLI keywords where broke in two and that’s it ?
Well, yes pretty much.
Every command starts with the
ros2 keyword, followed by a verb, a sub-verb and possibly positional/optional arguments. The pattern is then,
$ ros2 verb sub-verb <positional-argument> <optional-arguments>
Notice that throughout the CLI, the auto-completion (the infamous [tab][tab]) is readily available for verbs, sub-verbs and most positional arguments. Similarly, helpers are available at each stage,
$ ros2 verb --help
$ ros2 verb sub-verb -h
Let us see a few examples,
$ ros2 run demo_node_cpp talker
talker cpp node from the demo_nodes_cpp package.
$ ros2 run demo_node_py listener
listener python node from the demo_nodes_py package.
$ ros2 topic echo /chatter
outputs the messages sent from the
$ ros2 node info /listener
outputs information about the
$ ros2 param list
lists all parameters of every node.
Fairly similar to ROS 1 right ?
Missing CLI tools
We mentioned earlier that most of the CLI tools were ported to ROS 2, but not all. We believe such missing tools is one of the barriers to greater adoption of ROS 2, so we’ve started added some that we noticed were missing. Over the past week we contributed 5 sub-verbs, including one that is exclusive to ROS 2. Let us briefly review them,
$ ros2 topic find <message-type>
outputs a list of all topics publishing messages of a given type (#271).
$ ros2 topic type <topic-name>
outputs the message type of a given topic (#272).
$ ros2 service find <service-type>
outputs a list of all services of a given type (#273).
$ ros2 service type <service-name>
outputs the service type of a given service (#274).
This tools are pretty handy by themselves, especially to debug and grasp an overview of a running system. And they become even more interesting when combined, say, in handy little scripts,
$ ros2 topic pub /chatter $(ros2 topic type /chatter) "data: Hello ROS 2 Developers"
Have you ever looked for the version of a package you are using ?
Ever wondered who is the package author ?
Or which other packages it depends upon ?
All of this information, locked in the package’s xml manifest is now easily available at the tip of your fingers !
The new sub-verb we introduced allows one to retrieve any information contained in a package xml manifest (#280). The command,
$ ros2 pkg xml <package-name>
outputs the entirety of the xml manifest of a given package.
To retrieve solely a piece of it, or a
tag in xml wording, use the
$ ros2 pkg xml <package-name> --tag <tag-name>
A few examples are (at the time of writing),
$ ros2 pkg xml demo_nodes_cpp --tag version
$ ros2 pkg xml demo_nodes_py -t author
$ ros2 pkg xml intra_process_demo -t build_depend libopencv-dev
This concludes our brief review of the changes that ROS 2 introduced to the CLI tools.
Before leaving, let me offer you a treat.
— A ROS 2 CLI Cheats Sheet that we put together —
Feel free to share it, print and pin it above your screen but also contribute to it as it is hosted on github !