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

[ROS2] Service header files

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

jlepers gravatar image

Hi,

source: https://github.com/ros2/examples/blob...

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 ?

sum.srv
#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 ?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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 https://github.com/ros2/example_inter... for an example)

And use them in your package (using https://github.com/ros2/examples/tree... as an example)

edit flag offensive delete link more

Comments

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 image jlepers  ( 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 image marguedas  ( 2020-02-14 04:52:24 -0600 )edit

edit:

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

output:

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 image jlepers  ( 2020-02-14 04:58:36 -0600 )edit

Should I open a new question ?

jlepers gravatar image jlepers  ( 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 image marguedas  ( 2020-02-14 05:10:02 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 1,227 times

Last updated: Feb 14 '20