ROS PCL tutorials problem

asked 2018-03-30 15:33:12 -0500

tingwei gravatar image

updated 2018-04-06 01:59:27 -0500

ahendrix gravatar image

1.I follow the tutorials from ROS.org In the 4.1 section:sensor_msgs/PointCloud2 , I can use the catkin_make to compile the file without any error,doing the rosrun,and open the rviz , however, nothing shown by following the rviz setting steps ,do I miss any step?

2.the 4.2 section also didn't have any respond when I do the rosrun


Edit: these are my codes of example.cpp and CMakeLists.txt

1) CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)

project(my_pcl_tutorial)

find_package(catkin REQUIRED COMPONENTS
   pcl_conversions
   pcl_ros
   roscpp
   sensor_msgs
)

include_directories(
#include
  ${catkin_INCLUDE_DIRS}
)

add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES})

add_executable(planar_model_seg src/planar_model_seg.cpp)
target_link_libraries(planar_model_seg ${catkin_LIBRARIES})

find_package(PCL 1.2 REQUIRED)

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

add_executable (pcd_read src/pcd_read.cpp)
target_link_libraries (pcd_read ${PCL_LIBRARIES})

add_executable (voxel_grid src/voxel_grid.cpp)
target_link_libraries(voxel_grid ${PCL_LIBRARIES})

2) example,cpp

#include ros/ros.h
// PCL specific includes
#include sensor_msgs/PointCloud2.h
#include pcl_conversions/pcl_conversions.h
#include pcl/point_cloud.h
#include pcl/point_types.h

#include pcl/filters/voxel_grid.h

ros::Publisher pub;

void 
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
  // Container for original & filtered data
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; 
  pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
  pcl::PCLPointCloud2 cloud_filtered;

  // Convert to PCL data type
  pcl_conversions::toPCL(*cloud_msg, *cloud);

  // Perform the actual filtering
  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
  sor.setInputCloud (cloudPtr);
  sor.setLeafSize (0.1, 0.1, 0.1);
  sor.filter (cloud_filtered);

  // Convert to ROS data type
  sensor_msgs::PointCloud2 output;
  pcl_conversions::moveFromPCL(cloud_filtered, output);

  // Publish the data
  pub.publish (output);
}

int
main (int argc, char** argv)
{
  // Initialize ROS
  ros::init (argc, argv, "my_pcl_tutorial");
  ros::NodeHandle nh;

  // Create a ROS subscriber for the input point cloud
  ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("input", 1, cloud_cb);

  // Create a ROS publisher for the output point cloud
  pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);

  // Spin
  ros::spin ();
}
edit retag flag offensive close merge delete

Comments

Can you post the code you have complied?

ARB gravatar image ARB  ( 2018-04-01 11:43:22 -0500 )edit

I doubt CMakeLists.txt is a C++ source file ..

gvdhoorn gravatar image gvdhoorn  ( 2018-04-05 05:05:34 -0500 )edit

I am not sure about your problem but i usually put some print statements to narrow down the issue. Or use some kind of debugging.

BhanuKiran.Chaluvadi gravatar image BhanuKiran.Chaluvadi  ( 2018-04-05 06:06:42 -0500 )edit

Can you share your exact CMakelists.txt file..seems like you pasted source file twice

ARB gravatar image ARB  ( 2018-04-05 09:07:57 -0500 )edit

Do u have a topic in which Point cloud is being published and did u remap that topic to input while executing your source file?

ARB gravatar image ARB  ( 2018-04-05 09:10:58 -0500 )edit

Follow these steps: 1.Add this to ur CMakelists.txt

add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES})

2.navigate to ur catkin workspace and do catkin_make 3.launch roscore in one terminal

ARB gravatar image ARB  ( 2018-04-05 09:24:38 -0500 )edit

4.execute this in new terminal

 rosrun my_pcl_tutorial example input:=/camera/depth/points

Make sure that point cloud is being published into camera/depth/points

ARB gravatar image ARB  ( 2018-04-05 09:26:02 -0500 )edit

thanks for replying , sorry for putting wrong CMakeLists .The codes can do the catkin_make ,when executing ,I open three terminals for roscore,rosrun and ros rviz rviz ,and I also follow the setting of RVIZ,but nothing shown in rviz

tingwei gravatar image tingwei  ( 2018-04-05 11:27:38 -0500 )edit