Robotics StackExchange | Archived questions

ROS PCL tutorials problem

1.I follow the tutorials from ROS.org In the 4.1 section:sensormsgs/PointCloud2 , I can use the catkinmake 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 ();
}

Asked by tingwei on 2018-03-30 15:33:12 UTC

Comments

Can you post the code you have complied?

Asked by ARB on 2018-04-01 11:43:22 UTC

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

Asked by gvdhoorn on 2018-04-05 05:05:34 UTC

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.

Asked by BhanuKiran.Chaluvadi on 2018-04-05 06:06:42 UTC

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

Asked by ARB on 2018-04-05 09:07:57 UTC

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?

Asked by ARB on 2018-04-05 09:10:58 UTC

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

Asked by ARB on 2018-04-05 09:24:38 UTC

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

Asked by ARB on 2018-04-05 09:26:02 UTC

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

Asked by tingwei on 2018-04-05 11:27:38 UTC

these are the screenshot of roscore,rosrun and ros rviz rviz 1.catkin_make 2.roscore 3.rosrun 4.rviz

Asked by tingwei on 2018-04-05 11:36:53 UTC

What provides the input topic for your tutorial node? The tutorial assumes you have a stereo camera or a depth sensor.

Asked by ahendrix on 2018-04-06 02:04:58 UTC

@tingwei you are not giving point cloud data to your program.. 1.Download one sample .pcd file from net and save it in your my_pcl_tutorial folder 2.navigate to my_pcl_tutorial folder and execute "rosrun my_pcl_tutorial pcd_read

Asked by ARB on 2018-04-06 17:24:03 UTC

in another terminal execute rosrun my_pcl_tutorial example input:=

Asked by ARB on 2018-04-06 17:24:56 UTC

@ARB thanks for the advise .I've download the .pcd file from PCL tutorial website :table_scene_lms400.pcd ,and I follow the steps and commands you gave ,afterexecute rosrun my_pcl_tutorial pcd_read ,but it shows synax error near unexpected token 'newline' ,so I remove the <>

Asked by tingwei on 2018-04-07 05:13:39 UTC

I can read the data from my .pcd file screenshot , and i also execute rosrun my_pcl_tutorial example input:= by removing the <>screenshot ,however, still nothing shown in rviz

Asked by tingwei on 2018-04-07 05:24:41 UTC

pcd_read.cpp just reads the data from .pcd file and print it on console.but we need to publish the same in a topic.check this https://github.com/PacktPublishing/Mastering-ROS-for-Robotics-Programming-Second-Edition/blob/master/Chapter10/pcl_ros_tutorial/src/pcl_read.cpp

Asked by ARB on 2018-04-07 11:57:57 UTC

Also, check if the global frame in rviz matches the frame of the pcl message. If you don't know the pcl frame, do a "rostopic echo | grep frame".

Asked by robotchicken on 2018-05-19 12:05:58 UTC

Answers