Skip to content

Installing and Building Custom Message Files in ROS

Author

  • Harry Yu
  • Dec 10 2024

Overview

In ROS, custom message files allow you to define your own message types for communication between nodes. This guide will walk you through the process of creating, installing, and building custom message files in a ROS package.

Step 1: Define Your Custom Message Files

  1. Create a msg Directory:

Inside your package, create a directory named msg:

cd ~/catkin_ws/src/my_custom_msgs
mkdir msg
  1. Create Message Files:

Inside the msg directory, create your custom message files. For example, create a file named MyMessage.msg:

 int32 round_time_remaining
 string game_phase
 bool bomb_planted
 geometry_msgs/Point bomb_location
 string[] dead_players

Step 3: Modify CMakeLists.txt

Edit the CMakeLists.txt file in your package to include the message generation dependencies:

Find and uncomment/add the following lines:

find_package(catkin REQUIRED COMPONENTS
  std_msgs
  message_generation
)

Add your message files:

add_message_files(
  FILES
  GameStateMsg.msg
)

Generate messages:

generate_messages(
  DEPENDENCIES
  std_msgs
)

Include message_runtime in catkin_package:

catkin_package(
  CATKIN_DEPENDS message_runtime
)

Step 4: Modify package.xml

Edit the package.xml file to include the message generation dependencies:

  1. Add the following dependencies:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

Step 5: Build Your Package

```
ws
catkin_make
```

And you've successfully created your own message type!