如何在单独的节点ros pcl中发送群集

问题描述 投票:0回答:1

嗨,我是Pointcloud库的新手。我试图在rviz或pcl查看器上显示聚类结果点,然后什么也不显示。而且我意识到当我进行subcribe和cout时,我的数据也什么也没有显示。希望可以解决我的问题,谢谢

这是我的集群和发送节点代码

void cloudReceive(const sensor_msgs::PointCloud2ConstPtr& inputMsg){
mutex_lock.lock();
pcl::fromROSMsg(*inputMsg, *inputCloud);
cout<<inputCloud<<endl;
pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB>);
tree->setInputCloud(inputCloud);

std::vector<pcl::PointIndices> cluster_indices;
pcl::EuclideanClusterExtraction<pcl::PointXYZRGB> ec;

ec.setClusterTolerance(0.03);//2cm
ec.setMinClusterSize(200);//min points
ec.setMaxClusterSize(1000);//max points
ec.setSearchMethod(tree);
ec.setInputCloud(inputCloud);
ec.extract(cluster_indices);

if(cluster_indices.size() > 0){
    std::vector<pcl::PointIndices>::const_iterator it;

    int i = 0;

    for (it = cluster_indices.begin(); it != cluster_indices.end(); ++it){
        if(i >= 10)
            break;

        cloud_cluster[i]->points.clear();
        std::vector<int>::const_iterator idx_it;

        for (idx_it = it->indices.begin(); idx_it != it->indices.end(); idx_it++)
            cloud_cluster[i]->points.push_back(inputCloud->points[*idx_it]);

        cloud_cluster[i]->width = cloud_cluster[i]->points.size();
        // cloud_cluster[i]->height = 1;
        // cloud_cluster[i]->is_dense = true;

        cout<<"PointCloud representing the Cluster: " << cloud_cluster[i]->points.size() << " data points"<<endl;
        std::stringstream ss;
        ss<<"cobaa_pipecom2_cluster_"<< i << ".pcd";
        writer.write<pcl::PointXYZRGB> (ss.str(), *cloud_cluster[i], false);

        pcl::toROSMsg(*cloud_cluster[i], outputMsg);
        // cout<<"data = "<< outputMsg <<endl;
        cloud_cluster[i]->header.frame_id = FRAME_ID;
        pclpub[i++].publish(outputMsg);

        // i++;
    }
}
else
   ROS_INFO_STREAM("0 clusters extracted\n");

}

这是主要的

int main(int argc, char** argv){

for (int z = 0; z < 10; z++) {
    // std::cout << " - clustering/" << z << std::endl;

    cloud_cluster[z] = pcl::PointCloud<pcl::PointXYZRGB>::Ptr(new pcl::PointCloud<pcl::PointXYZRGB>);
    cloud_cluster[z]->height = 1;
    cloud_cluster[z]->is_dense = true;
    // cloud_cluster[z]->header.frame_id = FRAME_ID;
}

ros::init(argc,argv,"clustering");
ros::NodeHandlePtr nh(new ros::NodeHandle());
pclsub = nh->subscribe("/pclsegmen",1,cloudReceive);

std::string pub_str("clustering/0");

for (int z = 0; z < 10; z++) {
    pub_str[11] = z + 48;//48=0(ASCII)
    // z++;
    pclpub[z] = nh->advertise <sensor_msgs::PointCloud2> (pub_str, 1);
}

// pclpub = nh->advertise<sensor_msgs::PointCloud2>("/pclcluster",1);
ros::spin();

}

ros point-cloud-library
1个回答
0
投票

这不是确切的答案,但我认为它可以解决您的问题并可以简化调试。RViz可以直接订阅已发布的点云,我假设您要尝试在cloud_receive回调中看到它。如果将框架设置为要发布的框架,并从可用主题中添加框架,则应该看到要点。 (比尝试将其作为不同的主题进行广播更容易。)>

此外,我建议查看rostopic命令行工具。您可以执行rostopic检查它是否已发布,rostopic list查看它是否确实在发布预期的数据量(例如字节,千字节,兆字节),rostopic bw以查看其发布频率(如果有), (简短地)rostopic hz查看数据本身。 (这是我假设从您的问题来看,数据进入您的节点的问题更多)。

[如果遇到麻烦,既不是进入节点的数据,也不是一般的点云数据的可视化,而是要从节点出来的转换后的数据,我会检查集群是否工作正常,&减少代码,只让1个发布者发布某些内容。您可能正在做一些奇怪的事情。像弄乱了指针。您还可以使用rostopic echo为您的节点打开更强大的编译警告,或者逐步执行-Wall -Wextra -Werrorvia gdb)。

© www.soinside.com 2019 - 2024. All rights reserved.