the time delay of message: c++pub-c++sub and python_pub-c++sub
Hi, I intended to publish geometry_msgs/PoseArray with 40 poses every 40ms(25Hz), and find that when I use python to publish, the time delay between publisher and subscriber is unstable, but if I use c++ code to publish, the delay is very stable (about 0.6ms).
If I decrease the publishing frequency, both python-pub and c++-pub work fine. So the reason is message blocking? why do python-pub and c++-pub differ?
The test_pkg is here or zipped file.
command to run:
roscore
rosrun ros_tutorials_topic topic_publisher (rosrun ros_tutorials_topic talker.py)
clear;rosrun ros_tutorials_topic topic_subscriber
c++ pub, c++ sub, result:
msg stamp: 1686204251.396419, current_time: 1686204251.397029, lag: 0.609875ms
msg stamp: 1686204251.436181, current_time: 1686204251.436624, lag: 0.443220ms
msg stamp: 1686204251.476362, current_time: 1686204251.476907, lag: 0.545502ms
msg stamp: 1686204251.516361, current_time: 1686204251.516931, lag: 0.569582ms
msg stamp: 1686204251.556366, current_time: 1686204251.556851, lag: 0.484943ms
msg stamp: 1686204251.596394, current_time: 1686204251.596922, lag: 0.527382ms
msg stamp: 1686204251.636170, current_time: 1686204251.636633, lag: 0.462294ms
msg stamp: 1686204251.676356, current_time: 1686204251.676799, lag: 0.442743ms
msg stamp: 1686204251.716413, current_time: 1686204251.717030, lag: 0.616789ms
msg stamp: 1686204251.756269, current_time: 1686204251.756616, lag: 0.346422ms
msg stamp: 1686204251.796351, current_time: 1686204251.796906, lag: 0.554323ms
msg stamp: 1686204251.836172, current_time: 1686204251.836589, lag: 0.416517ms
msg stamp: 1686204251.876308, current_time: 1686204251.876890, lag: 0.582457ms
msg stamp: 1686204251.916340, current_time: 1686204251.916957, lag: 0.616550ms
msg stamp: 1686204251.956398, current_time: 1686204251.957023, lag: 0.625134ms
msg stamp: 1686204251.996382, current_time: 1686204251.997041, lag: 0.658512ms
msg stamp: 1686204252.036172, current_time: 1686204252.036653, lag: 0.481129ms
msg stamp: 1686204252.076376, current_time: 1686204252.076791, lag: 0.414848ms
msg stamp: 1686204252.116351, current_time: 1686204252.116970, lag: 0.619173ms
msg stamp: 1686204252.156344, current_time: 1686204252.157006, lag: 0.661850ms
msg stamp: 1686204252.196401, current_time: 1686204252.197004, lag: 0.602484ms
msg stamp: 1686204252.236174, current_time: 1686204252.236653, lag: 0.478745ms
msg stamp: 1686204252.276370, current_time: 1686204252.276992, lag: 0.621319ms
msg stamp: 1686204252.316295, current_time: 1686204252.316830, lag: 0.535250ms
msg stamp: 1686204252.356408, current_time: 1686204252.357079, lag: 0.671387ms
msg stamp: 1686204252.396413, current_time: 1686204252.397089, lag: 0.675440ms
msg stamp: 1686204252.436182, current_time: 1686204252.436805, lag: 0.623226ms
msg stamp: 1686204252.476397, current_time: 1686204252.477075, lag: 0.678062ms
msg stamp: 1686204252.516356, current_time: 1686204252.516959, lag: 0.603199ms
msg stamp: 1686204252.556360, current_time: 1686204252.557067, lag: 0.706673ms
msg stamp: 1686204252.596378, current_time: 1686204252.597093, lag: 0.715017ms
msg stamp: 1686204252.636172, current_time: 1686204252.636656, lag: 0.483751ms
msg stamp: 1686204252.676338, current_time: 1686204252.676964, lag: 0.625372ms
python pub, c++ sub, result:
msg stamp: 1686203878.882146, current_time: 1686203878.882632, lag: 0.485897ms
msg stamp: 1686203878.922367, current_time: 1686203878.922922, lag: 0.555277ms
msg stamp: 1686203878.962177, current_time: 1686203878.962702, lag: 0.524282ms
msg stamp: 1686203879.002203, current_time: 1686203879.002517, lag: 0.313282ms
msg stamp: 1686203879.042304, current_time: 1686203879.042747, lag: 0.443220ms
msg stamp: 1686203879.082170, current_time: 1686203879.082615, lag: 0.445127ms
msg stamp: 1686203879.122229, current_time: 1686203879.122649, lag: 0.419617ms
msg stamp: 1686203879.162186, current_time: 1686203879.162734, lag: 0.547409ms
msg stamp: 1686203879.202178, current_time: 1686203879.202579, lag: 0.401020ms
msg stamp: 1686203879.242177, current_time: 1686203879.242615, lag: 0.437498ms
msg stamp: 1686203879.282175, current_time: 1686203879.282565, lag: 0.389814ms
msg stamp: 1686203879.322175, current_time: 1686203879.322594, lag: 0.419140ms
msg stamp: 1686203879.362374, current_time: 1686203879.362831, lag: 0.457764ms
msg stamp: 1686203879.402170, current_time: 1686203879.402704, lag: 0.533104ms
msg stamp: 1686203879.442173, current_time: 1686203879.442550, lag: 0.376940ms
msg stamp: 1686203879.482183, current_time: 1686203879.482567, lag: 0.384331ms
msg stamp: 1686203879.522172, current_time: 1686203879.530254, lag: 8.081675ms
msg stamp: 1686203879.562421, current_time: 1686203879.574241, lag: 11.819601ms
msg stamp: 1686203879.602233, current_time: 1686203879.618374, lag: 16.141176ms
msg stamp: 1686203879.642168, current_time: 1686203879.662158, lag: 19.990206ms
msg stamp: 1686203879.682220, current_time: 1686203879.706085, lag: 23.865223ms
msg stamp: 1686203879.722202, current_time: 1686203879.750092, lag: 27.889252ms
msg stamp: 1686203879.762222, current_time: 1686203879.794236, lag: 32.014370ms
msg stamp: 1686203879.802184, current_time: 1686203879.838299, lag: 36.114931ms
msg stamp: 1686203879.842179, current_time: 1686203879.882104, lag: 39.925814ms
msg stamp: 1686203879.882168, current_time: 1686203879.926335, lag: 44.166803ms
msg stamp: 1686203879.922308, current_time: 1686203879.926356, lag: 4.047394ms
msg stamp: 1686203879.962175, current_time: 1686203879.970154, lag: 7.978201ms
I am using ubuntu 22.04, and install ros1 noetic from source.
Asked by xibeisiber on 2023-06-06 21:48:56 UTC
Answers
At higher publishing rates, you probably want to set the tcp_nodelay option. It should help with latency issues like you describe. I believe that you can set the option on either the publisher or the subscriber.
pub = rospy.Publisher(topic_name, msg_class, queue_size, tcp_nodelay=True)
Asked by Mike Scheutzow on 2023-06-07 09:26:40 UTC
Comments
Thanks. I added tcp_nodelay=True
, but see no improvement on my computer...
Asked by xibeisiber on 2023-06-08 01:08:20 UTC
Comments
Please don't post screenshots of text. Instead, copy/paste the actual text into your description and format it with the 101010 button.
Asked by Mike Scheutzow on 2023-06-07 09:27:32 UTC
Thank you for changing the screenshots to plain text. Could you check your github.com links? They do not work for me.
Asked by Mike Scheutzow on 2023-06-08 07:03:14 UTC
Sorry, I forget to make the repository public. They should work now.
Asked by xibeisiber on 2023-06-08 07:50:51 UTC
Your c++ publisher is buggy: 1) it never clears the pose array, so the message size increases forever. Ros does not handle enormous messages well, 2) having no spinner is bad node design (but probably not the cause of this specific issue.)
From what I see, it's your cpp->cpp case that should be having the trouble, not python->cpp.
Asked by Mike Scheutzow on 2023-06-10 10:37:32 UTC
1)Sorry, that was a mistake in the C++ publisher. After I correct it by putting
geometry_msgs::PoseArray msg
inside the loop, the delay behaves the same as python->cpp. So this has nothing to do with Python.. I now turn to use socket communication between python and C++.For the buggy C++ publisher, I don't understand why the delay is so small, but it will slightly increase as time goes on..
Asked by xibeisiber on 2023-06-12 01:29:21 UTC