# simple pointcloud subscriber

I'm new to ROS and I stuck in a beginner problem. I already did the ROS Tutorials where I wrote a subscriber but it doesn't explain my problem. I wanna write a simple subscriber in C++ for the kinect (topic => /camera/depth_registered/points). My code looks like the following:

void pcdCallback(const sensor_msgs::PointCloud2ConstPtr& msg) {

ROS_INFO("pointcloud recieved");

}

int main(int argc, char **argv) {

ros::init(argc, argv, "pcdlistener");

ros::NodeHandle n;

ros::Subscriber sub = n.subscribe("/camera/depth_registered/points", 1000, pcdCallback);

ros::spin();

return 0;

}

My Problem is now that the compiling produces the following failure:

/home/ronny/ros/pkgs/subscriber_pcd/src/pcdsubscriber.cpp:7: error: ISO C++ forbids declaration of ‘sensor_msgs’ with no type

would be great to get a hint or solution.

regards

edit retag close merge delete

First of all, welcome to ROS! About your question: Did you forget this: #include <sensor_msgs/PointCloud2.h>? it would be helpful for us if you posted the complete code (with #includes and all that). :)
( 2011-11-29 01:21:33 -0500 )edit

Sort by » oldest newest most voted

Hey Guys,

I solved the problem on my own. It happened, what had to happen...
After I looked over an hour for the failure I posted the question and right after that I found the solution. I had forgotten to add the boost directories to the CMake.

But thanks for your quick response and hint with the pcl_ros I will definitely have a look on that.

more

You'll need to #include the appropriate header for PointCloud2s:

#include "sensor_msgs/PointCloud2.h"


However, let me suggest something better: rather than subscribe to PointCloud2 objects (which are literal translations of the on-the-wire format, and somewhat hard to deal with), take a look at pcl_ros, and subscribe to PointCloud<PointXYZ> (or PointCloud<PointXYZ>, depending on your data); that way, all of the translation to a PCL type (and all the helpful machinery that comes with it) are done for you.

more