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

Ros publish() taking more time than expected

asked 2017-04-19 06:07:40 -0500

mkreddy477 gravatar image

updated 2017-04-21 01:27:16 -0500

Dear All

I have observed a strange behavior in my node. I am trying to publish pointcloud topic and subscribing in another node. While profiling the pointcloud node I have observed the publish() method was taking around 10ms of the time.
When no one subscribing there is no delay. The delay was observed when the other node was subscribing to the topic. I have also tried to echo the topic and observe the time.I have observed around 2ms delay.

Can any one explain me why this was happening and how can I minimize this overhead ?

EDIT: Adding source code

The snippet of code in the main method of the pointcloud subscribing node. In side callback I have only a print statement.

`typedef sync_policies::ExactTime<sensor_msgs::PointCloud2 ,sensor_msgs::Image, sensor_msgs::CameraInfo> MySyncPolicy;

message_filters::Subscriber<sensor_msgs::CameraInfo> imageCam_sub(nh,left_info_topic, 50);
message_filters::Subscriber<sensor_msgs::Image> image_sub(nh, left_topic, 50);
message_filters::Subscriber<sensor_msgs::PointCloud2> PC_sub(nh, topic_name, 50);


Synchronizer<MySyncPolicy> sync(MySyncPolicy(50),PC_sub, image_sub, imageCam_sub);
sync.registerCallback(boost::bind(&callback, &oD, _1, _2,_3));`

Thanks in advance

edit retag flag offensive close merge delete

Comments

You can try nodelets. It is faster specially in case of pointclouds.

arunavanag gravatar image arunavanag  ( 2017-04-19 20:53:16 -0500 )edit

I have tried them already and didn't observed much time difference.

mkreddy477 gravatar image mkreddy477  ( 2017-04-20 07:16:27 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-19 18:04:34 -0500

Geoff gravatar image

Even when publishing is asynchronous, the publish() method will always take some time when there are subscribers. When nothing is subscribing, there is nothing for it to do so it returns quickly, but when something subscribes, it must serialise the data and push it onto an output queue. For point clouds, which tend to be large, the serialisation can take a while. The good thing is that this time remains the same no matter how many subscribers there are.

If you are creating a synchronous publisher (by not passing the queue_size argument when you create the publisher) then message passing becomes synchronous, which could lead to a significant delay for large data like point clouds, particularly if the number of subscribers grows. You should always pass the queue_size argument when creating the publisher. See here for advice on choosing a good queue size.

edit flag offensive delete link more

Comments

Thanks for the reply. But if we can see the rostopic echo is also acts like a subscriber but it was taking around 2ms of time. and the node i have written was taking 9ms. why that huge difference in both the cases? can you please explain if possible.

mkreddy477 gravatar image mkreddy477  ( 2017-04-20 07:15:38 -0500 )edit

Without seeing your code it is hard to say why it is going slower. Can you post the code? It is possible that rostopic echo is subscribing using different settings and that is having an impact.

Geoff gravatar image Geoff  ( 2017-04-21 00:23:41 -0500 )edit

I haven't added any code to the call back. Just used and empty call back with a printout. I am updating the question with the code.

mkreddy477 gravatar image mkreddy477  ( 2017-04-21 01:21:32 -0500 )edit

Please post the full code for both the publishing and subscribing nodes.

Geoff gravatar image Geoff  ( 2017-04-21 01:34:03 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-19 06:07:40 -0500

Seen: 2,518 times

Last updated: Apr 21 '17