2021-04-21 01:46:37 +02:00
msg new package created and srv built 2021-04-20 18:27:13 +02:00
srv service call example created 2021-04-21 01:46:37 +02:00
CMakeLists.txt service call example created 2021-04-21 01:46:37 +02:00
package.xml new package created and srv built 2021-04-20 18:27:13 +02:00 Update 'src/custom_interfaces/' 2021-04-20 22:10:50 +02:00

Use this ROS2 package to create custom interfaces, eg. topic (.msg) and/or service (.srv) files.
This package must only be used for interface files and no Python scripts.

The following steps describe how to create a new custom topic or service.

1. Create new interface file

Topic *.msg files got into msg directory,
Service *.srv files got into srv directory.

Create these files according to the example on this instructions page.

2. CMakeLists.txt

Edit the CMakeLists.txt file by adding the newly created *.msg or *.srv files to this part:

  DEPENDENCIES builtin_interfaces

3. Build colcon workspace

Move back to the root of your colcon workspace and rebuild it: colcon build --symlink-install
It should build without any errors. If you encounter errors fix these before continuing.

After a successful build you must close and reopen all terminals in order to source the newly built workspace. For this to happen you must have edited .bashrc and added your current workspace (sudo nano ~/.bashrc and follow this example).

4. Import interfaces

Import the newly created interfaces into the Python scripts. These scripts must be located in Python packages inside the same workspace (or another sourced workspace):

  • Topics:
from custom_interfaces.msg import CustomMsg1
  • Services:
from custom_interfaces.srv import CustomSrv1

Now you can work with your custom interface in order to exchange custom information between nodes.