rosbag2
rosbag2 copied to clipboard
Python typesys msg type causes assertion errors in other modules
Description
Im trying to read pointclouds from a bag in Rolling, which are stored as sensor_msgs/msg/PointCloud2
.
When I deserialise these, they become of type <class 'rosbags.typesys.types.sensor_msgs__msg__PointCloud2'>
.
This causes assertion errors in for example sensor_msgs_py
which makes a call to assert isinstance(cloud, PointCloud2)
.
This is failing as the message is not of the correct type sensor_msgs/msg/PointCloud2
.
Perhaps there is some way to alter the class, I tried this, but ended up with:
TypeError: __class__ assignment: 'PointCloud2' object layout differs from 'sensor_msgs__msg__PointCloud2'
Also tried to register the original type but I didn't get this working.
Expected Behavior
I can read in a pointcloud from a rosbag and it behaves like a normal pointcloud message in other modules.
Actual Behavior
Assertion error in sensor_msgs_py: assert isinstance(cloud, PointCloud2), \ AssertionError: Cloud is not a sensor_msgs.msg.PointCloud2
To Reproduce
from rosbags.rosbag2 import Reader
from rosbags.serde import deserialize_cdr
from sensor_msgs_py import point_cloud2 as pc
filename = 'somefilename'
with Reader(filename) as reader:
for connection, timestamp, rawdata in reader.messages():
if connection.topic == "/ouster/points": #sensor_msgs/msg/PointCloud2
msg = deserialize_cdr(rawdata, connection.msgtype)
msg = pc.read_points_numpy(msg) #error occurs here
System (please complete the following information)
Ubuntu Bionic, Rolling
Additional context
Similarly, taking a message from a rosbag and simply republishing it:
python: /home/george/common_ws/build/std_msgs/rosidl_generator_py/std_msgs/msg/_header_s.c:57: std_msgs__msg__header__convert_from_py: Assertion strncmp("std_msgs.msg._header.Header", full_classname_dest, 27) == 0' failed. Aborted (core dumped)
Where the header now has a new class type <class 'rosbags.typesys.types.std_msgs__msg__Header'>
Can you clarify some things for me?
- What format is the bag? Is it a ROS 1 bag? Or is it a
.db3
bag from a ROS 2 distro - if so which one? - Have you used any
rosbag2
tools for playing it back / reading it? Such asros2 bag play
or the Pythonrosbag2_py
module It looks like you're using the toolrosbags
, which is a separate project that exists over here https://gitlab.com/ternaris/rosbags - Are you successfully running Rolling on Ubuntu Bionic? I wouldn't think the latest sources would even build there, it's definitely not supported.
You'll need to convert the msg to sensor_msgs.msg.PointCloud2() messge. Your original msg has all of the data fields, so you can instantiate a PointCloud2 with those fields.
- Closing as a stale issue since there is no response from the author.