0
$\begingroup$

Rosanswers logo

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="[email protected]">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="[email protected]">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>

Originally posted by pablo.arandarod on ROS Answers with karma: 53 on 2022-04-06

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Hello,

As there https://docs.ros.org/en/foxy/Tutorials/Custom-ROS2-Interfaces.html:

tutorial_interfaces is the name of the new package. Note that it is a CMake package; there currently isn’t a way to generate a .msg or .srv file in a pure Python package. You can create a custom interface in a CMake package, and then use it in a Python node, which will be covered in the last section.

It looks like your custom_msgs_srvs is a pure Python package. Just redo it as a C++ one :)


Originally posted by ljaniec with karma: 3064 on 2022-04-06

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by pablo.arandarod on 2022-04-06:
I redid everything in C++ but now it seems that it is unable to find some header files. The error is:

fatal error: custom_msg_srv/msg/detail/float32_multi_array__struct.h: No such file or directory #include "custom_msg_srv/msg/detail/float32_multi_array__struct.h"

I tried to find some similar situations that other people encountered, but didn't find much

Comment by ljaniec on 2022-04-07:
Can you add this C++ version of the package? Maybe put it on GitHub so we can see what settings are you missing

Comment by pablo.arandarod on 2022-04-07:
I will show the entire CMakeLists.txt and package.xml in an edit. The repository for the project is the following one: https://github.com/PabloDavidAR/encode-task-impedance-from-demonstration. The package for the service can be found inside the src folder

Comment by ljaniec on 2022-04-07:
I didn't find in your CMakeLists.txt a line with a find_package(std_msgs REQUIRED) and in package.xml a line with <depend>std_msgs</depend> for use of Float32MultiArray. Use something similar to:

set(srv_files
    "srv/SensorCall.srv"
)

rosidl_generate_interfaces(${PROJECT_NAME}
  ${srv_files}
  DEPENDENCIES 
    std_msgs
    builtin_interfaces
)

Comment by pablo.arandarod on 2022-04-07:
I added the builtin_interafaces and the std_msgs to both the find_package and the rosidl_generate_interfaces parts of the CMakeLists file and to the package.xml file, but still not working.

The error that appears now is fatal error: custom_msg_srv/msg/detail/float32_multi_array__struct.hpp: No such file or directory 126 | #include "custom_msg_srv/msg/detail/float32_multi_array__struct.hpp"

Comment by ljaniec on 2022-04-07:
Which file has this line? How did you get this error? Put commands down + the whole terminal output. Overall, this line #include "custom_msg_srv/msg/detail/float32_multi_array__struct.hpp" looks a bit weird too. It should look more like #include "tutorial_interfaces/srv/add_three_ints.hpp" . Look at the tutorial again, this part: https://docs.ros.org/en/foxy/Tutorials/Custom-ROS2-Interfaces.html#testing-addthreeints-srv-with-service-client Remember about changes in the package.xml and CMakeLists.txt too

Comment by pablo.arandarod on 2022-04-07:
Okay, I managed to solve the problem, although the solution that I ended up finding is not what I would have preferred. The problem appears to be related to using a Float32MultiArray, and when using standard types, such as float32[], the problem disappears. I tried putting the std_msgs dependency, but it was not enough and the problem did not disappear.

Comment by ljaniec on 2022-04-07:
Maybe this step by step tutorial will be easier for you: https://roboticsbackend.com/ros2-create-custom-message/

Comment by pablo.arandarod on 2022-04-07:
Just found the error. When declaring the Float32MultiArray in the service it is needed to put before std_msgs/, which indicates that it is coming from that package. I will upvote this solution and write the answer with the needed changes.

$\endgroup$
0
$\begingroup$

Rosanswers logo

Firstly, huge thanks to ljaniec.

The problem was solved by doing the following changes:

  1. Changes in the service declaration. When using types that are declared in other packages, it is needed to indicate it in the message/service declaration. In my case, instead of writing Float32MultiArray, it is needed to write it the following way std_msgs/Float32MultiArray.

  2. Changes in the package.xml file. Add the dependency of the std_msgs by writing <depend>std_msgs</depend>.

  3. Changes in the CMakeLists.txt file. Add the dependency of the std_msgs by writing find_package(std_msgs REQUIRED). Also, as it can be seen in this post, it is needed to add those dependencies declarations in the rosidl_generate_interfaces section of the CMakeLists file. In my particular case: rosidl_generate_interfaces(${PROJECT_NAME} "srv/SensorCall.srv" DEPENDENCIES std_msgs )


Originally posted by pablo.arandarod with karma: 53 on 2022-04-07

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.