Ask Your Question

how does ros communication works

asked 2019-02-12 16:33:27 -0600

debonair gravatar image

updated 2019-02-12 17:34:10 -0600

When does ros calls serialize::read() write() methods? when message is publishing, does it call serialization::write internally? and If I am subscribing to particular type on receiver side, does it call instantiate() or read() method? Lets assume when I publish rosbag::MessageInstance from publisher, and I am subscribed to MsgType, does it call instantiate()? how does it convert ros:MessageInstance to MsgType ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-12 18:00:16 -0600

ahendrix gravatar image

ROS messages are transferred over TCP as serialized data.

If you're subscribing to normal message type (for example std_msgs/String or whatever), then ros::serialization::Serializer<std_msgs::String>::read() is called by roscpp to deserialize the message, and the deserialized message is passed to your callback.

If you're publishing to normal message type (for example std_msgs/String or whatever), then ros::serialization::Serializer<std_msgs::String>::write() is called after you call publish(), to serialize the message.

If you're publishing and subscribing std_msgs::String::ConstPtr within the same process (often when using nodelets), the serialization and deserialization steps are skipped for messages passed within the same process. (if there are publishers or subscribers outside the process, serialization still happens).

rosbag is a bit of a special case; instead of handling normal messages, it directly handles the serialized data and message description. When rosbag records, it writes the serialized data (and the message MD5) directly to the bag file, without deserialized it (and without needing to be compiled against every message type). When rosbag plays back a file, it advertises with the same MD5 that was used during recording, and then it reads the serialized data and publishes it directly. Deserialization of these messages happens in the subscriber in the normal way (assuming the MD5 still matches).

The rosbag instantiate() is only used in the rosbag C++ API, if you want to read a specific message type from a bag file in C++.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-02-12 16:33:27 -0600

Seen: 345 times

Last updated: Feb 12 '19