How can I use the topics of a rosbag with custom messages?
I have a rosbag. When played, this rosbag publishes several topics. When I do rosbag info
to the rosbag I got for example
topics:
/some_interface/themessage 115msgs : custom_protocol_msgs/TheMessage
As you can see, the rosbag publishes a topic with a custom type (that was produced by a different program)
I am writing a python scripts and I want to receive these messages and use them. However my workspace and my package is different (not custom_protocol_msgs or some_interface).
How can I subscribe to this topic?
My work: I have done the following:
from mypackage.msg import TheMessage
subs= rospy.Subscriber("/some_interface/themessage", TheMessage,callback)
This does not work because when I do this, rostopic /some_interface/themessage
I got
ERROR: Cannot load message class for [custom_protocol_msgs/TheMessage]. Are your messages built?
If I do
subs= rospy.Subscriber("/mypackage/themessage", TheMessage,callback)
and I do mypackage /some_interface/themessage
I got no new messages.
How can I read these customs messages and operate on them?
You have two options I believe:
rospy.AnyMsg
and look at_connection_header['message_definition']
, similar to how #q230676 does itThe first is a probably more advanced than the second, and would also require actually building a node,
rosbag play
ing the.bag
and then running everything. The first simply opens the bag directly.Depending on what you want to do, opening the
.bag
directly and iterating over the messages may be more efficient anyway.