ROS uses a simplified message description language to describe the data values that ROS nodes publish. With this description, ROS can generate the right source code for these types of messages in several programming languages.
ROS has a lot of messages predefined, but if you develop a new message, it will be in the msg/ folder of your package. Inside that folder, certain files with the .msg extension define the messages.
A message must have two main parts: fields and constants. Fields define the type of data to be transmitted in the message, for example, int32, float32, and string, or new types that you created earlier, such as type1 and type2. Constants define the name of the fields.
An example of an msg file is as follows:
int32 id float32 vel string name
In ROS, you can find a lot of standard types to use in messages, as shown in the following table list:
Primitive type |
Serialization |
C++ |
Python |
bool (1) |
unsigned 8-bit int |
uint8_t(2) |
bool |
int8 |
signed 8-bit int |
int8_t |
int |
uint8 |
unsigned 8-bit int |
uint8_t |
int(3) |
int16 |
signed 16-bit int |
int16_t |
int |
uint16 |
unsigned 16-bit int |
uint16_t |
int |
int32 |
signed 32-bit int |
int32_t |
int |
uint32 |
unsigned 32-bit int |
uint32_t |
int |
int64 |
signed 64-bit int |
int64_t |
long |
uint64 |
unsigned 64-bit int |
uint64_t |
long |
float32 |
32-bit IEEE float |
float |
float |
float64 |
64-bit IEEE float |
double |
float |
string |
ascii string (4) |
std::string |
string |
time |
secs/nsecs signed 32-bit ints |
ros::Time |
rospy.Time |
duration |
secs/nsecs signed 32-bit ints |
ros::Duration |
rospy.Duration |
A special type in ROS is the header type. This is used to add the time, frame, and sequence number. This permits you to have the messages numbered, to see who is sending the message, and to have more functions that are transparent for the user and that ROS is handling.
The header type contains the following fields:
uint32 seq time stamp string frame_id
You can see the structure using the following command:
$ rosmsg show std_msgs/Header
Thanks to the header type, it is possible to record the timestamp and frame of what is happening with the robot, as we will see in upcoming chapters.
ROS provides certain tools to work with messages. The rosmsg tool prints out the message definition information and can find the source files that use a message type.
In upcoming sections, we will see how to create messages with the right tools.