0
$\begingroup$

EDIT: SOLUTION IS IN THE COMMENTS OF THE ANSWER

I am migrating a project from ROS1 to ROS2, I haven't created the project myself. In the main package, which is named 'rdds_kem123_test_package', there is a custom message which is an array of point clouds. This custom message is defined in the msg folder in the package. here is how the custom message file is written:

# ArrayPointCloud2.msg
std_msgs/Header header
sensor_msgs/PointCloud2[] cloud_array

In the CMakeLists file I have included the necessary things for the message:

cmake_minimum_required(VERSION 3.5)
project(rdds_kem123_test_package)

# Compile as C++14, supported in ROS2
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

# Find ament macros and libraries
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED) 
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_msgs REQUIRED)
find_package(tf2_sensor_msgs REQUIRED)
find_package(PCL REQUIRED COMPONENTS common io) # For pcl_conversions and pcl_ros

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})


set(msg_files
  "msg/ArrayPointCloud2.msg" 
)

rosidl_generate_interfaces(${PROJECT_NAME}
  ${msg_files}
  DEPENDENCIES std_msgs sensor_msgs
)


#including the C++ include directory 
include_directories(include)


add_executable(pcl_merge src/pcl_merge.cpp)
ament_target_dependencies(pcl_merge rclcpp std_msgs geometry_msgs sensor_msgs tf2 tf2_ros tf2_msgs tf2_sensor_msgs PCL)
target_link_libraries(pcl_merge ${PCL_LIBRARIES})
# the rest is adding executables in the same way as this and then installing them. 

In the package.xml file, I believe I am including the necessary dependencies as well:

  <buildtool_depend>ament_cmake</buildtool_depend>
  <buildtool_depend>ament_cmake_python</buildtool_depend>
  <depend>pcl_conversions</depend>
  <depend>pcl_ros</depend>
  <depend>rclcpp</depend>
  <depend>rclpy</depend>
  <depend>sensor_msgs</depend>
  <depend>std_msgs</depend>
  <depend>moveit_msgs</depend>
  <depend>tf2</depend>
  <depend>tf2_ros</depend>
  <depend>tf2_msgs</depend>
  <depend>tf2_sensor_msgs</depend>
  <depend>geometry_msgs</depend>
  <depend>rosidl_default_generators</depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

Then in one of my C++ scripts I try to include the header file of the custom message to use it to publish an array of point clouds, here is a part of that file:

#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <rdds_kem123_test_package/ArrayPointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

#Some code goes here and I call the custome message like the following 

//Custom message to store the clusters as individual clouds
rdds_kem123_test_package::ArrayPointCloud2 OutputClusters;

Everytime I try to build the package, I reach a 87% build and then it gives me the following error:

ros@ros:~/test_mig_ws$ colcon build --packages-select rdds_kem123_test_package Starting >>> rdds_kem123_test_package --- stderr: rdds_kem123_test_package
In file included from /home/ros/test_mig_ws/src/rdds_kem123_test_package/src/clustering.cpp:33: /home/ros/test_mig_ws/src/rdds_kem123_test_package/include/rdds_kem123_test_package/clustering.hpp:6:10: fatal error: rdds_kem123_test_package/ArrayPointCloud2.h: No such file or directory 6 | #include <rdds_kem123_test_package/ArrayPointCloud2.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.

One solution that I tried is to create a different package in the same workspace for interfaces, and I defined the custom message in it. The interfaces message built successfully without probelms, but then when I tried to include it again in the C++ script in the main package, it gave the same error as the following:

enter image description here

My understanding is that this header file should be created automatically by the building of the packages. ROS should create the source code needed for this custom message. I am not sure if I understand everything correctly, but I would really appreciate the help with this.

Thank you.

$\endgroup$
0

2 Answers 2

2
$\begingroup$

Have you added the new interfaces package to your ament_target_dependencies?

This is how my CMakeLists.txt looks like for a cpp executable:

...
find_package(reconstruction_msgs REQUIRED)
...

# Executables ------------------------------
add_executable(gp25_services_node
  src/ros_nodes/gp25_services_node.cpp
)
ament_target_dependencies( gp25_services_node
  rclcpp
  rclcpp_action
  moveit_ros_planning_interface
  reconstruction_msgs
)

The custom interface package in my case is the reconstruction_msgs.

Also make sure your #include ends with .hpp.

$\endgroup$
3
  • $\begingroup$ Yes I have added the needed changes to both files, similar to what you have as well, but I am still seeing the same error. $\endgroup$ Apr 9 at 7:31
  • $\begingroup$ The file you found in the other answer (with the lowercase naming) is the right one: #include <rdds_kem123_test_package/msg/array_point_cloud2.hpp> should point include the right msg type $\endgroup$
    – mink4sure
    Apr 9 at 7:44
  • $\begingroup$ Yes, Thank you, for some reason the name has changed to lower case with underscores, which i did not expect, and now when I compile that, I do not receive this error anymore. $\endgroup$ Apr 9 at 11:28
1
$\begingroup$

I believe that you would find the header file in a msg directory inside of the install folder so your include statement should actually be:

#include <rdds_kem123_test_package/msg/ArrayPointCloud2.hpp>

If you want to have the interfaces are defined in a separate ROS package for example rdds_kem123_interfaces. The rdds_kem123_test_package would need these changes:

CMakelists.txt
find_package(rdds_kem123_interfaces REQUIRED)

and

ament_target_dependencies(pcl_merge rclcpp std_msgs geometry_msgs sensor_msgs tf2 tf2_ros tf2_msgs tf2_sensor_msgs PCL rdds_kem123_interfaces)
Manifest (package.xml)
<depend>rdds_kem123_interfaces</depend>
$\endgroup$
1
  • $\begingroup$ Thank you @Justin, yes, I am focusing on the interfaces packages approach right now, I added the required CMakeLists and package.xml changes. and I am still getting the same error. But because of your comment about finding it in the install folder, I went there to test_mig_ws/install/ysio_interfaces/include/ysio_interfaces/msg , I found a header file that is called 'array_point_cloud2.hpp" and 'array_point_cloud2.h' (Original name: ArrayPointCloud2), when I try to include it with this different name, i get so many other errors in my folder, so I am not sure if this is the right thing. $\endgroup$ Apr 9 at 7:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.