Note: This tutorial assumes that you have completed the previous tutorials: criando um pacote 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.

Gerando um pacote no ROS

Description: Este tutorial cobre as ferramentas e métodos para a geração de um pacote no ROS.

Tutorial Level: BEGINNER

Next Tutorial: Um pouco mais sobre ROS Nodes

Montar Pacotes

Uma vez que toda as dependências de sistema em relação ao seu pacote foram instaladas, podemos gerar um novo pacote.

Note: Se você instalou o ROS usando apt ou outro gerenciador de pacote, você já deve ter todas as dependências necessárias.

Antes de continuarmos, lembre-se de inicializar seu arquivo de setup de ambiente, caso já não tenha feito. No Ubuntu o comando é o seguinte:

# source /opt/ros/%YOUR_ROS_DISTRO%/setup.bash
$ source /opt/ros/kinetic/setup.bash             # Para Kinetic por exemplo

Usando catkin_make

catkin_make é uma ferramenta de linha de comando que adciona utilidades ao fluxo de trabalho padrão do catkin. Pode-se imaginar que o catkin_make combina chamadas do cmake e make em um fluxo de trabalho CMake padrão.

Como usar:

# Em um catkin workspace
$ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

Para pessoas que não são familiar com o fluxo de trabalho padrão do CMake, ele é dividido da seguinte maneira:

Note: Se você executar os comandos abaixo, ele não funcionará, pois este é apenas um exemplo de como o CMake geralmente funciona.

# Em um projeto CMake
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install  # (opcionalmente)

Esse processo é executado para cada projeto CMake. Por outro lado, os projetos catkin podem ser montados juntos em um workspace. Montar (build) zero ou vários pacotes catkin em um workspace segue o fluxo de trabalho abaixo:

# Em um catkin workspace
$ catkin_make
$ catkin_make install  # (opcionalmente)

Os comandos acima irão montar qualquer projeto catkin encontrado na pasta src. Isto segue a recomendação definida pelo REP128. Se o seu código fonte está em um local diferente, por exemplo minha_src, então você chamaria catkin_make desta forma:

Note: Se você rodar os comandos abaixo, eles não irão funcionar, já que a pasta minha_src não existe.

# Em um catkin workspace
$ catkin_make --source minha_src
$ catkin_make install --source minha_src  # (opcionalmente)

Para usos mais avançados do catkin_make veja a seguinte documentação: catkin/commands/catkin_make

Montando seu pacote

Para os leitores desta página que estão prestes a criar seus próprios códigos, consulte também os próximos tutoriais (C++)/(Python) pois você pode precisar modificar o CMakeLists.txt.

Nesse momento você já deve ter um catkin workspace e um pacote catkin chamado beginner_tutorials criado no tutorial anterior Criando um pacote ROS. Entre no seu catkin workspace (se você ainda não estiver lá) e olhe a pasta src:

$ cd ~/catkin_ws/
$ ls src
  • beginner_tutorials/  CMakeLists.txt@  

Você deve notar que existe uma pasta chamada beginner_tutorials que você criou com o comando catkin_create_pkg no tutorial anterior. Agora, nós podemos montar (build) este pacote usando catkin_make:

$ catkin_make

