Contenu principal

Visualize Custom Messages from ROS or ROS 2 Bag Files

The ROS Data Analyzer app enables you to visualize custom ROS and ROS 2 messages by converting them into supported standard message types using the Adapter Manager. Adapters specify how the app converts data from a custom message into a format that supported visualizers can display.

Note

To visualize custom messages, MATLAB® must recognize the message definitions. If the messages are not already registered, generate the message package using the rosgenmsg function for ROS or ros2genmsg function for ROS 2. You can verify that MATLAB recognizes the custom message types by listing them using rosmsg list or ros2 msg list.

Supported Message Type Conversions for Visualization

The ROS Data Analyzer app visualizes custom messages by converting them into supported standard message types. You can create adapters only for custom messages whose data can be meaningfully mapped to a supported standard message type that has an associated visualizer. Typically, these are custom messages that contain image-based or spatial data suitable for visualization.

Target Standard Message TypeSupported Visualizer

sensor_msgs/Image

sensor_msgs/CompressedImage

Image Viewer
sensor_msgs/PointCloud2

Point Cloud Viewer

3D Viewer

sensor_msgs/LaserScan

Laser Scan Viewer

3D Viewer

nav_msgs/OdometryOdometry Viewer

sensor_msgs/NavSatFix

gps_common/GPSFix

Map Viewer

visualization_msgs/Marker

visualization_msgs/MarkerArray

Marker Viewer

3D Viewer

Tip

Adapters can also modify or transform standard message data before visualization. For example, you can apply the conversion logic of an active adapter to image data before rendering it in the Image viewer.

When to Use Message Adapters

Use message adapters to convert, modify, or transform message data at visualization, without changing the contents of the input ROS or ROS 2 bag file.

Adapters allow you to apply restructuring logic or processing algorithms, such as field remapping, filtering, or data transformation, so that you can visualize data using the supported visualizers in the app. You can update adapter logic and immediately revisualize the data, which makes adapters useful for iterative analysis and experimentation.

The following examples illustrate how adapters support different visualization workflows.

 Convert Custom Foxglove Image Messages for Visualization

 Visualize Custom Point Cloud Data Using Predefined Adapter

 Invert RGB Image Data for Visualization

Specify Message Adapter Store Location

From the Message Adapters tab in the app toolstrip, click Create to specify a path to store adapter files if you are creating or working with adapters for the first time. The app saves this folder as a preference and reuses it in future sessions.

After you select the adapter store location, the app opens the Adapter Creation Utility dialog box to generate the adapter.

You can also create adapters without opening the bag file containing the custom messages.

Create message adapter to visualize custom message in ROS Data Analyzer app

Define Message Conversion and Generate Adapter

In the Adapter Creation Utility dialog box:

  1. Select the ROS Version based on whether you are working with a ROS bag file or ROS 2 bag file.

  2. Select the From Message Type to specify the custom message type in use.

  3. Select the To Message Type to specify the supported standard message type for conversion.

  4. Enter a name for the adapter.

  5. Click Generate Adapter to generate the MATLAB plugin file (.m), that opens in the MATLAB Editor. Edit this file to implement the conversion logic that maps your custom message fields to the target visualization message type.

The Adapter Manager updates automatically as we remove or edit an existing adapter.

Manage Adapters Using Adapter Manager

From the Message Adapters tab, click Manage to open Adapter Manager. The Adapter Manager displays all the registered message adapters in a table. For each adapter, the table shows the source message type, the target message type after conversion, the ROS version, and the adapter name.

Adapter Manager interface in ROS Data Analyzer app

Use the Adapter Manager to:

  • Create new adapters in the adapter store.

  • Edit adapters to update conversion logic in the associated MATLAB plugin file (.m).

  • Remove selected adapters from the list.

  • Export selected adapters for sharing by packing them in a ZIP file.

  • Import adapters from ZIP files.

  • Filter adapters by name or message type using the search bar.

  • Change the adapter store location using the folder icon next to the Adapter Store option that lists the current path to store adapters.

The Adapter Manager updates automatically when you remove or edit an existing adapter.

Visualize Custom Messages

After you register an adapter, the app adds the custom message types to the Topic List.

Open a supported visualizer and specify an adapter in the Active Adapter to apply the appropriate message conversion. After you apply the adapter, select the custom message from the Select Data Source drop-down list to visualize the data.

See Also

Topics