Robotics StackExchange | Archived questions

Ros publish() taking more time than expected

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

Asked by mkreddy477 on 2017-04-19 06:07:40 UTC

Comments

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

Asked by arunavanag on 2017-04-19 20:53:16 UTC

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

Asked by mkreddy477 on 2017-04-20 07:16:27 UTC

Answers

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.

Asked by Geoff on 2017-04-19 18:04:34 UTC

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.

Asked by mkreddy477 on 2017-04-20 07:15:38 UTC

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.

Asked by Geoff on 2017-04-21 00:23:41 UTC

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.

Asked by mkreddy477 on 2017-04-21 01:21:32 UTC

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

Asked by Geoff on 2017-04-21 01:34:03 UTC