Getting Started with ROS on Embedded Systems - User Guide - C++ - Messages

From RidgeRun Developer Connection
Jump to: navigation, search




Previous: User Guide/C++/Topics Index Next: User Guide/C++/Names




Introduction

This wiki is based on the following ROS page: http://wiki.ros.org/msg

Messages are the main form of communication in a topic, in which the publisher will push a message of some defined type and the subscriber will use that same kind of message in the reception.

These messages are normally described in a simplified file that is then used by ROS to generate C++ (and other languages) code with them (which ends up being a simple struct). Message descriptions are located inside the msg/ folder in the package and end with the .msg extension.

Message types are referred to using package resource names. For example, the file rr_msgs/msg/RRMessage.msg is commonly referred to as rr_msgs/RRMessage.

Message description

Messages have two parts in the .msg file: fields and constants

Message fields

Fields are the data sent inside the message, this is defined in the messages as pairs of key and value:

type1 name1
type2 name2
type3 name3

Types

The types can be primitive:

bool, int8, uint8, int16, uint16, int32, uint32, int64, uint64, float32, float64, string, time, duration

Or they can be arrays too:

Names

The names for the fields determine how to get the data on the target language, just as one would do using structs. Field names must be translated to multiple languages, so their names are restricted to the following pattern: [a-zA-Z][a-zA-Z1-9_]*.

Creating a message

To create a message package, you can create a package as in the setting up section.

Then you will need to add the message generation and message runtime in the package configuration:

<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

And you will also need to add to the message CMakeLists.txt:

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs genmsg message_generation)
add_message_files(FILES RRMessage.msg RRMessage2.msg)
generate_messages(DEPENDENCIES std_msgs)

###################################
## catkin specific configuration ##
###################################

include_directories(${catkin_INCLUDE_DIRS})
catkin_package(
  CATKIN_DEPENDS message_runtime roscpp std_msgs
)

This assumes that we have a RRMessage.msg and RRMessage2.msg on the package msg/ folder.

Using message from another nodes

See current topics:

rostopic list
Previous: User Guide/C++/Topics Index Next: User Guide/C++/Names