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

the time delay of message: c++pub-c++sub and python_pub-c++sub [closed]

asked 2023-06-06 21:48:56 -0600

xibeisiber gravatar image

updated 2023-06-08 01:10:04 -0600

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 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by xibeisiber
close date 2023-06-12 01:34:38.730030

Comments

Please don't post screenshots of text. Instead, copy/paste the actual text into your description and format it with the 101010 button.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-06-07 09:27:32 -0600 )edit

Thank you for changing the screenshots to plain text. Could you check your github.com links? They do not work for me.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-06-08 07:03:14 -0600 )edit

Sorry, I forget to make the repository public. They should work now.

xibeisiber gravatar image xibeisiber  ( 2023-06-08 07:50:51 -0600 )edit

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.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-06-10 10:37:32 -0600 )edit

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..

xibeisiber gravatar image xibeisiber  ( 2023-06-12 01:29:21 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-07 09:26:40 -0600

Mike Scheutzow gravatar image

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)
edit flag offensive delete link more

Comments

Thanks. I added tcp_nodelay=True, but see no improvement on my computer...

xibeisiber gravatar image xibeisiber  ( 2023-06-08 01:08:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2023-06-06 21:48:56 -0600

Seen: 127 times

Last updated: Jun 08 '23