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

Generating Message Header File

Description: This tutorial shows how to generate message header files for using new message packages with rosserial.

Tutorial Level: INTERMEDIATE

Overview

Software running in embedded systems like rosserial_arduino or rosserial_embeddedlinux needs a definition of all messages passed between it and ROS nodes. It cannot directly use the C++ header files that are part of ROS because they depend on Boost libraries, which likely aren't available on the embedded system. The solution is to generate simplified C++ header files for the embedded environment from the same message definitions used by the rest of ROS.

These simplified message header files in C++ are generated for many important message types when you install rosserial. If you need to use other message types, or you have your own custom message types, you will need to generate the appropriate headers for both the embedded system and the ROS nodes that will use your message types.

Generating Message Header Files

The rosserial_client package includes a tool - make_library.py - for generating the required header files from message definition files. It regenerates all the standard messages (e.g. std_msgs, geometry_msgs, etc) as well as any messages you've defined in packages you specify on the command line, and places them in a directory you specify.

rosrun rosserial_client make_library.py path_to_libraries your_message_package

For instance, suppose you need to generate headers for message definitions contained in my crazy_msgs package, and ros_lib is located at '~/sketchbook/libraries/ros_lib':

rosrun rosserial_client make_library.py ~/sketchbook/libraries crazy_msgs

This command will create the headers, and locate them in ~/sketchbook/libraries/ros_lib/crazy_msgs/.

The make_library.py program generates the headers for all the standard messages, but you may only need to transfer your custom message headers to another environment (for example, a PC running the Arduino IDE).

If you use custom messages, generate ROS message headers for them, in addition to the simplified rosserial headers. Use the technique described in the DefiningCustomMessages tutorial to generate standard ROS headers.

Using Custom Messages

Your custom message definitions must be available to all software that uses them, including the rosserial_python proxy node and any ROS C++ or python nodes. All that's required to enable rosserial_python to find your custom message definition is to add the path to the package that defines it to your PYTHONPATH environment variable. When the rosserial_python proxy receives a subscriber or publisher or service registration from the embedded system, it searches $PYTHONPATH looking for packages with a msg directory that contains a matching message definition.

The ROSNodeTutorialPython tutorial shows how to include the ROS definition of your custom messages into a ROS C++ or python node.

Wiki: rosserial_client/Tutorials/Generating Message Header Files (last edited 2012-10-01 08:26:16 by PaulBouchier)