Important announcement

Dear visitor,

Please note that this OpenCourseWare platform will be replaced at the end of 2026 by a new platform (under the same url ocw.tudelft.nl).

Courses and their contents that are currently available the platform will partly be migrated. URL’s for this content will change and content might be unavailable for some time. In addition, some courses will not be available anymore.

If you are linking to specific courses on this platform (for instance for your students), please take timely measures to avoid problems with access. Possible actions are:

  • Download the materials to your local platform (laptop, server)
  • For educators only (including TU Delft lecturers): Contact us at ocw@tudelft.nl and inform us what course you are using in what context (institute, program, period of use, number of students). We will research (in collaboration with the authors of the course) and decide if we will migrate the course, and if yes, can supply you with a new url.

Thank you.

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
[sg_popup id=6]