Size: 6476
Comment:
|
Size: 6615
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 72: | Line 72: |
Now lets make sure that ROS can find your new package: | Now lets make sure that ROS can find your new package. It is often useful to call ''rospack profile'' after making changes to your path so that new directories will be found: |
Line 75: | Line 75: |
$ rospack profile |
Note: This tutorial assumes that you have completed the previous tutorials: Navegando pelo sistema de arquivos do ROS. |
![]() |
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
Contents
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 your home or project directory and create our beginner_tutorials package. We are going to make it depend on std_msgs, roscpp, and rospy, which are common ROS packages.
Note that your installation of ROS is likely write-protected; in any case, it is unwise to modify the base installation without specific reasons. Instead you should create a new path in your home directory and prepend it to your ROS_PACKAGE_PATH as outlined below, and create additional packages in there. Prepending a path to ROS_PACKAGE_PATH causes all rosbash functions, such as roscd, to search through that path before moving on to the later paths, searching the default installation last.
$ cd ~/ $ mkdir ros_tutorials $ export ROS_PACKAGE_PATH=~/ros_tutorials:$ROS_PACKAGE_PATH
Note that the export line above must be run each time you open a new terminal ( unless you edit your .bashrc file to do so automatically).
Now in the ~/ros_tutorials directory please run the following commands:
$ roscreate-pkg beginner_tutorials std_msgs rospy roscpp
You will see something similar to:
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. It is often useful to call rospack profile after making changes to your path so that new directories will be found:
$ rospack profile $ rospack find beginner_tutorials
YOUR_PACKAGE_PATH/beginner_tutorials
If this fails, it means ROS can't find your new package, which may be an issue with your ROS_PACKAGE_PATH. Please consult the installation instructions for setup from SVN or from binaries, depending how you installed ROS. If you've created or added a package that's outside of the existing package paths, you will need to amend your ROS_PACKAGE_PATH environment variable to include that new location.
Try moving to the directory for the package.
$ roscd beginner_tutorials $ pwd
YOUR_PACKAGE_PATH/beginner_tutorials
First-order package dependencies
When using roscreate-pkg earlier, a few package dependencies were provided. These first-order dependencies can now be reviewed 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 for C++.
Review
Lets just list some of the commands we've used so far:
- roscreate-pkg = ros+create-pkg : generates all the files needed to create a ROS package
- rospack = ros+pack(age) : provides information related to ROS packages
- rosstack = ros+stack : provides information related to ROS stacks
Now that you've made a new ROS package, let's build our ROS package.