Importing and defining custom services in ROS 2 Foxy
I have been trying to use some custom services that I created to read some sensor data in an UR5e. This service is declared in a package called custom_msgs_srvs, inside a folder called srv, with the name SensorCall.srv. This service is the used in nodes from different packages, not in that same package.
The package.xml file of the custom_msgs_srvs is:
<?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>custom_msgs_srvs</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="pablo.arandarod@gmail.com">pablo</maintainer>
<license>TODO: License declaration</license>
<depend>rclpy</depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>
In the setup.py of the package, in the data_files section of the setup, I had the following element:
(os.path.join('share', package_name, 'srv'), ["srv/SensorCall.srv"])
I import the service in the node that I'm using it by putting from custom_msgs_srvs.srv import SensorCall
.
I'm able to build everything with no problem, but when I try to execute the node that uses this service, I get the following error: ModuleNotFoundError: No module named 'custom_msgs_srvs.srv'
.
----Edit:
Adding the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.5)
project(custom_msg_srv)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# 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")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/SensorCall.srv"
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
And the package.xml:
<?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>custom_msg_srv</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="pablo.arandarod@gmail.com">pablo</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>