rosbag2 icon indicating copy to clipboard operation
rosbag2 copied to clipboard

Python typesys msg type causes assertion errors in other modules

Open broughtong opened this issue 1 year ago • 3 comments

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

broughtong avatar Jun 02 '23 23:06 broughtong

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'>

broughtong avatar Jun 03 '23 08:06 broughtong

Can you clarify some things for me?

  1. 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?
  2. Have you used any rosbag2 tools for playing it back / reading it? Such as ros2 bag play or the Python rosbag2_py module It looks like you're using the tool rosbags, which is a separate project that exists over here https://gitlab.com/ternaris/rosbags
  3. Are you successfully running Rolling on Ubuntu Bionic? I wouldn't think the latest sources would even build there, it's definitely not supported.

emersonknapp avatar Jun 07 '23 22:06 emersonknapp

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.

tom-bu avatar Mar 23 '24 00:03 tom-bu

  • Closing as a stale issue since there is no response from the author.

MichaelOrlov avatar May 05 '24 03:05 MichaelOrlov