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

Is it possible to reuse ROS messages?

asked 2014-08-06 15:17:31 -0600

Neil Traft gravatar image

After calling publish, can I reuse the same message object to send a similar message with some small changes? Basically I'm asking if the message is already serialized by the time the publish function returns. If it's not serialized right away, then there is a chance that I could overwrite some values from the previous message, and so it would not be possible to reuse it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2014-08-06 15:53:00 -0600

ahendrix gravatar image

In most cases, it's fine to re-use message objects.

if you're publishing shared pointers to messages, and subscribing within the came C++ node (or another nodelet in the same process), the pointers are passed directly, and the message should not be modified after it is published.

edit flag offensive delete link more

Comments

Okay, I think I understand the concern when publishing within the same node (because the message is never serialized), but if the message is serialized then it is done synchronously and is finished by the time `publish` returns?

Neil Traft gravatar image Neil Traft  ( 2014-08-06 16:25:20 -0600 )edit

Okay, I see it now. I just didn't know how to dig into the source code before, but I can see now that in topic_manager.cpp it is serialized right away.

Neil Traft gravatar image Neil Traft  ( 2014-08-06 16:30:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-08-06 15:17:31 -0600

Seen: 531 times

Last updated: Aug 06 '14