Understanding the ROS file system level
Similar to an operating system, ROS files are also organized on the hard disk in a particular fashion. In this level, we can see how these files are organized on the disk. The following graph shows how ROS files and folder are organized on the disk:
Here are the explanations of each block in the file system
- Packages: The ROS packages are the most basic unit of the ROS software. It contains the ROS runtime process (nodes), libraries, configuration files, and so on, which are organized together as a single unit. Packages are the atomic build item and release item in the ROS software.
- Package manifest: The package manifest file is inside a package that contains information about the package, author, license, dependencies, compilation flags, and so on. The
package.xml
file inside the ROS package is the manifest file of that package. - Meta packages: The term meta package is used for a group of packages for a special purpose. In an older version of ROS such as Electric and Fuerte, it was called stacks, but later it was removed, as simplicity and meta packages came to existence. One of the examples of a meta package is the ROS navigation stack.
- Meta packages manifest: The meta package manifest is similar to the package manifest; differences are that it might include packages inside it as runtime dependencies and declare an export tag.
- Messages (
.msg
): The ROS messages are a type of information that is sent from one ROS process to the other. We can define a custom message inside themsg
folder inside a package (my_package/msg/ MyMessageType.msg
). The extension of the message file is.msg
. - Services (
.srv
): The ROS service is a kind of request/reply interaction between processes. The reply and request data types can be defined inside thesrv
folder inside the package (my_package/srv/MyServiceType.srv
). - Repositories: Most of the ROS packages are maintained using a Version Control System (VCS) such as Git, subversion (svn), mercurial (hg), and so on. The collection of packages that share a common VCS can be called repositories. The package in the repositories can be released using a catkin release automation tool called
bloom
.
The following screenshot gives you an idea of files and folders of a package that we are going to make in the upcoming sections:
ROS packages
A typical structure of a ROS package is shown here:
We can discuss the use of each folder as follows:
config
: All configuration files that are used in this ROS package are kept in this folder. This folder is created by the user and is a common practice to name the folderconfig
to keep the configuration files in it.include/package_name
: This folder consists of headers and libraries that we need to use inside the package.scripts
: This folder keeps executable Python scripts. In the block diagram, we can see two example scripts.src
: This folder stores the C++ source codes. We can see two examples of the source code in the block diagram.launch
: This folder keeps the launch files that are used to launch one or more ROS nodes.msg
: This folder contains custom message definitions.srv
: This folder contains the service definitions.action
: This folder contains the action definition. We will see more about actionlib in the upcoming sections.package.xml
: This is the package manifest file of this package.CMakeLists.txt
: This is the CMake build file of this package.
We need to know some commands to create, modify, and work with the ROS packages. Here are some of the commands used to work with ROS packages:
catkin_create_pkg
: This command is used to create a new packagerospack
: This command is used to get information about the package in the file systemcatkin_make
: This command is used to build the packages in the workspacerosdep
: This command will install the system dependencies required for this package
To work with packages, ROS provides a bash-like command called rosbash
(http://wiki.ros.org/rosbash), which can be used to navigate and manipulate the ROS package. Here are some of the rosbash
commands:
roscd
: This command is used to change thepackage
folder. If we give the argument a package name, it will switch to that package folder.roscp
: This command is used to copy a file from a package.rosed
: This command is used to edit a file.rosrun
: This command is used to run an executable inside a package.
The definition of package.xml
of a typical package is shown as follows:
The package.xml
file consists of the package name, version of the package, the package description, author details, package build dependencies, and runtime dependencies. The <build_depend></build_depend>
tag includes the packages that are necessary to build the source code of the package. The packages inside the <run_depend></run_depend>
tag are necessary during runtime of the package node.
ROS meta packages
Meta packages are specialized packages in ROS that only contain one file, that is, a package.xml
file. It doesn't contain folders and files similar to a normal package.
Meta packages simply group a set of multiple packages as a single logical package. In the package.xml
file, the meta package contains an export tag, as shown here:
<export> <metapackage/> </export>
Also, in meta packages, there are no <buildtool_depend>
dependencies for catkin
, there are only <run_depend>
dependencies, which are the packages grouped in the meta package.
The ROS navigation stack is a good example of meta packages. If ROS is installed, we can try the following command, by switching to the navigation meta package folder:
$ roscd navigation
Open package.xml
using gedit
text editor
$ gedit package.xml
This is a lengthy file; here is a stripped down version of it:
ROS messages
The ROS nodes can publish data having a particular type. The types of data are described using a simplified message description language, also called ROS messages. These datatype descriptions can be used to generate source code for the appropriate message type in different target languages.
The data type description of ROS messages are stored in .msg
files in the msg
subdirectory of a ROS package.
The message definition can consist of two types: fields
and constants
. The field is split into field types and field name. Field types is the data type of the transmitting message and field name is the name of it. The constants define a constant value in the message
file.
Here is an example of message definitions:
int32 number string name float32 speed
Here, the first part is the field type and second is the field name. The field type is the data type and the field name can be used to access the value from the message. For example, we can use msg.number
for accessing the value of the number from the message.
Here is a table to show some of the built-in field types that we can use in our message:
Primitive type |
Serialization |
C++ |
Python |
---|---|---|---|
bool(1) |
unsigned 8-bit int |
uint8_t(2) |
bool |
int8 |
signed 8-bit int |
int8_t |
int |
uint8 |
unsigned 8-bit int |
uint8_t |
int (3) |
int16 |
signed 16-bit int |
int16_t |
int |
uint16 |
unsigned 16-bit int |
uint16_t |
int |
int32 |
signed 32-bit int |
int32_t |
int |
uint32 |
unsigned 32-bit int |
uint32_t |
int |
int64 |
signed 64-bit int |
int64_t |
long |
uint64 |
unsigned 64-bit int |
uint64_t |
long |
float32 |
32-bit IEEE float |
float |
float |
float64 |
64-bit IEEE float |
double |
float |
string |
ascii string(4) |
std::string |
string |
time |
secs/nsecs unsigned 32-bit ints |
ros::Time |
rospy.Time |
duration |
secs/nsecs signed 32-bit ints |
ros::Duration |
rospy.Duration |
A special type of ROS message is called message headers. Headers can carry information such as time, frame of reference or frame_id
, and sequence number. Using headers, we will get numbered messages and more clarity in who is sending the current message. The header information is mainly used to send data such as robot joint transforms (TF). Here is an example of the message header:
uint32 seq time stamp string frame_id
The rosmsg
command tool can be used to inspect the message header and the field types. The following command helps to view the message header of a particular message:
$ rosmsg show std_msgs/Header
This will give you an output like the preceding example message header. We can see more about the rosmsg
command and how to work with custom message definitions in the upcoming sections.
The ROS services
The ROS services are a type request/response communication between ROS nodes. One node will send a request and wait until it gets a response from the other. The request/response communication is also using the ROS message description.
Similar to the message definitions using the .msg
file, we have to define the service definition in another file called .srv
, which has to be kept inside the srv
sub directory of the package. Similar to the message definition, a service description language is used to define the ROS service types.
An example service description format is as follows:
#Request message type string str --- #Response message type string str
The first section is the message type of request that is separated by ---
and in the next section is the message type of response. In these examples, both Request
and Response
are strings.
In the upcoming sections, we can see how to work with ROS services.