Publishing Point Clouds

asked 2021-11-17 15:22:09 -0500

neRoss gravatar image

I'm trying to design a program that sends a series of point clouds between ros nodes. I'm following this article on the wiki. The Code I have is as follows for the Publisher,

int main(int argc, char* argv[]) {
ros::init(argc, argv, "pub_pcl");
ros:: NodeHandle nhl;
ros::Publisher pub2 = nhl.advertise<PointCloudT>("stitchData/points", 1000);
PointCloudT::Ptr demo (new PointCloudT);
demo->header.frame_id = "some_tf_frame";
demo->height = demo->width = 1;
demo->points.push_back (pcl::PointXYZ(1.0, 2.0, 3.0));
demo->points.push_back (pcl::PointXYZ(2.0, 2.0, 3.0));
//demo->points.push_back (pcl::PointXYZ(3.0, 2.0, 3.0));
//demo->points.push_back (pcl::PointXYZ(4.0, 2.0, 3.0));
//demo->points.push_back (pcl::PointXYZ(5.0, 2.0, 3.0));
 ros::Rate loop_rate(4);
while(nhl.ok()) {
    std::cout << "Publishing Cloud" << std::endl;
    pcl_conversions::toPCL(ros::Time::now(), demo->header.stamp);
    pub2.publish (demo);

    ros::spinOnce ();
    loop_rate.sleep();
}

return 0;

And the Subscriber,

void PCCallback(const PointCloudT::ConstPtr& msg) {

    std::cout << "Received a Point Cloud" << std::endl;
    std::cout << "Width: " << msg->width << std::endl;
    std::cout << "Size: " << msg->size() << std::endl;
    std::cout << "Points: " << msg->points.size() << std::endl;

} 

int main(int argc, char* argv[]) {
    ros::init(argc, argv, "listener");

    ros::NodeHandle n;

    ros::Subscriber pcSub = n.subscribe<PointCloudT>("stitchData/points", 1000, PCCallback);

    ros::spin();

    return 0;
}

Whenever I run the two, however, I am only ever able to receive one point in the received point cloud. Is this an aspect of the specification that I am unaware of? Any feedback would be appreciated. Thanks.

edit retag flag offensive close merge delete

Comments

Hi @neRoss your PSCallback function is not iterating through the cloud points as in the tutorial:

BOOST_FOREACH (const pcl::PointXYZ& pt, msg->points)

osilva gravatar image osilva  ( 2021-11-17 15:58:45 -0500 )edit

This line: demo->height = demo->width = 1; Is saying that you have a point cloud 1 point high and 1 point wide, i.e. one point.

Geoff gravatar image Geoff  ( 2021-11-17 17:03:29 -0500 )edit