Annotating data

Studio supports data annotations to optimize its visualizations.

Enums

Since ROS messages do not having built-in support for enums, we've implemented a way for Studio to read annotated message definitions to display enum values in a useful way.

Previously, Studio could only display the value for an enum field if that field's datatype provided its own enum mapping.

For example, let's consider the scenario where the message definition for color_msgs/PrimaryColors is as follows:

uint8 RED=1
uint8 YELLOW=2
uint8 BLUE=3

uint8 data

and the message definition for my_msgs/MySettings is as follows:

color_msgs/PrimaryColors my_color

Studio would correctly interpret my_msgs/MySettings's my_color as an enum of datatype color_msgs/PrimaryColors. In short, if Studio were to receive a my_msgs/MySettings message with my_color: 2, it would correctly display it as my_color: YELLOW.

With Studio's built-in enum support, you can now avoid that extra data field by annotating the message fields that reference it (in this case, my_color). As a result, the color value can be accessed more directly – i.e. mySettingsMsg.my_color vs. mySettingsMsg.my_color.data.

Now, the message definition for color_msgs/PrimaryColors can contain only constants:

uint8 RED=1
uint8 YELLOW=2
uint8 BLUE=3

Since we've removed all fields, it is no longer useful to reference the color_msgs/PrimaryColors datatype for my_color. However, the my_color field can now be converted to a simple uint8 and annotated as follows:

color_msgs/PrimaryColors my_color__foxglove_enum
uint8 my_color

This annotation will not add any bytes to the serialized ROS message, but it will add the necessary information (in this case, the constant values for RED, YELLOW, and BLUE) to the connection header, so that Studio can still output a human-readable value.

The end result is the same – if Studio were to receive a my_msgs/MySettings message with my_color: 2, it would display it as my_color: YELLOW.

Note: Studio can match multiple constants with their corresponding fields. Consider the message definitions below:

number_msgs/Integer:

uint8 ONE=1
uint8 TWO=2

letter_msgs/English:

uint8 A=1
uint8 B=2
uint8 letter

my_msgs/MySettings:

number_msgs/Integer my_integer__foxglove_enum
uint8 my_integer
letter_msgs/English my_letter__foxglove_enum
uint8 my_letter

For my_msgs/MySettings messages, Studio will display my_integer as ONE or TWO, and my_letter as A or B, even though both fields contain 1 or 2 as values.