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

Rosbag Python API: why do messages from a rosbag have mangled __class__?

asked 2018-02-25 21:17:39 -0600

Rick Armstrong gravatar image

I find that messages loaded from a rosbag via the Python API, have a weird __class__ attribute:

import rosbag
from sensor_msgs.msg import PointCloud2

# Round-trip a PointCloud2 message to a rosbag and back
bag = rosbag.Bag('test.bag', 'w')
try:
    scan = PointCloud2()
    print("__class__should be: \n{}".format(scan.__class__))
    bag.write('scan', msg)
finally:
    bag.close()

bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['scan']):
    print("But it comes out as: \n{}".format(msg.__class__))
bag.close()

The output:

__class__should be: 
<class 'sensor_msgs.msg._PointCloud2.PointCloud2'>
But it comes out as: 
<class 'tmpf1u1_e._sensor_msgs__PointCloud2'>

Is this a bug, or a feature?

ROS Indigo, Ubuntu 14, Python 2.7

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-02-26 01:49:57 -0600

ahendrix gravatar image

updated 2018-02-26 01:50:15 -0600

This is a feature, not a bug.

Instead of using or relying on the local message definitions, which may not match the message definitions stored in the bag file (or may not exist at all!), the python API for rosbag generates class definitions on the fly for each message type stored in the bag file. Unfortunately, these auto-generated classes don't have the same names as the original classes.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-02-25 21:17:39 -0600

Seen: 582 times

Last updated: Feb 26 '18