Ask Your Question
0

subscribe field of message array

asked 2018-05-16 08:08:16 -0600

Markus gravatar image

updated 2018-05-16 08:14:40 -0600

Hey there,

I would like to subscribe a field of a message array.

E.g. if my message looks like this:

BallStates.msg:

BallState[] ball_states

BallState.msg:

std_msgs/Header header   
uint32 uid 
geometry_msgs/Point position

Only the BallStates.msg is published. And I would like to subscribe to the first ball in this message with message_filters

self.topic2_sub = message_filters.Subscriber("/ball_states[0]/ball_state" , BallState)
ts = message_filters.TimeSynchronizer([self.topic1_sub, self.topic2_sub], 10)
ts.registerCallback(self.topic12_cb)

For that however I get this error:

ball_states[0]/ball_state' is not a legal ROS graph resource name. This may cause problems with other ROS tools
  super(Subscriber, self).__init__(name, data_class, Registration.SUB)

However if I echo that topic in a terminal by rostopic echo /ball_states[0]/ball_state it works :)

Does anyone know a fast workaround to this?

I mean of course I can kind of publish the first ball in an extra message and subscribe to that one but this is actually not what I want.....

I would like to have a fast short solution that does not cost time....

Note something like this:

  <remap from="ball_states[0]" to="ball1"/>

also will not work for me...:

Invalid <remap> tag: remap from [/turtlebot3/ball_tracking/ball_states[0]] is not a valid ROS name.
XML is <remap from="/turtlebot3/ball_tracking/ball_states[0]" to="ball1"/>
The traceback for the exception was written to the log file
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-05-16 09:14:29 -0600

gvdhoorn gravatar image

updated 2018-05-16 09:20:56 -0600

And I would like to subscribe to the first ball in this message with message_filters

this is not supported.

However if I echo that topic in a terminal by rostopic echo /ball_states[0]/ball_state it works :)

yes, but that is a 'trick': rostopic subscribes in the regular way and then filters its output for you, so it appears to subscribe to a field (which is impossible). See #q232748 fi.

Does anyone know a fast workaround to this?

No.

Note something like this:

<remap from="ball_states[0]" to="ball1"/>

also will not work for me...:

No, because remapping fields is also not supported.

I would like to have a fast short solution that does not cost time....

Yes, wouldn't we all.

Perhaps it would be good if you can explain what it is that you are actually trying to do, instead of us trying to suggest alternatives for a solution you've already chosen.

Something that could perhaps work for you is to use the transform node from topic_tools to republish a single field as a separate message. See #q232748 again for how that could be done.

edit flag offensive delete link more

Comments

Thanks :) well but wouldn't that be a nice feature... ? To be easily able to subscribe a message of a message array? I kind of miss that and simply wanted to know if something like this exists....

Markus gravatar imageMarkus ( 2018-05-16 09:21:10 -0600 )edit

There's all sorts of issues with subscribing to individual fields that make this less convenient than it appears. That's probably why this hasn't been added/implemented. See some earlier Q&As about this same topic.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-16 09:22:31 -0600 )edit

See my edit for a possible approach. It would be almost like your remapping example.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-16 09:23:03 -0600 )edit

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

Stats

Asked: 2018-05-16 08:08:16 -0600

Seen: 126 times

Last updated: May 16 '18