Fail to subscribe to PointCloud2 message type

asked 2020-06-18 17:36:18 -0500

Chao Chen gravatar image

updated 2020-06-18 17:37:25 -0500

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

}

edit retag flag offensive close merge delete

Comments

1

Try to clean a little your question.

Maybe spin is missing? http://wiki.ros.org/roscpp/Overview/C...

Put:

ros::spinOnce();

inside the while or:

ros::spin();

avoiding the while loop

Solrac3589 gravatar image Solrac3589  ( 2020-06-19 00:27:43 -0500 )edit

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.

Weasfas gravatar image Weasfas  ( 2020-06-19 03:27:35 -0500 )edit