ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is not a feature in ROS1 but this is a feature in ROS2. Interface definition using .msg / .srv / .action files Scroll down to the "Default values" section

In this ROS2 tutorial Creating custom msg and srv files They have you put the following in a .msg file

int64 num

By default the default value of a numerical datatype is 0. If you want to change the default value then put the desired default value after the name separated by a space. For example if you want to make the default value 1 then put the following in the .msg file.

int64 num 1

Now when you publish your message without defining the value of num it will publish num with a value of 1 instead of 0.

ros2 topic pub /numtopic tutorial_interfaces/msg/Num '{}'

You can confirm this by using ros2 topic echo.

ros2 topic echo /numtopic

num: 1
---