Ask Your Question

[ROS2] Service header files

asked 2020-02-13 10:53:32 -0600

jlepers gravatar image



In the example of the service Client they use following header file:

#include "example_interfaces/srv/add_two_ints.hpp"

I think it is necessary to make the server Client, to find the (example_interfaces::srv::AddTwoInts):

 rclcpp::Client<example_interfaces::srv::AddTwoInts::SharedPtr init = node->create_client<example_interfaces::srv::AddTwoInts>("init");

In my custom package I made some .srv files that I want to use, do I need a Header file as well ?

#include "my_package/srv/sum.hpp"

Obviously I don't have this .hpp file so it will throw an error. Do I need to make one myself or can I generate this file ?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-14 04:09:12 -0600

marguedas gravatar image

The headers are generated and not written by hand. You can generate them using the rosidl_generate_interfaces CMake macro (examnple here)

There doesn't seem to be an up-to-date tutorial explaining how to define and use custom interfaces at the moment.

I recommend you to create a package with only your custom messages / services files (you can look at for an example)

And use them in your package (using as an example)

edit flag offensive delete link more


Thank you, I was trying something similar. Is it possible that I need to install ROS2 by source to use rosidl_default_generators instead of ROS2 Debian packages?

jlepers gravatar imagejlepers ( 2020-02-14 04:13:05 -0600 )edit

Is it possible that I need to install ROS2 by source to use rosidl_default_generators instead of ROS2 Debian packages?

You should be able to use it from debian packages. You'll need to make sure that that package is installed (though I believe it is installed by default).

apt-get list --installed | grep rosidl-default-generators
marguedas gravatar imagemarguedas ( 2020-02-14 04:52:24 -0600 )edit


apt list --installed | grep rosidl-default-generators


ros-dashing-rosidl-default-generators/now 0.7.0-1bionic.20191016.185016 amd64 [installed,upgradable to: 0.7.0-1bionic.20191210.230356]

I guess this is fine, but I still have cmake troubles with the find_package(rosidl_default_generators REQUIRED) command.

jlepers gravatar imagejlepers ( 2020-02-14 04:58:36 -0600 )edit

Should I open a new question ?

jlepers gravatar imagejlepers ( 2020-02-14 04:59:07 -0600 )edit

Yes please. Can you make sure to add your full package.xml and CMakeLists (with the comment lines, starting with # removed for readability) ? This will help diagnose the issue

marguedas gravatar imagemarguedas ( 2020-02-14 05:10:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-02-13 10:53:32 -0600

Seen: 15 times

Last updated: Feb 14