Fail to subscribe to PointCloud2 message type
I am new to ROS. I wrote a program that subscribe to [/camera/depth/color/points]. It has been proved the traffic can be caught. average: 14.75MB/s mean: 1.16MB min: 0.56MB max: 2.32MB window: 3
But it seems not responding. Where did I go wrong.
include "ros/ros.h"
include "std_msgs/String.h"
include <sensor_msgs pointcloud2.h="">
bool new_cloud_available_flag;
void callback(const sensor_msgs::PointCloud2ConstPtr&){
std::cout << "Entering callback";
new_cloud_available_flag = true;
}
int main (int argc, char** argv) {
ros::init(argc, argv, "pointcloudlistener");
ros::NodeHandle nh;
std::string topic = nh.resolveName("/camera/depth/color/points");
uint32_t queue_size = 1;
new_cloud_available_flag = false;
ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> (topic, queue_size, callback);
while(!new_cloud_available_flag)
{
ros::Time t0 = ros::Time::now();
while(ros::Time::now()-t0 < ros::Duration(0.001));
}
}
Try to clean a little your question.
Maybe spin is missing? http://wiki.ros.org/roscpp/Overview/C...
Put:
inside the while or:
avoiding the while loop
Apart from what @Solrac3589 pointed out, when you
resolveName()
you return a fully-qualified name, so it is posible you are not subscribing to"/camera/depth/color/points"
but"namespace/camera/depth/color/points"
Just to be sure the node is properly connected you can just type in terminal
rqt_graph
to see the ROS connection graph between nodes.