0
$\begingroup$

Rosanswers logo

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)


Originally posted by sisko on ROS Answers with karma: 247 on 2020-07-27

Post score: 0


Original comments

Comment by praskot on 2020-07-27:
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
$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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:

KeyValueLists.msg

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

KeyValueString.msg

std_msgs/String key
std_msgs/String value

and thus:

StringDictionary.msg

KeyValueString[] items

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


Originally posted by mgruhler with karma: 12390 on 2020-07-28

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by sisko on 2020-07-30:
Thanks, I'm working on your suggested solution

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.