Mastering ROS for Robotics Programming(Second Edition)
上QQ阅读APP看书,第一时间看更新

ROS packages

A typical structure of an ROS package is shown here:

Figure 3: Structure of a typical C++ ROS package

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 it is a common practice to name the folder config 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.
  • script: This folder keeps executable Python scripts. In the block diagram, we can see two example scripts.
  • src: This folder stores the C++ source codes.
  • 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 services definitions.
  • action: This folder contains the action files. We will see more about these kind of files in the next chapter.
  • package.xml: This is the package manifest file of this package.
  • CMakeLists.txt: This files contains the directives to compile the 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 package
  • rospack: This command is used to get information about the package in the filesystem
  • catkin_make: This command is used to build the packages in the workspace
  • rosdep: 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 the current directory using a package name, stack name, or a special location. 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 using the vim editor.
  • rosrun: This command is used to run an executable inside a package.

The definition of package.xml of a typical package is shown in the following screenshot:

Figure 4: Structure of package.xml

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> tags are necessary during runtime of the package node.