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