Custom message with variable fields
I need a custom message but the fields inside may change depending of the content of this message, a simple example would be:
Food.msg
string type
std_msgs/ColorRGBA color
float64 diameter
bool is_in_a_grape
- In case type is "banana" then I can fill
color
andis_in_a_grape
but thediameter
does not make sense. - In case type is "melon" then I can fill
color
anddiameter
but theis_in_a_grape
does not make sense.
I'm looking at some way to implement inheritance (all of these needs to be handled as Food
).
My best bet is implementing everything that is common with standard ROS message fields and using one field containing a YAML string that would implement the rest:
Food.msg
string type
std_msgs/ColorRGBA color
string yaml_properties
yaml_properties
would then hold anything I need depending on the Food
in the message.
Is there a better way?