Revision 59 as of 2009-09-17 19:01:12

Clear message

Note: This tutorial assumes that you have completed the previous tutorials: Navegando pelo sistema de arquivos do 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.

Criando um Pacote ROS

Description: Este tutorial cobre a utilização de roscreate-pkg ou catkin para criar um novo pacote, e rospack para listar dependências de pacotes.

Tutorial Level: BEGINNER

Next Tutorial: Gerando um pacote ROS

Quick Environment Variable Setup

For this tutorial, you will need to know two key environment variables:

  • ROS_ROOT: this is the directory where ROS is installed and contains many ROS-related packages

  • ROS_PACKAGE_PATH: this is a of directories that ROS looks to find more ROS packages.

Using roscreate

Before we create a package, let's see how the roscreate-pkg command-line tool works. This creates a new ROS package: manifest, CMakeLists.txt, mainpage.dox, and Makefile. It addresses the common problem of packages being created by hand using pre-existing packages, which leads to errors in build files and manifests.

To create a new package in the current directory:

$ roscreate-pkg [pkgname]

You can also specify dependencies of that package:

$ roscreate-pkg [pkgname] [depend1] [depend2] [depend3]

Creating a New ROS Package

Now we're going to go into the ros_tutorials directory and create our beginner_tutorials package. We going to make it depend on roscpp and rospy, which are common ROS packages, as well as rospy_tutorials, which has some programs we're going to use later.

$ roscd ros_tutorials
$ roscreate-pkg beginner_tutorials std_msgs rospy roscpp rospy_tutorials roscpp_tutorials turtlesim

You will see:

  • Creating package directory ~/ros/ros_tutorials/beginner_tutorials
    Creating include directory ~/ros/ros_tutorials/beginner_tutorials/include/beginner_tutorials
    Creating cpp source directory ~/ros/ros_tutorials/beginner_tutorials/src
    Creating python source directory ~/ros/ros_tutorials/beginner_tutorials/src/beginner_tutorials
    Creating package file ~/ros/ros_tutorials/beginner_tutorials/Makefile
    Creating package file ~/ros/ros_tutorials/beginner_tutorials/manifest.xml
    Creating package file ~/ros/ros_tutorials/beginner_tutorials/CMakeLists.txt
    Creating package file ~/ros/ros_tutorials/beginner_tutorials/mainpage.dox
    
    Please edit beginner_tutorials/manifest.xml and mainpage.dox to finish creating your package

You're going to want to spend some time looking at beginner_tutorials/manifest.xml. manifests play an important role in ROS as they define how Packages are built, run, and documented.

Now lets make sure that ROS can find your new package:

$ rospack find beginner_tutorials 
  • ~/ros/ros_tutorials/beginner_tutorials

Try moving to the directory for the package.

$ roscd beginner_tutorials 
$ pwd
  • ~/ros/ros_tutorials/beginner_tutorials

First-order package dependencies

When using roscreate-pkg earlier, a few package dependencies were provided. These first-order dependencies can now reviewed by with the rospack tool.

$ rospack depends1 beginner_tutorials 
  • std_msgs
    rospy
    roscpp
    rospy_tutorials
    roscpp_tutorials
    turtlesim

As you can see, rospack lists the same dependencies that were used as arguments when running roscreate-pkg. These dependencies for a package are stored in the manifest file. Take a look at the manifest file.

$ roscd beginner_tutorials
$ cat manifest.xml
  • <package>
    
    ...
    
      <depend package="std_msgs"/>
      <depend package="rospy"/>
      <depend package="roscpp"/>
      <depend package="rospy_tutorials"/>
      <depend package="roscpp_tutorials"/>
      <depend package="turtlesim"/>
    
    </package>

Indirect package dependencies

In many cases, a dependency will also have its own dependencies. For instance, rospy has other dependencies.

$ rospack depends1 rospy
  • roslib
    roslang

A package can have quite a few indirect dependencies. Luckily rospack can recursively determine all nested dependencies.

$ rospack depends beginner_tutorials
  • genmsg_cpp
    roslib
    std_msgs
    roslang
    rospy
    xmlrpc++
    rosconsole
    roscpp
    pycrypto
    paramiko
    rosout
    roslaunch
    rostest
    std_srvs
    roscpp_tutorials
    rospy_tutorials
    turtlesim

ROS Client Libraries

You may be wondering what rospy and rospp dependencies are from the previous examples. rospy and rospp are Client Libraries. The client libraries allow different programming languages to communicate through ROS. rospy is the client library for Python. roscpp is the client library from C++.

Now that you've made a new ROS package, let's create a ROS msg and srv.