Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.
This repository was archived by the owner on May 31, 2025. It is now read-only.

point_cloud2 read_message returns 2 values when reading field #169

Closed
@sebaleme

Description

@sebaleme

Hello,

I think I found a bug in the file point_cloud2.py

I wrote a python ros node for reading a bag with a pointcloud2 format (and 4 fields, x,y,z,intensity). When I read the 3 first fields, it works fine, but when I read "intensity", it returns 2 values, "y" and "intensity". After some research, I found out that the issue occurs in _get_struct_fmt(), which generates the read mask for the Struct.unpack function.

In the line:
for field in (f for f in sorted(fields, key=lambda f: f.offset) if field_names is None or f.name in field_names):
The for loop occurs twice in the case of intensity, probably because when doing if f.name in field_names , the interpreter is able to find a "y" in the string "intensity". Now, the real question is, why does it parse character wise is the key. Either this is a bug happening for all bags, or somehow the input parameter fields doesn t come with the right type. I would lean towards the first hypothesis, since the resulting field variable is interpreted as a structure, from where later the members name or offset are extracted.

In the ZIP, you can see 4 tests I did:

  • Bag Unchanged ==> field intensity is named intensity
  • Bag Changed ==> field intensity is named intensit
  • python Unchanged ==> dictionaries fields_PI6 and fields_PI6_invers are using intensity
  • python Changed ==> dictionaries fields_PI6 and fields_PI6_invers are using intensit

Results:
BagU PythonU ==> read_message returns 2 values for intensity
BagU PythonC ==> read_message returns 0 values for intensity
BagC PythonU ==> read_message returns 2 values for intensity
BagC PythonC ==> read_message returns 1 value for intensity
pc2_tests.zip

The fact that looking for intensit when the field is named intensity doesn t work (0 values) shows that in this case, the field_name is not considered as a charater list, but as a string. But why then the parsing intensity for the character y? Maybe this is the result of having python not strong typed?

Configuration:

  • Ubuntu 18.04
  • Ros Melodic
  • Python 2.7

I had some difficulties to understand the file hierarchy. On my machine, sensor_message is installed directly under:
/opt/ros/melodic/lib/python2.7/dist-packages/sensor_msgs
And not under common_msgs as here in this repo. Maybe you reorganized the files? And also, there is no file provided or any XML giving me the package version.

Sebastien

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions