0
$\begingroup$

Rosanswers logo

Hi All

I have code for a ROS node that subscribes to A PointCloud2 topic published by iai_kinect2's kinect bridge. My problem is that the code runs quite slowly. I have narrowed down the slowing-down to my spinOnce() statement, so I'm pretty sure it's my callback function that's being slow. However, my callback is using the reccommended way of converting the pc2 message into a PCL point cloud. Here it is for reference:

void cloudCallback(const sensor_msgs::PointCloud2ConstPtr& msg){
  // Create a container for the data.
  pcl::PCLPointCloud2 pcl_pc2;
  pcl_conversions::toPCL(*msg,pcl_pc2);
  pcl::fromPCLPointCloud2(pcl_pc2,*cloud);

  pcl::removeNaNFromPointCloud(*cloud,*outputCloud, indices);

  sor.setInputCloud(outputCloud);
  sor.setLeafSize (0.01f, 0.01f, 0.01f);
  sor.filter (*outputCloudFilt);
}

All the objects used here were pre-initialised before main(). The code runs just as slowly if I remove the filtering from the callback.

I should also add that the speed is slow independently of how many points are in the cloud.

EDIT: Using fromROSMsg() doesn't help with my problem.


Originally posted by christophecricket on ROS Answers with karma: 21 on 2020-03-24

Post score: 0


Original comments

Comment by gvdhoorn on 2020-03-24:
Something to check: did you compile with optimisations enabled?

And not an answer, but pcl_ros comes with a few PCL filters wrapped in nodelets: wiki/pcl_ros - Nodelets.

Comment by stevemacenski on 2020-03-24:
Also, please give us your full code, for all we know the issue is somewhere over there. Also please describe what "slow" means to you. Give us some metrics to work with.

Comment by christophecricket on 2020-03-24:
Yeah fair enough. I meant that my code was running at like 0.1Hz, which is way slower than you would actually expect.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Thanks @gvdhoorn turning on compiler optimisation gives me speeds more in line with what I expect (~20-30Hz, and actually scales with the size of the cloud). To anyone else experiencing this problem: set the following flag in catkin_make:

-DCMAKE_BUILD_TYPE=Release

Originally posted by christophecricket with karma: 21 on 2020-03-24

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by stevemacenski on 2020-03-24:
Sounds about right! Was this for setting in your application or in your PCL/PCL ROS build itself?

Comment by christophecricket on 2020-03-25:
I just turned it on for the entirety of the packages in my src/ folder.

Comment by stevemacenski on 2020-03-25:
And what’s in that? PCL, pcl_perception? Just your application code?

Comment by christophecricket on 2020-03-25:
Oooh I just got what you're trying to ask. No it's just my application code. I didn't recompile the binaries for PCL or ROS.

Comment by stevemacenski on 2020-03-25:
ah ok,thanks

$\endgroup$

Your Answer

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