Equivalent of rospy.AnyMsg but only for messages with a Header?
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'
Asked by lucasw on 2016-03-31 13:32:29 UTC
Answers
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.
Asked by lucasw on 2016-03-31 15:40:56 UTC
Comments
Can you describe why you need to use exec()
or eval()
? Wouldn't import(..) (or importlib(..)) allow you to import modules by name?
Asked by gvdhoorn on 2016-04-01 00:56:29 UTC
I briefly tried out importlib, didn't get it right, but a search for rospy importlib brought me to roslib, which works fine.
Asked by lucasw on 2016-04-01 12:13:05 UTC
Comments