Getting Started with ROS on Embedded Systems/User Guide/C++/Package set up

From RidgeRun Developer Connection
Jump to: navigation, search

Introduction

This serves an introduction on how to create and build simple packages using ROS with catkin build system.

A ROS package is simply one folder located under a workspace that can be constructed by using catkin. It's two basic compontens are the following:

A catkin compliant package.xml file: This file provides metadata about the package, like its name, maintainer, dependencies, etc. A CMakeLists.txt which will be invoced by the catkin build system : This just needs to be a boilerplate CMakeLists.txt file, it will be very similar to a normal CMakeLists.txt but with some custom flags used by catking.

These two files need to be contained inside the package folder, without nesting or sharing folders between packages. A normal structure can look like this:

ros_workspace
└── src
    └── rr_package1
        ├── CMakeLists.txt
        └── package.xml

The toplevel src folder needs to be created manually, and you should always have a layout like this, and one folder for each package inside the src folder.

Creating a new package

Creating a new package is simple[1], you can create one by using the command line tool:

catkin_create_pkg <package_name> <dependencies>
<syntaxhighlight>

For example:
<syntaxhighlight lang="bash">
catkin_create_pkg rr_package2 std_msgs roscpp

This will create a ROS package with std_msgs and roscpp packages as dependencies.

Configuring packge

The first step on configuring the package, is to modify the package.xml, you will have entries similar to the following:

<?xml version="1.0"?>
<package format="2">
  <name>Package name</name>
  <version>0.1.0</version>
  <description>Description of the package</description>
  <maintainer email="example@example.com">Maintainer name</maintainer>
  <license>GPL</license>
  <buildtool_depend>catkin</buildtool_depend>
  <depend>roscpp</depend>
  <depend>std_msgs</depend>
</package>

You can get more information on the ROS tutorials[2].

For now, all fields are self explanatory, besides the buildtool_depend or depend, these are just simplification of saying which package this package depends on at build time, or at both build and execution.

Building a package

To build a package, you will make usage of the catking_make command inside the workspace directory [3] (in the same directory as the src folder is located):

catkin_make [make_targets] [-DCMAKE_VARIABLES=...]

make_targets are the commands you would pass to make, and -DCMAKE_VARIABLES stand for any flag you want to pass to the cmake call, for example include directories flag:

catkin_make -DCMAKE_CXX_FLAGS="-I ..."

Running this command the first time will generate 2 more folders:

  1. build: Where cmake and make are called to configure and build your packages.
  2. devel: Where the executables and libraries go before you install your packages.

To make usage of anything inside the package, you can source the workspace:

source ./devel/setup.sh

References