1.2.6 Define and build custom message types
In this video tutorial, we will show you how to define your own message type in a message file, and add the file to your CMakeLists.txt to create a new ROS message type.
Don’t forget to source your workspace! If you’ve followed the procedure under the Course Setup section correctly, you only need to execute the following in the Course Command Shell (CCS):
$ source $HOME/hrwros_ws/devel/setup.bash
First, navigate to the folder where ROS message types are defined:
$ roscd hrwros_msgs
$ cd msg
Then, create the messagefile:
$ touch SensorInformation.msg
You can see all created message types by typing
$ rosmsg show sensor_msgs/
and hitting the Tab key.
Since we will need the Range type, enter
$ rosmsg show sensor_msgs/Range
and you will see what the Range message type consists of.
In the following example, we will create our own message type.
- Create the file and contents as shown below:
- Detail the data types the message type will contain
- And then some comments detailing the data entries
- Make sure to add the name to the add_message_files section in the CMakeLists.txt file
- Finally, run the catkin build command
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//.