Ask Your Question
0

Can ROS service have union as data type

asked 2018-10-29 05:30:54 -0600

Hi I want to define ROS service taking two arguments.First argument is type and second argument type depends on type. For example if type = 1 then argument2 is CustomMsg1, if type = 2 then argument2 is CustomMsg2. How can we achieve it in ROS service? Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

Can ROS service have union as data type

a plain answer to this would be: no, that's not supported (on purpose I believe).

Other community members will probably suggest a few alternatives / work-arounds.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-29 05:33:26 -0600 )edit

What is purpose behind not supporting this? Can someone else suggest workarounds for this.

sapana_khemkar gravatar imagesapana_khemkar ( 2018-10-29 08:00:43 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-29 08:51:32 -0600

One solution to this in ROS is to include the type variable as well as a variable for each of the CustomMessages, so that only one of those custom messages is used each time. This shouldn't be too bad if you don't have that many different custom message types to choose from.

A more dynamic but even less elegant solution would be to serialise the custom message type and store it in a byte array next to the type variable. This means that there is no limit to the number of message types it can hold, but the code to deal with them becomes much more complicated.

Hope this helps.

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

Stats

Asked: 2018-10-29 05:30:54 -0600

Seen: 50 times

Last updated: Oct 29 '18