1.2.5 Custom message types

Course subject(s) Module 1. ROS Essentials

In previous lectures, we spoke of ROS topics having a topic type. In this lecture, ROS message and topic types will be further explained.

Summary

Nodes can process and share information through topics. The information they pass through these topics needs to be structured in some way, to make it actually usable. Such a structure is known as a data structure. In ROS, we can abstract these data structures as ROS message types. Common data structures in ROS are for example floats, integers, and strings.

In ROS, we can easily combine multiple data structures using derived message types. For example, to represent a position in 3D space we will need 3 floating point values: X, Y and Z. The derived message type will then be a struct of three floating point numbers: {float x, float y, float z}.

These (derived) message types are defined in message files. These message files are typically located in <ros_package_name>/msg, with the filename <NewMessageType>.msg. For example, look in the $HOME/hrwros_ws/src/hrwros_msgs/msg folder for some examples.

Example: Ultrasound distance sensor.

We want to construct a new message type called SensorInformation. It should contain:

  • A ROS message type for interfacing with distance sensors
  • A string containing the manufacturer name
  • An unsigned integer containing the sensor part number

We would create the following file: $HOME/hrwros_ws/src/hrwros_msgs/msg/SensorInformation.msg.

It will contain the following:
sensor_msgs/Range sensor_data
string maker_name
uint32 part_number

We can see something really interesting here: We use an already derived message, sensor_msgs/Range, and simply add a string and an integer to it. So we can create new message types using already existing derived message types! This idea of stacking is really useful in ROS, since you can easily re-use what already exists. So in the above example, the sensor_msgs/Range already contains everything we need from the range sensor itself, and we only add the maker name and the part number.

Creative Commons License
Hello (Real) World with ROS - Robot Operating System by TU Delft OpenCourseWare is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at https://online-learning.tudelft.nl/courses/hello-real-world-with-ros-robot-operating-systems//.
Back to top