• Diff for "pt_BR/ROS/Tutorials/CreatingPackage"
Differences between revisions 73 and 74
Revision 73 as of 2009-09-29 19:03:44
Size: 4944
Editor: MeloneeWise
Comment:
Revision 74 as of 2009-12-07 00:49:22
Size: 6865
Comment:
Deletions are marked like this. Additions are marked like this.
Line 45: Line 45:
You will see: This may fail! If it does, see below for a workaround. If it succeeds, you will see:
Line 143: Line 143:

=== roscreate-pkg Workaround ===

If roscreate-pkg fails, the reason may be because it is attempting to create the same directory twice. To fix it you will need to edit "roscreatepkg.py" in the "roscreate" package:

{{{
$ rosed roscreate roscreatepkg.py
}}}

On line 75, we will add a check that the directory we are trying to create (for the second time) doesn't already exist:

{{{
<<<<<< Old:
  73 if uses_rospy:
  74 # create package/src/ for python files
  75 py_path = os.path.join(p, 'src')
  76 print "Creating python source directory", py_path
  77 os.makedirs(py_path)
>>>>>> New:
  73 if uses_rospy:
  74 # create package/src/ for python files
  75 py_path = os.path.join(p, 'src')
  76 if not os.path.exists(py_path):
  77 print "Creating python source directory", py_path
  78 os.makedirs(py_path)
}}}

Once you have saved this file, you should be able to see something like the following:

{{{
$ rm -rf beginner_tutorials/
$ roscreate-pkg beginner_tutorials std_msgs rospy roscpp
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.
}}}

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

Using roscreate

Before we create a package, let's see how the roscreate-pkg command-line tool works. This creates a new ROS package. All ROS packages consist of the many similar files : manifests, CMakeLists.txt, mainpage.dox, and Makefiles. roscreate-pkg eliminates many tedious task of creating a new package by hand, and eliminates common errors caused by hand-typing build files and manifests.

To create a new package in the current directory:

$ roscreate-pkg [package_name]

You can also specify dependencies of that package:

$ roscreate-pkg [package_name] [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 std_msgs, roscpp, and rospy, which are common ROS packages.

Please run the following commands:

$ roscd ros_tutorials
$ roscreate-pkg beginner_tutorials std_msgs rospy roscpp

This may fail! If it does, see below for a workaround. If it succeeds, 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/pkgs/ros_tutorials/beginner_tutorials

Try moving to the directory for the package.

$ roscd beginner_tutorials 
$ pwd
  • ~/ros/pkgs/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

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"/>
    
    </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

ROS Client Libraries

You may be wondering what rospy and roscpp dependencies are from the previous examples. rospy and roscpp 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 build our ROS package.

roscreate-pkg Workaround

If roscreate-pkg fails, the reason may be because it is attempting to create the same directory twice. To fix it you will need to edit "roscreatepkg.py" in the "roscreate" package:

$ rosed roscreate roscreatepkg.py

On line 75, we will add a check that the directory we are trying to create (for the second time) doesn't already exist:

<<<<<< Old: 
  73    if uses_rospy:
  74        # create package/src/ for python files
  75        py_path = os.path.join(p, 'src')
  76        print "Creating python source directory", py_path
  77        os.makedirs(py_path)
>>>>>> New: 
  73    if uses_rospy:
  74        # create package/src/ for python files
  75        py_path = os.path.join(p, 'src')
  76        if not os.path.exists(py_path):
  77            print "Creating python source directory", py_path
  78            os.makedirs(py_path)

Once you have saved this file, you should be able to see something like the following:

$ rm -rf beginner_tutorials/
$ roscreate-pkg beginner_tutorials std_msgs rospy roscpp
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.

Wiki: pt_BR/ROS/Tutorials/CreatingPackage (last edited 2020-04-18 23:08:59 by MateusMenezes)