Problem adding PointCloud2 to a Custom Message

asked 2022-07-13 14:39:40 -0500

Anogornian gravatar image

updated 2022-07-20 15:23:01 -0500

I've been trying to work on creating my own custom messages by expanding upon the tutorial for custom .msg and .srv files found here: https://docs.ros.org/en/foxy/Tutorial.... I've successfully used .msg files I've created in other .msg files as field types, as per https://docs.ros.org/en/foxy/Concepts..., but I'm having trouble adding PointCloud2 to the message, which I want to use to transfer realsense camera data.

I think it has something to do with not referencing sensor_msgs correctly in the cmake or package.xml files, but I'm out of ideas. I've basically been trying everything I could find that might work, so the cmake is a bit cluttered with things that I don't think I actually need.

TestingMulti.msg:

int32 ros_class 10
float32[] bounding_one [1, 2, 3]
float32[] bounding_two [2, 3, 4]
float32[] bounding_three [3, 4, 5]
float32[] bounding_four [4, 5, 6]
float32[] bounding_five [5, 6, 7]
float32[] frame [10, 9, 8]
tutorial_interfaces/Channel testframe
sensor_msgs/PointCloud2 pcloud

CMakeLists:

cmake_minimum_required(VERSION 3.5)
project(tutorial_interfaces)

# 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)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

find_package(builtin_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Num.msg"
  "msg/Numtwo.msg"
  "msg/Testing.msg"
  "msg/Testingmulti.msg"
  "msg/ExampleOfUsingPredefinedMessage.msg"
  "msg/Channel.msg"
  "msg/Width.msg"
  "msg/Height.msg"
  "sensor_msgs/PointCloud2.msg"
  DEPENDENCIES sensor_msgs builtin_interfaces geometry_msgs std_msgs
  ADD_LINTER_TESTS
  generate_messages( DEPENDENCIES std_msgs sensor_msgs )
)

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()

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>tutorial_interfaces</name>
  <version>0.0.0</version>
  <description>custom msg testing</description>
  <maintainer email="anon@anon.anon">Anon</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rosidl_default_generators</build_depend>

  <exec_depend>rosidl_default_runtime</exec_depend>
  <exec_depend>sensor_msgs</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>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

The error/traceback that I get when I try to build is:

C:\dev_ws>colcon build --merge-install --packages-select tutorial_interfaces
[1.103s] root DEBUG Using proactor: IocpProactor
Starting >>> tutorial_interfaces
[1.174s] colcon.colcon_ros.prefix_path.catkin WARNING The path 'C:\opt\ros\foxy\x64\tools\vcpkg\installed\x64-windows' in the environment variable CMAKE_PREFIX_PATH doesn't exist
--- stderr: tutorial_interfaces
CMake Error at C:/opt/ros/foxy/x64/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:93 (message):
  rosidl_generate_interfaces() the passed file 'sensor_msgs/PointCloud2.msg'
  doesn't exist ...
(more)
edit retag flag offensive close merge delete

Comments

Figured it out. FYI for anyone having similar problems, the issue for me was in CMakeLists. I removed

DEPENDENCIES sensor_msgs builtin_interfaces geometry_msgs std_msgs
ADD_LINTER_TESTS

and it build error free and ran without issues.

Anogornian gravatar image Anogornian  ( 2022-07-23 15:53:58 -0500 )edit