2016-08-24 26 views
0

我嘗試用高斯分佈構建自己的點雲。 rviz的可視化不起作用。RVIZ:顯示自己的點雲

這裏是我創建點雲

int sizeOfCloud = 1000; 
keypoints.points.resize(sizeOfCloud); 
getRandomPointCloud(keypoints, 100, 100, sizeOfCloud); 

keypoints.header.frame_id = "base_link"; 
keypoints.header.stamp = ros::Time::now(); 
keypoints_publisher.publish(keypoints); 

,這裏是功能getRandomPointCloud:

void getRandomPointCloud(sensor_msgs::PointCloud& pc, int centerX, int centerY, int& sizeOfCloud) { 
    std::random_device rd; 
    std::mt19937 gen(rd()); 
    std::normal_distribution<> distX(centerX, 10); 
    std::normal_distribution<> distY(centerY, 10); 


    for (int i = 0; i < pc.points.size(); i++) { 
     double xValue = distX(gen); 
     double yValue = distY(gen); 
     std::cout << std::round(xValue) << std::endl; 
     pc.points[i].x = std::round(xValue); 
     pc.points[i].y = std::round(yValue); 
    } 
    std::cout << "done" << std::endl; 
} 

正如我所說的,它不能在rviz顯示。我按主題選擇,選擇適當的主題,然後屏幕上沒有任何內容。主題是正確的,如果我將網格設置爲base_link,那麼包含該主題的所有內容都可以。也許我必須在rviz中設置一個特殊的屬性,否則我不會正確構建我的pointcloud。

編輯:

這裏是rviz Screenshot from rviz

截圖現在,我認爲這個問題是更多關於「base_link」 TF話題不能得到解決。如果我試圖映射我的TF樹,那麼沒有條目。我如何在我的tf樹中設置base_link。或者我的目的還有另一種可能性嗎?

+0

貴的問題得到解答,對我的作品的代碼? – cassinaj

回答

0

消息sensor_msgs::PointCloud pc有一個Point32數組,它有x,y和z值。您正在設置每個點的x和y值,但是您缺少z值

我不知道,如果rviz可視化還需要信道的信息。如果儘管z值點雲依然不可見,請設置通道信息。該頻道是sensor_msgs::PointCloud中的一個數組,名爲channels,其類型爲ChannelFloat32。如果你有深入的信息,你可以使用一個通道:

sensor_msgs::ChannelFloat32 depth_channel; 
depth_channel.name = "distance"; 
for (int i = 0; i < pc.points.size(); i++) { 
    depth_channel.values.push_back(0.43242); // or set to a random value if you like 
} 
// add channel to point cloud 
pc.channels.push_back(depth_channel); 

同樣重要的是要發佈的消息不止一次才能看到它rviz常與TF打交道時,你需要更新時間戳記在標題中。

順便說一下你周圍的點百米/10米這就是傳播點的出路!

這裏是我的榜樣。 2D Gaussian generated by the point cloud

這裏是

#include <ros/ros.h> 
#include <sensor_msgs/PointCloud.h> 
#include <string> 
#include <random> 

void getRandomPointCloud(sensor_msgs::PointCloud& pc, 
         double centerX, 
         double centerY, 
         int& sizeOfCloud) { 
    std::random_device rd; 
    std::mt19937 gen(rd()); 
    std::normal_distribution<> distX(centerX, 2.); 
    std::normal_distribution<> distY(centerY, 2.); 

    for (int i = 0; i < pc.points.size(); i++) { 
    double xValue = distX(gen); 
    double yValue = distY(gen); 
    pc.points[i].x = xValue; 
    pc.points[i].y = yValue; 
    pc.points[i].z = 
     std::exp(-((xValue * xValue) + (yValue * yValue))/4.); 
    } 
    sensor_msgs::ChannelFloat32 depth_channel; 
    depth_channel.name = "distance"; 
    for (int i = 0; i < pc.points.size(); i++) { 
    depth_channel.values.push_back(pc.points[i].z); // or set to a random value if you like 
    } 
    // add channel to point cloud 
    pc.channels.push_back(depth_channel); 
} 

int main(int argc, char** argv) { 
    ros::init(argc, argv, "point_cloud_test"); 
    auto nh = ros::NodeHandle(); 

    int sizeOfCloud = 100000; 
    sensor_msgs::PointCloud keypoints; 
    keypoints.points.resize(sizeOfCloud); 
    getRandomPointCloud(keypoints, 0.5, 0.5, sizeOfCloud); 

    keypoints.header.frame_id = "base_link"; 
    keypoints.header.stamp = ros::Time::now(); 

    auto keypoints_publisher = 
     nh.advertise<sensor_msgs::PointCloud>("point_cloud", 10); 
    ros::Rate rate(30); 
    while (ros::ok()) { 
    keypoints.header.stamp = ros::Time::now(); 
    keypoints_publisher.publish(keypoints); 
    ros::spinOnce(); 
    rate.sleep(); 
    } 

    return 0; 
} 
+0

謝謝你的提示,但這並不能解決問題。所以我更新了我的第一篇文章。 – BeJay

+0

@BeJay請解決這個問題,如果它已經解決了! – cassinaj