Setting rviz topic (publish <pcl::PointCloud<pcl::PointXYZ> >)

asked 2017-06-29 18:33:13 -0500

Arnold gravatar image

updated 2017-06-29 18:34:12 -0500

I'm trying to view a .pcd file with rviz.

I wrote a little script to read the file and than publish it. (Yes I included way to many headers)

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <ros/publisher.h>
#include <ros/ros.h>
#include <pcl_ros/publisher.h>
#include <pcl_ros/point_cloud.h>
#include <string>

pcl::PointCloud<pcl::PointXYZ>::Ptr loadPCDfile() //Laden eines PCD Files
    //Nach dem Dateipfad fragen
    std::string pcdpath;
    std::cout << "Bitte Pfad+Name.pcd eingeben: ";
    //Einagbe lesen
    std::getline(std::cin, pcdpath);
    //Ausgabe der Eingabe
    //std::cout<< pcdpath << std::endl;

    // Erkennen ob es sich um eine gültige Eingabe handelt (
    pcl::PointCloud<pcl::PointXYZ>::Ptr pcdcloud(
            new pcl::PointCloud<pcl::PointXYZ>);

    if (pcl::io::loadPCDFile<pcl::PointXYZ>(pcdpath, *pcdcloud) == -1) //* load the file
        std::cout << "Keine pcd Datei gefunden unter: " << pcdpath << std::endl;
    return pcdcloud;

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

    pcl::PointCloud<pcl::PointXYZ>::Ptr pcdcloud = loadPCDfile(); //Laden unserer PCD Datei

    /*for (size_t i = 0; i < pcdcloud->points.size (); ++i)
     std::cout << "    " << pcdcloud->points[i].x
     << " "    << pcdcloud->points[i].y
     << " "    << pcdcloud->points[i].z << std::endl;
    // Initialize ROS
    ros::init(argc, argv, "pcdcloud");
    ros::NodeHandle nh;
    // Create a ROS publisher for the output pointcloud
    ros::Publisher pubrviz = nh.advertise<pcl::PointCloud<pcl::PointXYZ> >("pcdcloud", 1);
    ros::Rate loop_rate(10);
    // Spin
    return (0);

The reading Part should be fine, since I get a lot of points returned when I don't comment the for loop out. When I build it I get no error returned.

But I can't get the rviz gui to show the cloud. I used rosrun tf static_transform_publisher 0 0 0 0 0 0 1 map my_frame 10 to set up the tf map. link

Probably I'm doing something wrong withing with the topic.

image description

edit retag flag offensive close merge delete


This is not a real solution, but you might be interested in pcd_to_pointcloud.

gvdhoorn gravatar imagegvdhoorn ( 2017-06-30 01:45:41 -0500 )edit

I saw this, too. But I need to use some segmentation later on in the project, so its no solution. But I can try to use it for the troubleshooting. Thank you.

Arnold gravatar imageArnold ( 2017-06-30 02:39:54 -0500 )edit