5.10. Inspecting ROS packages#
As you have seen ROS packages, such as turtlesim
,
collect all the necessary stuff for some kind of functionalities of the robotic system.
In a package could be zero or more programs, such as ROS nodes or other utilities, but also custom messages, and/or launch files and RViz configuration
(launch files and RViz configurations will be discussed later in this manual).
Real-world ROS applications combine functionality from many different packages.
In practice, each package is maintained by a maintainer or team of maintainers, all code in the package has the same software license, and usually there is a single GitHub repository for the package where development happens and bug reports are reported.
5.10.1. The ros2 pkg
CLI tool#
The ros2 pkg
(package) command is a very useful command to understand what ROS
packages are installed on your system, where they are installed, and the
executables contained within each package. These tools are particularly useful
for understanding an existing robot configuration and finding tools that are
only used on occasion. Let’s start by taking a look at the help file for the pkg
command:
$ ros2 pkg -h
usage: ros2 pkg [-h] Call `ros2 pkg <command> -h` for more detailed usage. ...
Various package related sub-commands
optional arguments:
-h, --help show this help message and exit
Commands:
create Create a new ROS2 package
executables Output a list of package specific executables
list Output a list of available packages
prefix Output the prefix path of a package
xml Output the XML of the package manifest or a specific tag
Call `ros2 pkg <command> -h` for more detailed usage.
Note
The first sub command in the pkg
command is create
.
create
is a tool to help you create a ROS package.
We’ll use this sub command in a later chapter after you have learned about development workspaces.
For now it suffices to know that this command will help you setup
template code for creating new ROS packages.
The subject of creating new packages is outside the scope of this section.
5.10.2. Listing available packages in your workspace#
This command has a variety of sub commands, many of which should look fairly
familiar at this point. The list
sub command acts in a manner very similar to
list
sub commands we have discussed previously, but this one only lists the
installed system packages. This sub command is often used with grep
to help you
find out if a particular package is installed.
Once you have located an installed package you can then have it list the
executables contained by the package using the executables
command. This is
much more practical than finding the executables manually. The sub command takes
in a single argument which is the package name. The executables command has a
single optional argument, --full-path
, which will output the full path to all
the executable programs. The example below shows how to use these
commands to check the path for all of the turtlesim executables:
$ ros2 pkg list | grep turtle
turtlesim
$ ros2 pkg executables turtlesim --full-path
/opt/ros/humble/lib/turtlesim/draw_square
/opt/ros/humble/lib/turtlesim/mimic
/opt/ros/humble/lib/turtlesim/turtle_teleop_key
/opt/ros/humble/lib/turtlesim/turtlesim_node
5.10.3. Locating where packages are installed on your system#
If you just wanted to know the path to the turtlesim
executables you could use
the prefix
sub command.
It returns the path for a given package’s executables.
For example:
$ ros2 pkg prefix turtlesim
/opt/ros/humble
5.10.4. Finding the maintainer and license of a package#
Each ROS package contains an XML file that contains metadata for the package
including information such as the license, maintainer, and its dependencies. ROS
pkg has a handy xml
sub command to print these files to the screen, saving you
the hassle of locating and opening the file.
You can use grep
on the output of this command to get just the info you need.
Below is an example of xml
to find the maintainer and license of turtlesim
:
$ ros2 pkg xml turtlesim | grep maintainer
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
$ ros2 pkg xml turtlesim | grep license
<license>BSD</license>