0
$\begingroup$

Rosanswers logo

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


Originally posted by dinamex on ROS Answers with karma: 447 on 2011-11-29

Post score: 0


Original comments

Comment by Martin Peris on 2011-11-29:
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). :)

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Mac with karma: 4119 on 2011-11-29

This answer was NOT ACCEPTED on the original site

Post score: 4

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.

rosbuild_add_boost_directories()

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


Originally posted by dinamex with karma: 447 on 2011-11-29

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.