Note: This tutorial assumes that you have completed the previous tutorials: Установка и настройка рабочего окружения ROS.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Navigating the ROS Filesystem

Description: This tutorial introduces ROS filesystem concepts, and covers using the roscd, rosls, and rospack commandline tools.

Tutorial Level: BEGINNER

Next Tutorial: Создание пакета ROS

Prerequisites

For this tutorial we will inspect a package in ros-tutorials, please install it using

$ sudo apt-get install ros-<distro>-ros-tutorials

Replace '<distro>' (including the '<>') with the name of your ROS distribution (e.g. hydro, groovy, electric, fuerte etc.)

Quick Overview of Filesystem Concepts

  • Packages: Packages are the lowest level of ROS software organization. They can contain anything: libraries, tools, executables, etc.

  • Manifest: A manifest is a description of a package. Its most important role is to define dependencies between packages.

  • Stacks: Stacks are collections of packages that form a higher-level library.

  • Stack Manifest: These are just like normal manifests, but for stacks.

When you look at the filesystem, it's easy to tell packages and stacks apart:

  • A package is a directory with a manifest.xml file.
  • A stack is a directory with a stack.xml file.


filesystem_layout.png

Filesystem Tools

Code is spread across many ROS packages and stacks. Navigating with command-line tools such as ls and cd can be very tedious which is why ROS provides tools to help you.

Using rospack and rosstack

rospack and rosstack allow you to get information about packages and stacks. In this tutorial, we are only going to cover the find option, which returns the path to package or stack.

Usage:

$ rospack find [package_name]
$ rosstack find [stack_name]

Example:

$ rospack find roscpp

Would return:

  • YOUR_INSTALL_PATH/share/roscpp

If, for example, you have used the binary install of ROS Fuerte on Ubuntu linux, you would see exactly:

  • /opt/ros/fuerte/share/roscpp

Using roscd

roscd is part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.

Usage:

$ roscd [locationname[/subdir]]

Run this example:

$ roscd roscpp

To verify that we have changed to the roscpp package directory. Now let's print the working directory using the Unix command pwd:

$ pwd

You should see:

  • YOUR_INSTALL_PATH/share/roscpp

You can see that YOUR_INSTALL_PATH/share/roscpp is the same path that rospack find gave in the previous example.

Note that roscd, like other ROS tools, will only find ROS packages that are below the directories listed in your $ROS_PACKAGE_PATH. To see what is in your $ROS_PACKAGE_PATH, type:

$ echo $ROS_PACKAGE_PATH

If you have not modified your $ROS_PACKAGE_PATH, you should see:

  • YOUR_INSTALL_PATH/share:YOUR_INSTALL_PATH/stacks

Similarly to other environment paths, you can add additional directories to your $ROS_PACKAGE_PATH, with each path separated by a colon ':'

Subdirectories

roscd can also move to a subdirectory of a package or stack.

Try:

$ roscd roscpp/cmake
$ pwd

You should see:

  • YOUR_INSTALL_PATH/share/roscpp/cmake

Special cases for roscd

There are a few special places you can tell roscd to go, that are not a package or stack.

roscd with no arguments

roscd without an argument will take you to $ROS_WORKSPACE. Try:

$ roscd
$ pwd

You should see:

  •  /home/user/fuerte_workspace

Note: Prior to Fuerte, roscd would take you to $ROS_ROOT.

roscd log

roscd log will take you to the folder where ROS stores log files. Note that if you have not run any ROS programs yet, this will yield an error saying that it does not yet exist.

If you have run some ROS program before, try:

$ roscd log

Using rosls

rosls is part of the rosbash suite. It allows you to ls directly in a package, stack, or common location by name rather than by package path.

Usage:

$ rosls [locationname[/subdir]]

Example:

$ rosls roscpp_tutorials

Would return:

  • bin  cmake  manifest.xml  srv

Tab Completion

It can get tedious to type out an entire package name. In the previous example, roscpp_tutorials is a fairly long name. Luckily, some ROS tools support TAB completion.

Start by typing:

$ roscd roscpp_tut<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out the rest.

  • $ roscd roscpp_tutorials/

This works because roscpp_tutorials is currently the only ROS package that starts with roscpp_tut.

Now try typing:

$ roscd tur<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out as much as possible:

  • $ roscd turtle

However, in this case there are multiple packages that begin with turtle. Try typing TAB another time. This should display all the ROS packages that begin with turtle

  •   turtle_actionlib/  turtlesim/         turtle_tf/

On the command line you should still have

  • $ roscd turtle

Now type a s after turtle and then push TAB

$ roscd turtles<<< now push the TAB key >>>

Since there is only one package that start with turtles, you should see:

  • $ roscd turtlesim/

Review

