perception_pcl icon indicating copy to clipboard operation
perception_pcl copied to clipboard

Wiki page out-of-date

Open kunaltyagi opened this issue 5 years ago • 12 comments
trafficstars

Since PCL shifted to std::shared_ptr, the documentation on the wiki page is out of date. Example: https://wiki.ros.org/pcl_ros#Publishing_point_clouds

It uses a typedef from PCL, which is now std::shared_ptr<pcl::PointCloud<pcl::PointXYZ>> but ROS expects boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ>>

ros_ptr and pcl_ptr for interfacing between ROS and PCL might also need to be introduced.

kunaltyagi avatar Aug 06 '20 10:08 kunaltyagi

Relevant PointCloudLibrary/pcl#4307

kunaltyagi avatar Aug 06 '20 10:08 kunaltyagi

What specifically should change? I don't see anything with boost::shared_ptr, things look OK to me. Everything is typedefed from typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;, which I think should hide any of that to a user?

SteveMacenski avatar Aug 06 '20 19:08 SteveMacenski

With PCL 1.11 at least, the following lines will throw an error:

  • https://wiki.ros.org/pcl_ros#CA-226070dcbe48ef19c444eb4914084fc903868f16_14
  • https://wiki.ros.org/pcl_ros#CA-2c92c01374035f603e08bcde0eb24382b1ccd02e_8

That's due to them using std::shared_ptr (from PCL) while ROS expected boost::shared_ptr

kunaltyagi avatar Aug 06 '20 20:08 kunaltyagi

What's the specific fix I should change it to

SteveMacenski avatar Aug 06 '20 20:08 SteveMacenski

  • Not use PointCloud<T>::{Const}Ptr on subscriber callback parameter. Instead use boost::shared_ptr<{const} PointCloud<T>>
  • Use ros_ptr(message) in the publish calls to convert from std pointer to boost pointerc

kunaltyagi avatar Aug 06 '20 20:08 kunaltyagi

@kunaltyagi: This has been very useful. I am trying to use ROS Melodic with PCL 1.11.0 via perception_pcl but I am facing the same problem you mentioned above when publishing a point cloud. I tried to use ros_ptr. You can find the code as follows:

#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
void Publish_Cloud ( std::string frame_id, PointCloud::Ptr input_cloud )
{
  input_cloud->header.frame_id = frame_id;
  pub.publish ( pcl::ros_ptr ( input_cloud->makeShared () ) );
  // std::cout << "Published point cloud with frame_id: " << frame_id << std::endl;
}

However, I cannot find ros_ptr in the pcl namespace. Could you help me tackle this? In catkin_ws/src/ I have my perception package and the melodic_devel version of perception_pcl

The error message I get is:

pub.publish ( pcl::ros_ptr ( input_cloud->makeShared () ) );

And I have confirmed that ros_ptr is a member of the pcl namespace in the perception_pcl package.

fawadahm avatar Feb 05 '21 08:02 fawadahm

It should be present at the end of pcl_ros/point_cloud.h

The link might be wrong. On my mobile right now

kunaltyagi avatar Feb 05 '21 08:02 kunaltyagi

@kunaltyagi , thank you. I do see it there and I am trying to reference it using that namespace pcl::ros_ptr but I keep getting the same error i.e., ros_ptr is not a member of pcl. Could you please help me dig deeper? The following is what my CMakeLists.txt looks like:

# %Tag(FULLTEXT)%
cmake_minimum_required(VERSION 2.8.3)
project(perception)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS
	roscpp
	rospy
	std_msgs
	genmsg
	PCL
	rosbag)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include 
					${catkin_INCLUDE_DIRS} 
					${PCL_INCLUDE_DIRS}
    				#${Boost_INCLUDE_DIRS}
					)

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

# We need boost libraries
find_library(BOOST_SERIALIZATION boost_serialization)
if (NOT BOOST_SERIALIZATION)
	message(FATAL_ERROR "Can't find libboost_serialization")
endif()

find_library(BOOST_SYSTEM boost_system)
if (NOT BOOST_SYSTEM)
	message(FATAL_ERROR "Can't find libboost_serialization")
endif()

# Lidar compression from a bag
add_executable(pc_publisher src/point_cloud_publisher.cpp)
target_link_libraries(pc_publisher ${catkin_LIBRARIES} ${BOOST_SYSTEM} ${PCL_LIBRARIES})# ${Boost_LIBRARIES})
add_dependencies(pc_publisher perception)

fawadahm avatar Feb 05 '21 08:02 fawadahm

You need pcl_ros package, not the pcl catkin package. You might also need to use find package pcl and link the pcl libraries, if I remember correctly

kunaltyagi avatar Feb 05 '21 08:02 kunaltyagi

Thank you. By any chance, do you a catkin package that uses pcl_ros that I can use as a reference?

fawadahm avatar Feb 05 '21 19:02 fawadahm

Thank you. By any chance, do you a catkin package that uses pcl_ros that I can use as a reference?

Have a look at the wiki page, on the right side, under "Used by".

mvieth avatar Feb 05 '21 19:02 mvieth

Got it, thanks for all the help. It seems like I had installed an older version of pcl_ros through apt-get that I needed to remove and build the melodic_devel branch of pcl_ros instead.

fawadahm avatar Feb 05 '21 19:02 fawadahm