Ask Your Question
0

How is the service.hpp file generated from service.srv file in ROS2 ?

asked 2018-05-15 12:30:00 -0500

aks gravatar image

updated 2018-05-16 06:12:39 -0500

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 (find_package): By not providing "Findexample_interface.cmake" in CMAKE_MODULE_PATH 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 "example_interface" to CMAKE_PREFIX_PATH or set "example_interface_DIR" to a directory containing one of the above files. If "example_interface" provides a separate development package or SDK, be sure it has been installed.`

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-16 04:11:23 -0500

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/examp...

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!

edit flag offensive delete link more

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

aks gravatar imageaks ( 2018-05-16 05:01:56 -0500 )edit

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.

pokitoz gravatar imagepokitoz ( 2018-05-16 06:22:59 -0500 )edit

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...

aks gravatar imageaks ( 2018-05-16 10:25:28 -0500 )edit

AddTwoInts_Request with heatFlow_Request in the add_two_ints_client.cpp

aks gravatar imageaks ( 2018-05-16 10:26:43 -0500 )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

2 followers

Stats

Asked: 2018-05-15 12:30:00 -0500

Seen: 253 times

Last updated: May 16 '18