foxglove / ws-protocol

Foxglove Studio WebSocket protocol specification and libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example of "foxglove.PointCloud"?

felixf4xu opened this issue · comments

Hi,

I'm trying to write some python code to in examples.protobuf_server.py

To show my data in the 3D pane, I think I need to create a foxglove.PointCloud message, but I'm stuck here.

my python code to create the message is like this:

empty_pose = Pose_pb2.Pose(
            position=Vector3_pb2.Vector3(x=0,y=0,z=0), orientation=Quaternion_pb2.Quaternion(x=0,y=0,z=0,w=1)
        )
point_cloud = PointCloud_pb2.PointCloud(
                timestamp=timestamp,
                frame_id="point_cloud",
                pose=empty_pose)

then I don't know how to create the other 3 protobuf fields:

  // Number of bytes between points in the `data`
  fixed32 point_stride = 4;

  // Fields in the `data`
  repeated foxglove.PackedElementField fields = 5;

  // Point data, interpreted using `fields`
  bytes data = 6;

expecailly for foxglove.PackedElementField, it's very complicated.

Any sample code to show how to create a PackedElementField or the whole PointCloud message? otherwise I'm afraid that I need to spend several days to try and err and try again.

@james-rms sending your way. This isn't mcap specific but the way messages and schemas are serialized is very similar. Maybe for now we can have the docs for ws_protocol examples reference the mcap docs or add a foxglove.PointCloud protobuf example to the examples in this repo.

are you referring to https://mcap.dev/docs/python/jsonschema_tutorial.html#creating-a-foxglove-pointcloud ?

It's useful! It's not in protobuf and I'm lucky that it's in python! I have managed to create my own PointCloud in protobuf.

PS:
it's strange that in protobuf we still keep the concept of "PackedElement". For my understanding, protobuf will pack the data automatically (that's why we are using protobuf, I guess), so it's more natural to just use a plain struct of 4 float32 (as in the sample doc) instead of packing the data manually (I'm referring to the code of struct.pack("<ffff", x, y, z, intensity)).

I see the conversion of foxglove protobuf to ros message from foxglove-studio source code, I guess that's the historical reason but I don't think it's necessary to do a struct to struct conversion, I really hope PackedElement can be remove from protobuf
:-)