ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Error in building point cloud using PointCloud2

asked 2012-01-31 07:13:45 -0600

alfa_80 gravatar image

updated 2012-02-01 02:31:58 -0600

I've been trying to build a point cloud using pcl function as in the code. It seems to work as the point cloud gets accumulated over time as I monitor ROS_INFO output from rxconsole. The variable "cloud" in the code is a cloud that is gathered over time while "c_tmp" is a temporary cloud that is stored in.

The problem I'm currently having is that I couldn't be able to visualize it via rviz. As I click on the /cloud topic, it warns that "No messages received". As for /c_tmp topic, no surprise, it just works out the box. Any idea, how do I fix this? Is the point cloud building correctly coded?

sensor_msgs::PointCloud2 cloud; //Class variable

//    In a callback function
{
sensor_msgs::PointCloud2 c_tmp;

static tf::TransformBroadcaster tfb;
tf::Transform xform;
xform.setOrigin(tf::Vector3(pose3D_LDD.pose.position.x, pose3D_LDD.pose.position.y, pose3D_LDD.pose.position.z));
xform.setRotation(tf::Quaternion(pose3D_LDD.pose.orientation.x, pose3D_LDD.pose.orientation.y, pose3D_LDD.pose.orientation.z, pose3D_LDD.pose.orientation.w));
tfb.sendTransform(tf::StampedTransform(xform, ros::Time(pose3D_LDD.header.stamp), "base_link", "laser"));
tfListener_.waitForTransform("base_link", "laser", previous_scan_.header.stamp, ros::Duration(1.0));

try
{
    projector_.transformLaserScanToPointCloud("base_link", previous_scan_, c_tmp, tfListener_);

    if (!initialized_cloud_)
    {
        cloud = c_tmp;
        initialized_cloud_ = true;
    }
    else
    {
         pcl::concatenatePointCloud(cloud, c_tmp, cloud);

         ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
         ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
    }
}

EDIT

    if (!initialized_cloud_)
    {
        cloud = c_tmp;
        initialized_cloud_ = true;
    }
    else
    {
        pcl::concatenatePointCloud(cloud, c_tmp, temp_cloud);
        cloud = temp_cloud;

        ROS_INFO("From c_tmp: Got cloud with %u of width and %u of height", c_tmp.width, c_tmp.height);
        ROS_INFO("From cloud: Got cloud with %u of width and %u of height", cloud.width, cloud.height);
          }
edit retag flag offensive close merge delete

Comments

Can you point me to the documentation on pcl::concatenatePointCloud()? I can't find it anywhere
DimitriProsser gravatar image DimitriProsser  ( 2012-01-31 07:33:43 -0600 )edit
See here (http://www.ros.org/doc/diamondback/api/pcl/html/io_8cpp_source.html), this one not actually a documentation but would suffice to refer I think. Actually that function I just type pcl:: and with my autocompletion, then i guess the function itself should be self-explanatory.
alfa_80 gravatar image alfa_80  ( 2012-01-31 07:46:36 -0600 )edit
I'm not really sure, it is right or not.
alfa_80 gravatar image alfa_80  ( 2012-01-31 07:47:18 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-02-02 03:33:18 -0600

alfa_80 gravatar image

It is just solved. The lesson learned is the cloud itself has to be defined its frame. So, I define it in my launch file using static_transform_publisher package.

edit flag offensive delete link more
1

answered 2012-01-31 07:53:52 -0600

DimitriProsser gravatar image

updated 2012-01-31 07:54:42 -0600

If the documentation for pcl::concatenatePointCloud() is correct, you cannot provide cloud as a const input and also as the output. You must provide a third cloud to be filled in the function. Then, you can set cloud = third_cloud.

sensor_msgs::PointCloud2 temp_cloud;
pcl::concatenatePointCloud(cloud, c_tmp, temp_cloud);
cloud = temp_cloud;
edit flag offensive delete link more

Comments

Yes, I agree with you. I really overlooked it, 1st and 2nd arguments are constant. I rewrite it and run, but still having the same problem.
alfa_80 gravatar image alfa_80  ( 2012-01-31 08:08:01 -0600 )edit
By the way, at the moment, the best case I have is getting 2 messages received in rviz, but it's still problematic as I expect to get more than 100 messages at least.
alfa_80 gravatar image alfa_80  ( 2012-01-31 18:25:16 -0600 )edit
It may be a silly question... But, Are you actually publishing the messages?? have you a publisher like ros::Publisher pub = n.advertise<sensor_msgs::PointCloud2>("cloud", 100); and then do pub.publish(cloud);
jrcapriles gravatar image jrcapriles  ( 2012-02-01 01:28:52 -0600 )edit
Yes I do have, I set it like this "point_cloud_publisher_ = n.advertise<sensor_msgs::PointCloud2> ("/cloud", 100); "point_cloud_publisher_.publish(cloud);"
alfa_80 gravatar image alfa_80  ( 2012-02-01 01:55:35 -0600 )edit
Have you check that this callback is actually be called 100 times? If the incoming message is not being received, then the output message won't be published.
DimitriProsser gravatar image DimitriProsser  ( 2012-02-01 02:15:35 -0600 )edit
Yes, I've checked from the rxconsole and rostopic echo /cloud, it seems messages always come but, in rviz, they don't.
alfa_80 gravatar image alfa_80  ( 2012-02-01 02:33:18 -0600 )edit
are you sure that you are showing Pointcloud2 type message in rviz?
jrcapriles gravatar image jrcapriles  ( 2012-02-01 03:30:00 -0600 )edit
Yes, it is PointCloud2 not PointCloud i mean..
alfa_80 gravatar image alfa_80  ( 2012-02-01 04:22:15 -0600 )edit

Question Tools

Stats

Asked: 2012-01-31 07:13:45 -0600

Seen: 1,239 times

Last updated: Feb 02 '12