You may have noticed a pattern with the naming of the ROS tools:

  • rospack = ros + pack(age)
  • rosstack = ros + stack
  • roscd = ros + cd
  • rosls = ros + ls

This naming pattern holds for many of the ROS tools.

Prerequisites

For this tutorial we will inspect a package in ros-tutorials, please install it using

$ sudo apt-get install ros-<distro>-ros-tutorials

Replace '<distro>' (including the '<>') with the name of your ROS distribution (e.g. indigo, kinetic, lunar etc.)

Quick Overview of Filesystem Concepts

  • Packages: Packages are the software organization unit of ROS code. Each package can contain libraries, executables, scripts, or other artifacts.

  • Manifests (package.xml): A manifest is a description of a package. It serves to define dependencies between packages and to capture meta information about the package like version, maintainer, license, etc...

Show    Note about stacks

Note: rosbuild users might be wondering where stacks went. The concept of stacks was removed with catkin to simplify the growing code base and to support better distribution of packages. In catkin you can define metapackages to collect similar packages and multiple packages can reside in a single VCS repository. Those two features replace the functionality of stacks.

Filesystem Tools

Code is spread across many ROS packages. Navigating with command-line tools such as ls and cd can be very tedious which is why ROS provides tools to help you.

Using rospack

rospack allows you to get information about packages. In this tutorial, we are only going to cover the find option, which returns the path to package.

Usage:

$ rospack find [package_name]

Example:

$ rospack find roscpp

would return:

  • YOUR_INSTALL_PATH/share/roscpp

If you installed ROS Kinetic from apt on Ubuntu Linux you would see exactly:

  • /opt/ros/kinetic/share/roscpp

Using roscd

roscd is part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.

Usage:

$ roscd <package-or-stack>[/subdir]

To verify that we have changed to the roscpp package directory, run this example:

$ roscd roscpp

Now let's print the working directory using the Unix command pwd:

$ pwd

You should see:

  • YOUR_INSTALL_PATH/share/roscpp

You can see that YOUR_INSTALL_PATH/share/roscpp is the same path that rospack find gave in the previous example.

Note that roscd, like other ROS tools, will only find ROS packages that are within the directories listed in your ROS_PACKAGE_PATH. To see what is in your ROS_PACKAGE_PATH, type:

$ echo $ROS_PACKAGE_PATH

Your ROS_PACKAGE_PATH should contain a list of directories where you have ROS packages separated by colons. A typical ROS_PACKAGE_PATH might look like this:

  • /opt/ros/kinetic/base/install/share

Similarly to other environment paths, you can add additional directories to your ROS_PACKAGE_PATH, with each path separated by a colon ':'.

Subdirectories

roscd can also move to a subdirectory of a package or stack.

Try:

$ roscd roscpp/cmake
$ pwd

You should see:

  • YOUR_INSTALL_PATH/share/roscpp/cmake

roscd log

roscd log will take you to the folder where ROS stores log files. Note that if you have not run any ROS programs yet, this will yield an error saying that it does not yet exist.

If you have run some ROS program before, try:

$ roscd log

Using rosls

rosls is part of the rosbash suite. It allows you to ls directly in a package by name rather than by absolute path.

Usage:

$ rosls <package-or-stack>[/subdir]

Example:

$ rosls roscpp_tutorials

would return:

  • cmake launch package.xml  srv

Tab Completion

It can get tedious to type out an entire package name. In the previous example, roscpp_tutorials is a fairly long name. Luckily, some ROS tools support TAB completion.

Start by typing:

$ roscd roscpp_tut<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out the rest:

$ roscd roscpp_tutorials/

This works because roscpp_tutorials is currently the only ROS package that starts with roscpp_tut.

Now try typing:

$ roscd tur<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out as much as possible:

$ roscd turtle

However, in this case there are multiple packages that begin with turtle. Try typing TAB another time. This should display all the ROS packages that begin with turtle:

  • turtle_actionlib/  turtlesim/         turtle_tf/

On the command line you should still have:

$ roscd turtle

Now type an s after turtle and then push TAB:

$ roscd turtles<<< now push the TAB key >>>

Since there is only one package that starts with turtles, you should see:

$ roscd turtlesim/

If you want to see a list of all currently installed packages, you can use tab completion for that as well:

$ rosls <<< now push the TAB key twice >>>

Review

You may have noticed a pattern with the naming of the ROS tools:

  • rospack = ros + pack(age)
  • roscd = ros + cd
  • rosls = ros + ls

This naming pattern holds for many of the ROS tools.

Now that you can get around in ROS, let's create a package.

Wiki: ru/ROS/Tutorials/NavigatingTheFilesystem (last edited 2015-10-19 18:24:48 by IvanSCM)