Is there any way to parse C structures to ROS messages?

asked 2018-02-05 03:43:31 -0600

wojtasso gravatar image

I'm looking for a way to convert a C structure to a ROS message. Does has any ideas how to do it? Does ROS provide some tools to do that? Or should I write parser on my own?

edit retag flag offensive close merge delete

Comments

1

This is only one way, and it's not parsing, but is related: wiki/roscpp/Overview/MessagesTraits.

Related Q&As: #q229469, #q261468 and #q11828.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-05 04:43:08 -0600 )edit
1

Also: can you give a bit more context, so we can avoid a potential xy-problem?

gvdhoorn gravatar imagegvdhoorn ( 2018-02-05 04:44:21 -0600 )edit

By now I've defined a structure example in file example.h and message in example.msg which have the same fields. I want to avoid situation when I will have to introduce small changes into my C structures and then I will have to make changes in .msg file. I want to make changes only once.

wojtasso gravatar imagewojtasso ( 2018-02-05 05:12:33 -0600 )edit

So the best option would be to generate message from .h file or publish C structure directly without creating .msg files.

wojtasso gravatar imagewojtasso ( 2018-02-05 05:13:23 -0600 )edit
1

or publish C structure directly without creating .msg files.

that is possible (see the MessageTraits page), but know that for any node to be able to receive your msgs they will need a .msg definition (unless you're shadowing one of the ROS standard msgs).

gvdhoorn gravatar imagegvdhoorn ( 2018-02-05 05:14:37 -0600 )edit

Thanks. But this is poor solution since I have to still have .msg files. Do you know anything about generating messages from C structures?

wojtasso gravatar imagewojtasso ( 2018-02-05 05:29:20 -0600 )edit
1

Do you know anything about generating messages from C structures?

no. See some of the related questions. There is no standard tool for this, nor do I know of a community contributed one.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-05 05:30:51 -0600 )edit
2

But I would suggest to do it the other way around: generate C structures from ROS .msg files. That would seem to result in the same thing (.msg and header in sync) and is already done by rosserial fi.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-05 05:32:05 -0600 )edit