Ask Your Question

simple pointcloud subscriber

asked 2011-11-29 01:07:51 -0500

dinamex gravatar image

updated 2014-01-28 17:10:54 -0500

ngrennan gravatar image

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);


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.


edit retag flag offensive 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). :)
Martin Peris gravatar image Martin Peris  ( 2011-11-29 01:21:33 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2011-11-29 01:33:41 -0500

dinamex gravatar image

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.

edit flag offensive delete link more

answered 2011-11-29 01:19:12 -0500

Mac gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-11-29 01:07:51 -0500

Seen: 2,039 times

Last updated: Nov 29 '11