How is the service.hpp file generated from service.srv file in ROS2 ?
While using services in ROS2, we include example_interfaces/srv/add_two_ints.hpp
in the server.cpp and client.cpp files. How is this file generated.
In my case, i created a new service file heatFlow.srv
and changed the CMakeLists.txt file and the cpp files accordingly. But when i try to build the package, it gives a fatal error : fatal error: example_interfaces/srv/heatFlow.hpp: No such file or directory
compilation terminated.
How are these .hpp
files basically generated ?
EDIT :
I created a new folder "example_interface" (note: without S in the end) and created a new service file called heatFlow.srv
. Now the CMakeLists is as follows :
cmake_minimum_required(VERSION 3.5) project(example_interface) # Default to C++14 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # we dont use add_compile_options with pedantic in message packages # because the Python C extensions dont comply with it set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() find_package(ament_cmake REQUIRED) find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "srv/heatFlow.srv" ) ament_export_dependencies(rosidl_default_runtime) install(FILES mapping_rules.yaml DESTINATION share/${PROJECT_NAME}) ament_package()
and the package.xml as follows:
> <?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org /2001/XMLSchema"?>
<package format="3">
<name>example_interface</name>
<version>0.4.0</version>
<description>Contains message and service definitions used by the examples.</description>
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
<license>Apache License 2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
<ros1_bridge mapping_rules="mapping_rules.yaml"/>
</export>
</package>
When I compile it using : ament build --symlink-install --only-package heatflow_cpp
, it gives an error `CMake Error at CMakeLists.txt:15 (findpackage):
By not providing "Findexampleinterface.cmake" in CMAKEMODULEPATH this
project has asked CMake to find a package configuration file provided by
"example_interface", but CMake did not find one.
Could not find a package configuration file provided by "example_interface" with any of the following names:
example_interfaceConfig.cmake
example_interface-config.cmake
Add the installation prefix of "exampleinterface" to CMAKEPREFIXPATH or set "exampleinterfaceDIR" to a directory containing one of the above files. If "exampleinterface" provides a separate development package or SDK, be sure it has been installed.`
Asked by aks on 2018-05-15 12:30:00 UTC
Answers
Hello!
Can you give the CmakeFile/Package.xml you created for your service? In my case it looks like https://github.com/ros2-for-arm/example/tree/master/trusted_application_demo/aes_custom_interface
If the service name is 'aes_custom_interface' Then you need to add the following line in the package,xml that is using this specific service;
<depend>aes_custom_interface</depend>
And in the Cmake:
find_package(aes_custom_interface REQUIRED)
ament_target_dependencies(${PROJECT_NAME}
...
aes_custom_interface)
About the generation of those header file, I believe this is done in rosidl_generate_interfaces function which is then generating header files for ROS2 and IDL files for the DDS.
Hope it helps!
Asked by pokitoz on 2018-05-16 04:11:23 UTC
Comments
@pokitoz thanks for the suggestion but i guess i have already added the dependencies. I have edited the question with the CMakelists and package.xml
Asked by aks on 2018-05-16 05:01:56 UTC
I would suggest to build from start (remove the --only-package heatflow_cpp). I think you are trying to build the package heatflow_cpp. I don't think the dependencies are build using --only-package.
Probably the package 'example_interface' containing your service has never been build.
Asked by pokitoz on 2018-05-16 06:22:59 UTC
yes, think this could be the point. But when i try to build all i get an error rosidl_parser.InvalidResourceName: heatFlow_Request
CMakeFiles/example_interfaces__cpp.dir/build.make:90: recipe for target 'rosidl_generator_cpp/example_interfaces/srv/add_two_ints.hpp' failed
. I replaced the...
Asked by aks on 2018-05-16 10:25:28 UTC
AddTwoInts_Request with heatFlow_Request
in the add_two_ints_client.cpp
Asked by aks on 2018-05-16 10:26:43 UTC
I have the same error. However, i do can compile my pkg with the srv, but the code pkg doesnt find the service. Dont know what to do. I will appreciate the help, thank you.
Asked by Peanpepu on 2022-04-26 01:43:08 UTC
Comments