Is there any way to parse C structures to ROS messages?
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?
Asked by wojtasso on 2018-02-05 04:43:31 UTC
Comments
This is only one way, and it's not parsing, but is related: wiki/roscpp/Overview/MessagesTraits.
Related Q&As: #q229469, #q261468 and #q11828.
Asked by gvdhoorn on 2018-02-05 05:43:08 UTC
Also: can you give a bit more context, so we can avoid a potential xy-problem?
Asked by gvdhoorn on 2018-02-05 05:44:21 UTC
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.
Asked by wojtasso on 2018-02-05 06:12:33 UTC
So the best option would be to generate message from .h file or publish C structure directly without creating .msg files.
Asked by wojtasso on 2018-02-05 06:13:23 UTC
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).Asked by gvdhoorn on 2018-02-05 06:14:37 UTC
Thanks. But this is poor solution since I have to still have .msg files. Do you know anything about generating messages from C structures?
Asked by wojtasso on 2018-02-05 06:29:20 UTC
no. See some of the related questions. There is no standard tool for this, nor do I know of a community contributed one.
Asked by gvdhoorn on 2018-02-05 06:30:51 UTC
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.Asked by gvdhoorn on 2018-02-05 06:32:05 UTC
Thank you. This way seems much more convenient. Do you have any example of this solution?
Asked by wojtasso on 2018-02-05 08:30:31 UTC