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

Can ROS service have union as data type

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

sapana_khemkar gravatar image

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 image gvdhoorn  ( 2018-10-29 05:33:26 -0500 )edit
1

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

sapana_khemkar gravatar image sapana_khemkar  ( 2018-10-29 08:00:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Question Tools

Stats

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

Seen: 723 times

Last updated: Oct 29 '18