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

Creating custom msg message vs sending data on topic via string

asked 2022-07-21 13:30:34 -0500

Flash gravatar image

updated 2022-07-21 13:31:17 -0500

Hi,
I had a dilemma whether to create a custom message that has all the variables of a certain node or to convert those variables to a dictionary and send it as a string on a ROS topic.
So my question is which way is better when we compare it with data transmission. Which one will be faster and consume less memory?
Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-24 09:06:52 -0500

gvdhoorn gravatar image

So my question is which way is better when we compare it with data transmission.

Using semantically appropriate messages is always the "better" way.

Is your data structure a string? At the very least it's a dictionary, as you describe yourself. A dictionary != string.

Do not use strings to transmit data structures.

It's unnecessary and undesirable.

Which one will be faster and consume less memory?

Unless you have evidence already using a custom message (with proper fields) is causing you performance issues, do not prematurely optimise.

edit flag offensive delete link more

Comments

I was thinking that since using a custom message will have multiple fields means each field will have a key and values kind of data structure. This is similar to a dictionary data structure.
So are there any advantages of using a custom message over converting a dictionary to a string and sending it as a string, because both ways it will have the same amount of data as per my understanding? or when we use ROS custom messages it only transmits values and decodes those values at that node using a custom data structure format.

Flash gravatar image Flash  ( 2022-07-24 11:08:42 -0500 )edit
1

Only values are transmitted.

But that's not the point here.

A string has no meaning. If you receive a std_msgs/String, could you tell me what it contains? Other than some characters?

If you receive (for example) a sensor_msgs/PointCloud2, could you tell me what it contains? I believe you can: a pointcloud.

So semantically, it's clear that a sensor_msgs/PointCloud2 is not a string.

That's what the guiding principle should be when using ROS: clear, semantically meaningful messages.

gvdhoorn gravatar image gvdhoorn  ( 2022-07-25 04:30:52 -0500 )edit

Only values are transmitted.

Thx that's what I was looking for.
And I do agree that the topic should have a clear indication as you mentioned.
And if it uses less memory in doing so then we should definitely go for it, if your topic is for internal communication only. Correct me if I am wrong.

Flash gravatar image Flash  ( 2022-07-25 08:40:05 -0500 )edit

It's unclear to me what "internal communication" means or why one should eschew good semantic practice in them.

BlakeAnderson gravatar image BlakeAnderson  ( 2022-07-25 11:27:29 -0500 )edit

internal communication in terms of when you are not sharing those topics publicly

Flash gravatar image Flash  ( 2022-07-25 11:29:53 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-07-21 13:30:34 -0500

Seen: 220 times

Last updated: Jul 24 '22