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

Why do we store the service file in example_interface in ROS2 ?

asked 2018-05-15 10:22:13 -0500

aks gravatar image

updated 2018-05-15 10:49:36 -0500

gvdhoorn gravatar image

Like in ROS1, the service file needs to be stored in srv folder(not compulsary but convention). In ROS2 as well we store them in a srv folder which is located in the example_interfaces folder. And then we always give it as a scope in the .cpp file for e.g.

auto handle_add_two_ints =
  [this](const std::shared_ptr<rmw_request_id_t> request_header,
    const std::shared_ptr<example_interfaces::srv::AddTwoInts::Request> request,
    std::shared_ptr<example_interfaces::srv::AddTwoInts::Response> response).

Here we use <example_interface::srv::AddTwoInts::Request> request as a parameter. Why ?

edit retag flag offensive close merge delete

Comments

Afaik there is no requirement to store your service definitions specifically in that package. You could use any package, just as in ROS1.

The examples just use that package because it is a package that stores the defs for the examples. So example_interfaces seems like an apt name.

gvdhoorn gravatar image gvdhoorn  ( 2018-05-15 10:50:28 -0500 )edit

But if I try to rename it for instance dummy_interface and then change the name accordingly in the CMAKELISTS, then it gives an error `CMake Error at CMakeLists.txt:15 (find_package): No package configuration file found. How can i create that ?

aks gravatar image aks  ( 2018-05-15 11:55:27 -0500 )edit

You'd have to create a new package called dummy_interface move the definition into the new package and add a dependency upon the dummy_interface package to any packages that use the service.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-05-15 12:13:40 -0500 )edit

I already mentioned that i did that :)

aks gravatar image aks  ( 2018-05-15 12:19:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-10 12:19:56 -0500

tfoote gravatar image

It is not necessary to store all Services in the example_interface package. They can be in any package the example_interface is just an example package.

There are a lot of other packages with messages and services defined in them. Just off the top of my head: rcl_interfaces and common_interfaces repositories have several packages with messages and services defined.

If you've changed the name on your package and it's not working I'd suggest posting enough information here to reproduce it so that we can help you make sure you have renamed everything that you need to rename. There's likely something that needed to be renamed that you overlooked.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-15 10:22:13 -0500

Seen: 356 times

Last updated: Oct 10 '19