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

Equivalent of rospy.AnyMsg but only for messages with a Header?

asked 2016-03-31 13:32:29 -0500

lucasw gravatar image

updated 2020-11-21 12:06:41 -0500

Is there an equivalent of rospy.AnyMsg that would work for all message types with a Header?

I'd like to have a message_filters.TimeSynchronizer subscribe to a generic message type, but it has to have a Header.

Trying to put AnyMsg into the synchronizer yields:

[ERROR] [/demux_topic] [/opt/ros/jade/lib/python2.7/dist-packages/rospy/topics.py]:[723] [bad callback: <bound method Subscriber.callback of <message_filters.Subscriber instance at 0x7f6d333c75f0>>
Traceback (most recent call last):
  File "/opt/ros/jade/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
    cb(msg)
  File "/opt/ros/jade/lib/python2.7/dist-packages/message_filters/__init__.py", line 74, in callback
    self.signalMessage(msg)
  File "/opt/ros/jade/lib/python2.7/dist-packages/message_filters/__init__.py", line 56, in signalMessage
    cb(*(msg + args))
  File "/opt/ros/jade/lib/python2.7/dist-packages/message_filters/__init__.py", line 190, in add
    my_queue[msg.header.stamp] = msg
AttributeError: 'AnyMsg' object has no attribute 'header'
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-03-31 15:40:56 -0500

lucasw gravatar image

updated 2016-04-01 12:40:42 -0500

I created a solution to this using a bootstrapping technique: subscribe to an AnyMsg with a regular rospy.Subscriber callback, then look in _connection_header['message_definition'] for Header header then if it has it:

Current solution

import roslib.message
...
topic_type = msg._connection_header['type']
topic_class = roslib.message.get_message_class(topic_type)
bootstrap_sub.unregister()
sub = message_filters.Subscriber("foo", topic_class)

Possible Solution

__import__ or importlib - need an example.

Previous solution

if it exists import the message type using exec(), then resubscribe with a message_filters.Subscriber using eval() and create the TimeSynchronizer, unregister the bootstrap subscriber.

Using exec and eval is undesirable for security reasons.

edit flag offensive delete link more

Comments

1

Can you describe why you need to use exec() or eval()? Wouldn't __import(..)__ (or __importlib__(..)) allow you to import modules by name?

gvdhoorn gravatar image gvdhoorn  ( 2016-04-01 00:56:29 -0500 )edit

I briefly tried out importlib, didn't get it right, but a search for rospy importlib brought me to roslib, which works fine.

lucasw gravatar image lucasw  ( 2016-04-01 12:13:05 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-03-31 13:32:29 -0500

Seen: 795 times

Last updated: Apr 01 '16