Custom message with variable fields

asked 2018-09-07 02:47:59 -0600

VictorLamoine gravatar image

updated 2018-09-07 02:54:37 -0600

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 and is_in_a_grape but the diameter does not make sense.
  • In case type is "melon" then I can fill color and diameter but the is_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?

edit retag flag offensive close merge delete