Ask Your Question
0

publish c structs

asked 2016-03-21 04:10:44 -0500

ElTonno gravatar image

updated 2016-03-19 02:40:55 -0500

gvdhoorn gravatar image

Hey guys,

I'm searching for a way to publish my own c struct. In my code I use a struct like:

struct test {
  int a;
  int b;
  int c;
  float d;
} ;

and I want a message that uses two integers and one "test". Of course I could use a message that uses five integers and one float to solve the problem but this is not a very well solution. I also tried MessagesSerializationAndAdaptingTypes of the roswiki, but either I did something wrong or it does not help with this problem.

If there is already a post with this topic I'm sorry to ask this again, but I was not able to find it.

Best
ElTonno

edit retag flag offensive close merge delete

Comments

I also tried MessagesSerializationAndAdaptingTypes of the roswiki, but either I did something wrong [..]

It would help to know what exactly you tried, in order to avoid other posters suggesting the same things. Please include some example code-snippets showing what you tried (and any errors).

gvdhoorn gravatar image gvdhoorn  ( 2016-03-19 02:41:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-03-21 04:24:54 -0500

ahendrix gravatar image

You always need a message definition to publish a message. This allows non-C++ clients to decode the message.

If you have a specific C/C++ type that you want to publish (struct test), you could define a matching message:

test.msg:

int32 a
int32 b
int32 c
float32 d

And define a message which uses that:

combined.msg

int32 e
int32 f
my_package/test g

You can then define a struct which contains a test:

struct combined_t {
  int e;
  int f;
  struct test g;
}

And then you can define a serializer for combined_t, which either uses the serializer for struct test or does everything inline, and then, finally, you'll be able to publish combined_t onto a topic with the combined.msg type.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-03-18 06:47:44 -0500

Seen: 1,138 times

Last updated: Mar 21 '16