The last ROS 1 release Noetic will go end of life on May 31st with that the ROS Wiki (this website) will also be EOL and transition to being an archive.
Maintainers:Please migrate any wiki content into your package's README.md file.
If you need more help on migrating code please see this migration guide.
Or watch Shane's Lightning Talk from ROSCon 2024.
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 de ROS manualmente
Description: Como criar um pacote do ROS sem usar ferramentas.
There is a tool for creating ROS Packages (roscreate-pkg), but, as you will see, there is nothing actually difficult here. roscreate-pkg prevents mistakes and saves effort, but packages are just a directory and a simple XML file.
Now we'll create a new foobar package. This tutorial assumes that we're working in the directory pkgs on your ROS_PACKAGE_PATH.
pkgs$ mkdir foobar
pkgs$ cd foobar
The very first thing we'll do is add our manifest file. The manifest.xml file allows tools like rospack to determine information about what your package depends upon.
Now that your package has a manifest, ROS can find it. Try executing the command:
rospack find foobar
If ROS is set up correctly you should see something like: /home/user/ros/pkgs/foobar. This is how ROS finds packages behind the scenes.
Note that this package now also has dependencies on roscpp and std_msgs. To see one example of why specifying these dependencies is useful, try executing the following commands rospack commands:
When you run these, rospack looks up the dependencies of foobar and generates the necessary list of includes or linking statements to compile and link the executable. These commands are used by the ROS build system to correctly compile and link your packages despite the modular nature of ROS. You'll probably never have to use these directly since our build system takes care of it for you. However, as you can see, they are reasonably easy use if you want to use a different build system.
In order to take advantage of this, we need to make two build files: a Makefile and CMakeLists.txt file.
Inside of foobar/Makefile, put:
include $(shell rospack find mk)/cmake.mk
This tells make that we're going to use CMake instead of Make to build this package.
Now we need the CMakeLists.txt file so that we can use CMake instead. ROS uses CMake for its more powerful flexibility when building across multiple platforms.
That's all you need to start building a package in ROS. Of course, if you want it to actually start building something, you're going to need to learn a couple more CMake macros. See our CMakeLists guide for more information.
Existe uma ferramenta para criar pacotes (Packages) de ROS, o catkin_create_pkg, mas, como este tutorial demonstrará, também é possível criar pacotes sem usar nenhuma ferramenta. catkin_create_pkg evita erros e ganha tempo, mas um pacote nada mais é que um diretório com um arquivo XML específico.
Agora vamos criar um novo pacote chamado foobar. Este tutorial presume que estamos em um workspace catkin e que o arquivo setup já foi "sourced".
Começamos criando um diretório para o pacote e entrando nele:
catkin_ws_top $ mkdir -p src/foobar
catkin_ws_top $ cd src/foobar
A primeira coisa a se fazer é adicionar nosso arquivo package.xml. Este arquivo permite que ferramentas como rospack determinem informações sobre as dependências do seu pacote.
Agora que seu pacote tem um arquivo package, o ROS consegue encontrá-lo. Tente executar o comando:
rospack find foobar
Se ROS estáiver configurado corretamente, você verá algo como: /home/user/ros/catkin_ws_top/src/foobar. É por esse mecanismo que o ROS sempre encontra seus pacotes.
Note que nosso pacote também tem dependência em roscpp e std_msgs.
Tais dependências são usadas por catkin para configurar pacotes na ordem correta.
Agora nós precisamos do arquivo CMakeLists.txt para que catkin_make, que usa CMake para compilar em múltiplas plataformas, compile o pacote.
Isso é tudo que é necessário para começar a compilar um pacote em ROS usando catkin. Apesar disso ser o mínimo necessário, mais macros do CMake são necessárias para compilar algo. Veja nosso guia de CMakeLists.txt para mais informações. E sempre consulte os tutoriais iniciantes (Criando pacotes, etc) para customizar seu package.xml e CMakeLists.txt.
Wiki: pt_BR/ROS/Tutorials/Creating a Package by Hand (last edited 2020-04-18 22:18:51 by chapulina)