ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Convert Protobuf Message to ROS Message

asked 2015-02-25 11:37:10 -0500

ReneGaertner gravatar image

Hi,

i just got the issue, that my incoming message (via an external libary) is in Protobuf 2.5 format.

i got those .proto files and let them generate in catkin_make

now i need a gateway function cause already existing nodes need the data as ros message those are generated via the .msg files

the .proto files have the same internal stuff than the .msg file

as example the .proto file:

package Grid
message MsgExample
{
optional float f_A = 10 [default = - 66666.0];
optional float f_B = 20 [default = - 55555.0];
optional int32 i_A = 1 [default = 0];

and my ros message looks like:

#MsgExample

float32 f_A
float32 f_B
int32 i_A

is it possible to directly copy the to each other?

not only one by one, cause in some cases these are really big number of different variables inside of a message.

at the moment i have to do for every message

ros_message::MsgExample myRosMessage;

    Grid::MsgExample myProtoMessage
   // this data i get from a callback (not important for my question where the data coming from)

    myRosMessage.f_A = myProtoMessage .f_a();
    myRosMessage.f_B = myProtoMessage .f_b();
    myRosMessage.i_A = myProtoMessage .i_a();

to publish the ros message later

is need something to directy publish the protobuf message as ros message or to only do it with one operation like

myRosMessage = myProtoMessage

is this possible?

thanks for your help and intrest best regards Rene Gaertner

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-02-25 18:33:09 -0500

tfoote gravatar image

My recommendation would be to write a function which does the conversion for you for each data type. You can do tricks and overload operators but that usually ends up with less readable code.

edit flag offensive delete link more

Comments

Unfortunately if you change the message definitions you will need to update the code. If you want to fully automate that you're starting to look at code generators and ways to define the mappings between the two messages. You will need to maintain a mapping between them, in code is usually easiest

tfoote gravatar image tfoote  ( 2015-02-27 14:49:56 -0500 )edit

i m just going that way, i have a file with the mapping options and search for my topic name to find which one is for which other message, than i choose the 2 header files of the message and fill them to each other. At the moment it s not working but seems to be a good way to do it.

ReneGaertner gravatar image ReneGaertner  ( 2015-03-02 02:53:41 -0500 )edit
1

Hi tfoote, I'm curious if you would change your recommendations now?(Sorry if this is not the right avenue to ask that question)

-jinder

jinder1s gravatar image jinder1s  ( 2018-04-20 10:09:03 -0500 )edit

No, why would you expect a change in the recommendation?

tfoote gravatar image tfoote  ( 2018-04-20 12:04:48 -0500 )edit
0

answered 2015-02-27 05:43:16 -0500

ReneGaertner gravatar image

Hey tfoote,

thanks for the answer, yes of course i can do that, and badly if there is no other option i have to do it that way :)

i just hoped that there is a more generic option, cause the income protobufs and the outgoing rosmessages ll change much during development process and i don t want to change it all the time by hand.

best regards René

edit flag offensive delete link more

Comments

1

Please don't use an answer to comment. Use the comment box.

tfoote gravatar image tfoote  ( 2015-02-27 14:42:03 -0500 )edit

tried, hadn t enough characters :)

ReneGaertner gravatar image ReneGaertner  ( 2015-03-02 02:51:31 -0500 )edit
1

You can also edit your question if you need more space to add clarifications.

tfoote gravatar image tfoote  ( 2015-03-02 03:15:12 -0500 )edit

Question Tools

4 followers

Stats

Asked: 2015-02-25 11:37:10 -0500

Seen: 3,469 times

Last updated: Feb 27 '15