Why do we store the service file in example_interface in ROS2 ?
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 ?
Asked by aks on 2018-05-15 10:22:13 UTC
Answers
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.
Asked by tfoote on 2019-10-10 12:19:56 UTC
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.Asked by gvdhoorn on 2018-05-15 10:50:28 UTC
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 ?Asked by aks on 2018-05-15 11:55:27 UTC
You'd have to create a new package called
dummy_interface
move the definition into the new package and add a dependency upon thedummy_interface
package to any packages that use the service.Asked by PeteBlackerThe3rd on 2018-05-15 12:13:40 UTC
I already mentioned that i did that :)
Asked by aks on 2018-05-15 12:19:50 UTC