Revision 50 as of 2009-09-16 20:52:39

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

$ rospack depends1 beginner_tutorials 
  • std_msgs
    rospy
    roscpp
    rospy_tutorials
    roscpp_tutorials
    turtlesim

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

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