[Documentation] [TitleIndex] [WordIndex

Creating a package

To easily create the package, you can use the excellent roscreate-pkg. To be able to interact with our robots, you need to make your new package depends on sr_robot_msgs, sensor_msgs and std_msgs. Depending on what you are planning to use, you probably also need to depend from roscpp or rospy (and probably other packages).

In this tutorial we'll guide you through the creation of an existing package: sr_example.

Once you've determined on which packages yours is depending, just run the following command (where sr_example is the name of your package)

$ roscreate-pkg sr_example roscpp rospy sr_robot_msgs sensor_msgs std_msgs

Using the created package

This will create the whole architecture for your package. Traditionally, your sources can be added to the src and the headers to the include/sr_example directories.

If you're writing in python, you have the choice to put your sources in the src directory, or to create a nodes directory (recommended if you plan on writing both python and c++ code, to keep things tidy). In our case, we'll write two examples, one in python, one in c++, so we create the nodes directory:

$ mkdir nodes

Writing the examples

We won't cover how to write the code in this tutorial, it's already been detailed in the previous tutorials. You can browse the code which should be heavily commented. The main thing to remember is that you just need to have access to the messages and the services definition in your package.

Adding new dependencies

If you forgot to add a dependency at the creation of the package, you can add them later by editing the manifest.xml. Just add a line with the dependency you want (before the </package>):

   1   <depend package="geometry_msgs"/>

2024-12-07 18:21