Note: This tutorial assumes that you have completed the previous tutorials: What are Service Pairs?. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Create ServicePair Messages
Description: Create msgs from .pair definitions.Keywords: servicepairs, rocon
Tutorial Level: BEGINNER
Next Tutorial: Writing a ServicePair Server (Python)
Overview
This tutorial takes you through the process of creating a package with .pair definitions and inspecting the results of the build.
Define the Pair
> catkin_create_pkg chatter > cd chatter > mkdir pairs > echo "string babble" > pairs/Chatter.pair > echo "----" >> pairs/Chatter.pair > echo "string reply" >> pairs/Chatter.pair
In your CMakeLists.txt, you'll need a dependency on rocon_service_pair_msgs as well as the add_service_pair_files macro to trigger generation of the messages:
1 find_package(catkin REQUIRED COMPONENTS
2 message_generation
3 rocon_service_pair_msgs
4 )
5
6 add_service_pair_files(
7 DIRECTORY pairs
8 FILES
9 Chatter.pair
10 )
11 generate_messages(DEPENDENCIES rocon_service_pair_msgs)
12
13 catkin_package(CATKIN_DEPENDS
14 message_runtime
15 rocon_service_pair_msgs
16 )
Don't forget to add message_xxx and rocon_service_pair_msgs to your package.xml:
Build
You should be able to catkin_make this package now and detect the output in the cmake step:
-- +++ processing catkin package: 'chatter' -- ==> add_subdirectory(chatter) -- Using these message generators: gencpp;genlisp;genpy -- Generating .msg files for service pair chatter/Chatter -- ... this is hard work, toss me a beer! -- chatter: 5 messages, 0 services
The resulting pub/sub messages can be found in devel/share/chatter/msg.