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

Ros publisher message type for arrays

asked 2020-07-27 20:46:02 -0500

sisko gravatar image

updated 2020-07-29 15:39:41 -0500

Can someone please tell me what message-type to use in publishing the following array?:

  ['/turtle1/color_sensor', 'turtlesim/Color'], 
  ['/client_count', 'std_msgs/Int32'], 
  ['/rosout', 'rosgraph_msgs/Log'], 
  ['/rosout_agg', 'rosgraph_msgs/Log'], 
  ['/connected_clients', 'rosbridge_msgs/ConnectedClients'], 
  ['/all_topics', 'std_msgs/String'], 
  ['/turtle1/cmd_vel', 'geometry_msgs/Twist'], 
  ['/turtle1/pose', 'turtlesim/Pose']

I'm reacquainting myself with ROS and learning the basics as I modify a basic talker to publish the array above instead of a string. I have consulted documentation but I'm having difficulty figuring out which of those message types to use, if any.

publisher = rospy.Publisher('/all_topics', ???, queue_size=1)

edit retag flag offensive close merge delete



I'm not sure, if you can use the std_msgs as it is, but maybe can custom-define your own msg? Something like this StringMultiArray.msg

std_msgs/MultiArrayDimension[] dim
std_msgs/String[] data
praskot gravatar image praskot  ( 2020-07-27 21:29:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-28 01:03:18 -0500

mgruhler gravatar image

updated 2020-07-28 01:03:33 -0500

There is no predefined message to do this easily. You can do what @praskot suggested, or go one of many other ways. (Note, you can always check the other common_msgs if you want to use one of the generic types ones)

In general, it is, however, advised to add semantic meaning to messages and thus stay away from the std_msgs package as much as possible. See also #q255674.

All in all, you have to create your own message type. The following are just some ways to do that, in addition to what @praskot suggested:


std_msgs/String[] keys
std_msgs/String[] values

Dictionary.msg (using a message from the diagnostic_msgs package)

diagnostic_msgs/KeyValue[] items

of course, you could that create yourself too, if you don't want to depend on the diagnostic_msgs package


std_msgs/String key
std_msgs/String value

and thus:


KeyValueString[] items

(obviously, the names are free to choose...)

edit flag offensive delete link more


Thanks, I'm working on your suggested solution

sisko gravatar image sisko  ( 2020-07-30 16:55:13 -0500 )edit

Question Tools



Asked: 2020-07-27 20:46:02 -0500

Seen: 2,701 times

Last updated: Jul 30 '20