[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.
(!) 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.

Creating a package to interact with our robots.

Description: This tutorial will show you how to create a package to interact with our robots. This is the "clean" way of working with the robots.

Tutorial Level: BEGINNER

  Show EOL distros: 

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

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

Our stacks have not yet been released under Groovy, please use the Fuerte versions.

Our stacks have not yet been released under Hydro, please use the Fuerte versions.


2019-09-21 13:13