how to achieve message polymorphism in ROS?
if I want a message or service to handle 2 or more types, what's the best way to do it?
it would be similar to tagged unions in C...
since message fields cannot be null, I was thinking to a scheme like this:
uint8 TYPE_1=1
...
uint8 TYPE_n=n
uint8 type
pkg/Message1[] msg_1
...
pkg/MessageN[] msg_n
with the constraint (which must be enforced by the client application) that at most one array has one element, and all other arrays have zero elements.
it looks quite an ugly workaround.
is there anything better that could be done?
@DamienJadeDuff the motivation is that I need to represent one very generic type, which is a logic term (Term), which is composed by a functional (string) and an array of args of type Atom. Now the problem is that the type Atom can be int, float, string, or even a Term itself.
I wonder if you could further elucidate why you want this to help potential answerers? I should have thought using multiple message types would've had the same effect? Any particular reason you want them published/called over 1 topic? Good luck.
Without knowing the exact criteria, this may be of interest: http://wiki.ros.org/topic_tools/mux