Difference between python and cpp publisher/subscriber

asked 2020-01-15 17:01:14 -0500

thompson104 gravatar image

updated 2020-01-15 17:02:56 -0500

Hello all,

I know it looks like a naive question. However, I have been using ROS for about 4 years...Our question is if there is some underlying difference between the cpp and python ROS publisher? If not, I wonder if anyone perhaps can share some thoughts on this matter? Thank you.

We are sending a float number (that's all) to an industry servo to control its current position. The float number is increasing in each time step by a fixed number, for example, 10->10.1->10.2... When we are publishing this incremental number to the servo control node (written with cpp) with cpp publisher, the motion is quite jerky. However, when we use python to write exactly the same thing to publish this incremental number to the same servo control node with the same frequency, the motion is much smoother. We can tell the motion is much smoother just by my eyes, so there is a quite noticeable difference.

edit retag flag offensive close merge delete


We are using ROS kinetic on Ubuntu 16.04

thompson104 gravatar image thompson104  ( 2020-01-15 17:01:27 -0500 )edit

Could you share the publishing code segments for both cpp and python?

Namal Senarathne gravatar image Namal Senarathne  ( 2020-01-15 20:33:51 -0500 )edit

We'd need to see the code. It's not really a fair comparison if we don't understand the loops running and their rates with the settings on the publishers.

stevemacenski gravatar image stevemacenski  ( 2020-01-16 13:06:19 -0500 )edit

We faced the similar situation and after investigating we found a weird problem. To dig deep into the problem we send 50 images using both python and cpp code in a loop. Sending 50 images using python took around 1100ms, while using cpp took around 500ms. All of the images sent using python was received by the subscriber node, while using cpp publisher only 20 to 30 images (we tested many times) was received by the subscriber. Just to make sure the problem is not the subscriber, we tested with both cpp and python subscriber, almost the same result.

To make things more interesting, we used 4 subscriber node and 1 publisher and tested again. This time python took around 4500ms to publish all the images and cpp still took 500ms. all the images were received when using python and only half of them received using cpp.

It seems there ...(more)

Solariseir gravatar image Solariseir  ( 2022-08-09 10:01:51 -0500 )edit