Você deve ver um monte de saída do cmake e `make, que deve ser algo similar a isto:

  • Base path: /home/user/catkin_ws
    Source space: /home/user/catkin_ws/src
    Build space: /home/user/catkin_ws/build
    Devel space: /home/user/catkin_ws/devel
    Install space: /home/user/catkin_ws/install
    ####
    #### Running command: "cmake /home/user/catkin_ws/src
    -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel
    -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build"
    ####
    -- The C compiler identification is GNU 4.2.1
    -- The CXX compiler identification is Clang 4.0.0
    -- Checking whether C compiler has -isysroot
    -- Checking whether C compiler has -isysroot - yes
    -- Checking whether C compiler supports OSX deployment target flag
    -- Checking whether C compiler supports OSX deployment target flag - yes
    -- Check for working C compiler: /usr/bin/gcc
    -- Check for working C compiler: /usr/bin/gcc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
    -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
    -- This workspace overlays: /opt/ros/groovy
    -- Found PythonInterp: /usr/bin/python (found version "2.7.1") 
    -- Found PY_em: /usr/lib/python2.7/dist-packages/em.pyc
    -- Found gtest: gtests will be built
    -- catkin 0.5.51
    -- BUILD_SHARED_LIBS is on
    -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -- ~~  traversing packages in topological order:
    -- ~~  - beginner_tutorials
    -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -- +++ add_subdirectory(beginner_tutorials)
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/user/catkin_ws/build
    ####
    #### Running command: "make -j4" in "/home/user/catkin_ws/build"
    ####

Observe que catkin_make primeito mosta quais caminhos ele está usando para cada um dos espaços. Os espaços são descritos no REP128 e na documentação dobre catkin workspaces na wiki: catkin/workspaces. Uma coisa importante para observar é que por causa destes valores padrão, várias pastam foram criadas no seu catkin workspace. Dê uma olhada usando o comando ls:

$ ls
  • build
    devel
    src

A pasta build é o local padrão do build space e é onde cmake e make são chamados para configurar e montar (buid) seus pacotes. A pasta devel é o local padrão do devel space, que é onde seus executáveis e bibliotecas vão antes da instalação dos seus pacotes.

Building Packages

Once all the system dependencies are installed, we can build our package that we just created.

Using rosmake

rosmake is just like the make command, but it does some special ROS magic. When you type rosmake beginner_tutorials, it builds the beginner_tutorials package, plus every package that it depends on, in the correct order. Since we listed rospy, roscpp, and std_msgs as dependencies when creating our ROS package, these packages (and their dependiencies, and so on) will be built by rosmake as well.

Usage:

rosmake [package]

Try:

$ rosmake beginner_tutorials

This previous command may take a while to finish. As it is running you should see some output like:

  • [ rosmake ] No package specified.  Building ['beginner_tutorials']
    [ rosmake ] Logging to directory
    [ rosmake ] /home/dbking/.ros/rosmake_output-2009-09-22-03-17-14
    [ rosmake ] [ 0 of 18  Completed ]
    [rosmake-0] >>> genmsg_cpp >>> [ make ]
    [rosmake-0] <<< genmsg_cpp <<< [PASS] [ 0.39 seconds ]
    [ rosmake ] [ 1 of 18  Completed ]
    ...
    ...
    ...
    [ rosmake ] [ 17 of 18  Completed ]
    [rosmake-0] >>> beginner_tutorials >>> [ make ]
    [rosmake-0] <<< beginner_tutorials <<< [PASS] [ 0.79 seconds ]

On Fuerte, since dependencies are greatly reduced, this takes almost no time and produces:

  • [ rosmake ] rosmake starting...                                                                     
    [ rosmake ] Packages requested are: ['beginner_tutorials']                                          
    [ rosmake ] Logging to directory /home/alex/.ros/rosmake/rosmake_output-20120603-082414             
    [ rosmake ] Expanded args ['beginner_tutorials'] to:
    ['beginner_tutorials']                         
    [rosmake-0] Starting >>> std_msgs [ make ]                                                          
    [rosmake-1] Starting >>> roslang [ make ]                                                           
    [rosmake-0] Finished <<< std_msgs ROS_NOBUILD in package std_msgs
     No Makefile in package std_msgs  
    [rosmake-1] Finished <<< roslang ROS_NOBUILD in package roslang
     No Makefile in package roslang     
    [rosmake-1] Starting >>> rospy [ make ]                                                             
    [rosmake-2] Starting >>> roscpp [ make ]                                                            
    [rosmake-1] Finished <<< rospy ROS_NOBUILD in package rospy
     No Makefile in package rospy           
    [rosmake-2] Finished <<< roscpp ROS_NOBUILD in package roscpp
     No Makefile in package roscpp        
    [rosmake-2] Starting >>> beginner_tutorials [ make ]                                                
    [rosmake-2] Finished <<< beginner_tutorials [PASS] [ 1.14 seconds ]                                 
    [ rosmake ] Results:                                                                                
    [ rosmake ] Built 5 packages with 0 failures.                                                       
    [ rosmake ] Summary output to directory                                                             
    [ rosmake ] /home/alex/.ros/rosmake/rosmake_output-20120603-082414  

rosmake multiple packages

We can also use rosmake to build multiple packages at once.

Usage:

rosmake [package1] [package2] [package3]

Review

Lets just list some of the commands we've used so far:

  • rosdep = ros+dep(endencies) : a tool to install package dependencies
  • rosmake = ros+make : makes (compiles) a ROS package

Agora que você construiu seu pacote ROS, vamos falar mais sobre Nós ROS.

Wiki: pt_BR/ROS/Tutorials/BuildingPackages (last edited 2020-04-18 23:05:41 by MateusMenezes)