Embedded Motion Control/Tutorials/Navigating the ROS filesystem: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 15: Line 15:


= Filesystem Tools=  
= 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.
In ROS, code is spread across many ROS packages and stacks, which in turn may be spread across different parts of your filesystem. 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 ==
== 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.
[http://wiki.ros.org/rospack rospack] and [http://wiki.ros.org/rosstack 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:
Usage:


$ rospack find [package_name]
<pre>
$ rosstack find [stack_name]
rospack find [package_name]
Example:
rosstack find [stack_name]
</pre>


$ rospack find roscpp
For example, if you type the following in a terminal:
Would return:


YOUR_INSTALL_PATH/share/roscpp
<pre>rospack find roscpp</pre>
If, for example, you have used the binary install of ROS Fuerte on Ubuntu linux, you would see exactly:
 
It returns:
 
:<pre>/opt/ros/groovy/share/roscpp</pre>


/opt/ros/fuerte/share/roscpp
== Using roscd ==
== Using roscd ==


roscd is part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.
roscd is part of the [http://wiki.ros.org/rosbash rosbash] suite. It allows you to change directory (cd) directly to a package or a stack.


Usage:
Usage:


$ roscd [locationname[/subdir]]
<pre>roscd [locationname[/subdir]]</pre>
 
Run this example:
Run this example:


$ roscd roscpp
<pre>roscd roscpp</pre>
 
To verify that we have changed to the roscpp package directory. Now let's print the working directory using the Unix command pwd:
To verify that we have changed to the roscpp package directory. Now let's print the working directory using the Unix command pwd:


$ pwd
<pre>pwd</pre>
 
You should see:
You should see:


YOUR_INSTALL_PATH/share/roscpp
:<pre>/opt/ros/groovy/share/roscpp</pre>
You can see that YOUR_INSTALL_PATH/share/roscpp is the same path that rospack find gave in the previous example.
 
You can see that this 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:
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
<pre>echo $ROS_PACKAGE_PATH</pre>
If you have not modified your $ROS_PACKAGE_PATH, you should see:


YOUR_INSTALL_PATH/share:YOUR_INSTALL_PATH/stacks
This should return
Similarly to other environment paths, you can add additional directories to your $ROS_PACKAGE_PATH, with each path separated by a colon ':'


Subdirectories
:<pre>/home/YOUR_NAME/ros/emc:/opt/ros/groovy/share:/opt/ros/groovy/stacks</pre>


roscd can also move to a subdirectory of a package or stack.
This means that ROS will look for packages and stacks within all these colon-seperated directories. So, we should be able to navigate to any ROS package or stack that is located in ''ros/emc'' in your home folder. To check this, type:


Try:
<pre>roscd pico_gazebo</pre>


$ roscd roscpp/cmake
If everything is set up correctly, you will have navigated to ''~/ros/emc/general/pico_gazebo''.
$ pwd
You should see:


YOUR_INSTALL_PATH/share/roscpp/cmake
=== Subdirectories ===
Special cases for roscd


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


roscd with no arguments
Try:


roscd without an argument will take you to $ROS_WORKSPACE. Try:
<pre>
roscd pico_example/src
pwd
</pre>


$ roscd
$ pwd
You should see:
You should see:


/home/user/fuerte_workspace
:<pre>/home/YOUR_NAME/ros/emc/general/pico_example/src</pre>
Note: Prior to Fuerte, roscd would take you to $ROS_ROOT.


roscd log
which means you directly navigated to the ''src'' directory in the ''pico_example'' package.


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 =
= 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.
It can get tedious to type out an entire package name. For example, it may become annoying to type pico_example over and over again. Luckily, many ROS tools support TAB completion.


Start by typing:
Start by typing:


$ roscd roscpp_tut<<< now push the TAB key >>>
<pre>roscd pico_e<<< now push the TAB key >>></pre>
After pushing the TAB key, the command line should fill out the rest.
After pushing the TAB key, the command line should fill out the rest.


$ roscd roscpp_tutorials/
:<pre>roscd pico_example</pre>
This works because roscpp_tutorials is currently the only ROS package that starts with roscpp_tut.
 
This works because ''pico_example'' is currently the only ROS package that starts with ''pico_e''.


Now try typing:
Now try typing:


$ roscd tur<<< now push the TAB key >>>
<pre>roscd pico<<< now push the TAB key >>></pre>
After pushing the TAB key, the command line should fill out as much as possible:
After pushing the TAB key, the command line should fill out as much as possible:


$ roscd turtle
:<pre>roscd pico_</pre>
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
 
However, in this case there are multiple packages that begin with ''pico''. Try typing TAB another time. This should display all the ROS packages that begin with ''pico''
 
:<pre>  pico_description  pico_example  pico_gazebo  pico_visualization</pre>


  turtle_actionlib/  turtlesim/        turtle_tf/
On the command line you should still have
On the command line you should still have


$ roscd turtle
:<pre>roscd pico_</pre>
Now type a s after turtle and then push TAB
Now type an ''e'' after ''pico_'' and then push TAB
 
<pre>roscd pico_e<<< now push the TAB key >>></pre>


$ roscd turtles<<< now push the TAB key >>>
Since there is only one package that start with ''pico_e'', you should see:
Since there is only one package that start with turtles, you should see:


$ roscd turtlesim/
:<pre>roscd pico_example</pre>


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


Line 143: Line 131:
* rosstack = ros + stack
* rosstack = ros + stack
* roscd = ros + cd
* roscd = ros + cd
* rosls = ros + ls


This naming pattern holds for many of the ROS tools.
This naming pattern holds for many of the ROS tools.


 
Now that you can get around in ROS, [[Embedded Motion Control/Tutorials/Creating a ROS package | let's create a package]].
Now that you can get around in ROS, let's create a package.

Latest revision as of 22:19, 23 April 2014

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

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 Tools

In ROS, code is spread across many ROS packages and stacks, which in turn may be spread across different parts of your filesystem. 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]

For example, if you type the following in a terminal:

rospack find roscpp

It returns:

/opt/ros/groovy/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:

/opt/ros/groovy/share/roscpp

You can see that this 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

This should return

/home/YOUR_NAME/ros/emc:/opt/ros/groovy/share:/opt/ros/groovy/stacks

This means that ROS will look for packages and stacks within all these colon-seperated directories. So, we should be able to navigate to any ROS package or stack that is located in ros/emc in your home folder. To check this, type:

roscd pico_gazebo

If everything is set up correctly, you will have navigated to ~/ros/emc/general/pico_gazebo.

Subdirectories

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

Try:

roscd pico_example/src
pwd

You should see:

/home/YOUR_NAME/ros/emc/general/pico_example/src

which means you directly navigated to the src directory in the pico_example package.

Tab Completion

It can get tedious to type out an entire package name. For example, it may become annoying to type pico_example over and over again. Luckily, many ROS tools support TAB completion.

Start by typing:

roscd pico_e<<< now push the TAB key >>>

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

roscd pico_example

This works because pico_example is currently the only ROS package that starts with pico_e.

Now try typing:

roscd pico<<< now push the TAB key >>>

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

roscd pico_

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

  pico_description  pico_example  pico_gazebo  pico_visualization

On the command line you should still have

roscd pico_

Now type an e after pico_ and then push TAB

roscd pico_e<<< now push the TAB key >>>

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

roscd pico_example

Review

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

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

This naming pattern holds for many of the ROS tools.

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