ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why does ROS2 not have pcl::toRosMsg? Deprecated?

asked 2022-09-30 10:56:56 -0600

AHuguet gravatar image

I come from ROS(1) and pcl::toRosMsg is essential to everything to do with pointclouds. I see this message:

error: ‘fromROSMsg’ is not a member of ‘pcl’

It also happens with 'toROSMsg'. If I try pcl::fromPCLPointCloud2, for example, it works. I have seen that at PCL 1.12, toROSMsg and fromROSMsg are deprecated (why?) and it seems there's no substitute.

I am surely missing something...

My CMakeLists.txt is this:

cmake_minimum_required(VERSION 3.5)
project(hashtable)

# 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_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package( PCL 1.8 REQUIRED )
find_package(pcl_conversions REQUIRED)

add_executable(demo_hashtable3d
  src/main.cpp
  src/hashtable3d_public.cpp
  src/hashtable3d_private.cpp
  include/hashtable/hashtable3d.hpp
)

ament_target_dependencies(demo_hashtable3d rclcpp sensor_msgs pcl_conversions)

if( PCL_FOUND )

  # [C/C++]>[General]>[Additional Include Directories]
  include_directories( ${PCL_INCLUDE_DIRS} )

  # [C/C++]>[Preprocessor]>[Preprocessor Definitions]
  add_definitions( ${PCL_DEFINITIONS} )

  # For Use Not PreCompiled Features 
  #add_definitions( -DPCL_NO_PRECOMPILE )

  # [Linker]>[General]>[Additional Library Directories]
  link_directories( ${PCL_LIBRARY_DIRS} )

  # [Linker]>[Input]>[Additional Dependencies]
  target_link_libraries( demo_hashtable3d ${PCL_LIBRARIES} )

endif()

install(TARGETS
  demo_hashtable3d
  DESTINATION lib/${PROJECT_NAME})

ament_package()

and 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>hashtable</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="andreu@todo.todo">andreu</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>rclcpp</depend>
  <depend>sensor_msgs</depend>
  <depend>pcl_ros</depend>
  <depend>pcl_conversions</depend>

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

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-10-01 01:05:08 -0600

ravijoshi gravatar image

Assuming you are looking for a way to convert a sensor_msgs::msg::PointCloud2 to a pcl::PCLPointCloud2. If yes, please read below:

void MyClass::callback(const sensor_msgs::msg::PointCloud2::SharedPtr msgPtr)
{
  RCLCPP_INFO_STREAM(get_logger(), "[Input PointCloud] width " << msgPtr->width << " height " << msgPtr->height);

  pcl::PCLPointCloud2::Ptr cloudPtr(new pcl::PCLPointCloud2);
  pcl_conversions::toPCL(*msgPtr, *cloudPtr);

  RCLCPP_INFO_STREAM(get_logger(), "[Output PointCloud] width " << cloudPtr->width << " height " << cloudPtr->height);
}

Do not forget to add find_package(pcl_conversions REQUIRED) and ament_target_dependencies(... pcl_conversions) in your CMakeLists.txt file.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-09-30 10:56:56 -0600

Seen: 1,439 times

Last updated: Oct 01 '22