Rosanswers logo

I try to build my own point cloud with a gaussian distribution. The visualization with rviz doesn't work.

Here is how I create the pointcloud

int sizeOfCloud = 1000;
getRandomPointCloud(keypoints, 100, 100, sizeOfCloud);

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

and here is the function 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;

As I said, it can't be displayed in rviz. I do select by topic, select the proper topic and then there is nothing on the screen. Topic is correct and if I set the grid to base_link then everything with the topic is okay. Maybe I have to set a special attribute in rviz or I don't build my pointcloud correctly.

Edit: My Publisher:

ros::Publisher keypoints_publisher;
keypoints_publisher = nh.advertise<sensor_msgs::PointCloud>("/keypoints", 1000);


Here is a screenshot of rviz. Maybe this shows my problem better

Screenshot RVIZ

Originally posted by JanB on ROS Answers with karma: 11 on 2016-08-24

Post score: 0

Original comments

Comment by Shay on 2016-08-24:
How is your keypoints_publisher defined?

Comment by JanB on 2016-08-24:
I've edited it in my question. Sorry for forgetting this piece of code.

Comment by Shay on 2016-08-25:
What is your fixed frame, the first line of Displays window.

Comment by JanB on 2016-08-25:
I've writen base_link in Fixed Frame


1 Answer 1


Rosanswers logo

  1. Do rostopic echo /keypoints and see if the messages are right.

  2. Add a PointCloud in RViz, select that /keypoints topic, see if the status is OK.

  3. Choose base_link as the fixed frame, see if everything is all right. If you want odom or map to be the fixed frame, you need to make sure your tf odom->base_link or map->odom->base_link is provided.

Originally posted by Shay with karma: 763 on 2016-08-24

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by Morgan on 2016-08-24:
These debugging steps are a great place to start. Without seeing the whole program it's hard to know, but perhaps you're publishing a single point cloud immediately after calling advertise() ? Since the peer-to-peer connections take time to set up, it's recommended to (re)publish topics periodically

Comment by JanB on 2016-08-25:
Thank you, step 1 and 2 is already done and successful. Step 3 is a little bit confusing to me. I don't know how to solve this base_link fixed frame. I edited my initial post to show a screen shot from my rviz.

Comment by Airuno2L on 2016-08-25:
@Morgan has a good point, are you just publishing the cloud once? If so, you should try publishing it periodically, like once every second until you get things working.

Comment by JanB on 2016-08-25:
thank you. I do publish it for a static period. And the published cloud can be seen with "rostopic echo /keypoints"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.