Define a custom message type for .msg files

asked 2018-05-30 09:03:38 -0500

traderain gravatar image

updated 2018-05-30 09:26:33 -0500

Hey so my problem is that I need a custom format for msgs which I have no idea how to do with ROS. The problem is that I have a really complex dynamic format and I would basically need a serialize() and deserialize() or something along those lines where I can define how to serialize and deserialize the msg. The main problem is that its changing during runtime and I found no way to do that with ros yet. I have values similar to this I need to send in the message:

message Variant {
    oneof value {
        int64 int_value = 3;
        double double_value = 4;
        bool bool_value = 5;
        string string_value = 6;
    }
}
edit retag flag offensive close merge delete

Comments

Not saying you're wrong, but just so we avoid an xy-problem: can you please describe what you actually are trying to do, instead of what you believe is the solution to your problem? Are you trying to interface with another middleware that has variant support fi?

gvdhoorn gravatar imagegvdhoorn ( 2018-05-30 10:04:17 -0500 )edit

Send protobuff messages between nodes

traderain gravatar imagetraderain ( 2018-05-30 10:06:02 -0500 )edit

I don't really understand: there is no protobuf transport for ROS 1, so that would seem to be impossible.

Can you say anything about the semantics of the messages that you are trying to pub-sub? Perhaps an approach where you transform incoming protobuf msgs into their ROS equivalents ..

gvdhoorn gravatar imagegvdhoorn ( 2018-05-30 10:08:43 -0500 )edit

.. would work here.

Semantics of 'variant' msgs are typically not something I'm too thrilled about anyway, but that is personal.

There has been some discussion of using protobuf with ROS recently, I believe on the ros_comm tracker, perhaps that can be of help.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-30 10:09:37 -0500 )edit

Thanks. Basically I wana just serialize protobuff stuff and send that with ros and deserialize that at the other end.

traderain gravatar imagetraderain ( 2018-05-30 10:32:01 -0500 )edit

So you want to serialise protobuf msgs into bytestrings, send those over using the TCPROS and then deserialise?

This still sounds like an xy-problem to me, but in that case a byte array sounds like what you'd use. Or if you really want to, abuse a std_msgs/String.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-30 10:34:33 -0500 )edit

Yeah but how can I distinguish which message is which if I just send them as byte arrays?

traderain gravatar imagetraderain ( 2018-05-30 10:41:34 -0500 )edit
1

This is all rather nasty anyway, but how about making separate msgs for each of the protobuf msgs that you'd want to pub-sub?

So a ROS MsgA.msg with just a byte array to serialise Protobuf A msgs into, one for B, etc.

gvdhoorn gravatar imagegvdhoorn ( 2018-05-30 11:00:01 -0500 )edit