Introducing Topic Alias Extensions in Foxglove Studio

Dynamically rename topics to better organize and navigate complex datasets
Esther WeonEsther Weon ·
Miles EganMiles Egan ·
4 min read
Published
Introducing Topic Alias Extensions in Foxglove Studio

Until now, Foxglove Studio has provided users with two types of extensions – custom panels and message converters – to better visualize their data. To continue empowering users, we now provide users with a third extension type. With topic alias extensions, you can rename topics in your data source to better manage, navigate, and analyze complex datasets.

When to use topic aliases

With topic alias extensions, you can create shorter, more intuitive aliases for complex or lengthy topic names. You can also reorganize your data into categories that better reflect the analysis you wish to perform.

For example, your robotics team may have namespaced your topics with a particular sensor (e.g. /CAM_FRONT/image_rect_compressed, /CAM_BACK/image_rect_compressed, etc.). Instead of creating nearly identical layouts to visualize data from each camera, you may want to create a generic Foxglove Studio layout that can visualize any of these different cameras’ topics, and then simply set a global variable (e.g. $camera) to easily switch between them.

In this case, you may create a topic alias extension that takes in all sensor topics (e.g. /CAM_FRONT/image_rect_compressed, /CAM_BACK/image_rect_compressed, etc.), sees what the $camera global variable points to, and then uses that variable value to determine which topic is renamed to /selected_camera_image.

From there, you can build a Foxglove Studio layout with panels that just reference /selected_camera_image to display the desired sensor data. By simply editing the $camera value (e.g. from “FRONT” to “BACK”), you can easily switch between cameras without making any other changes to your layout.

Getting started

Topic alias extensions allow you to create alternative names for your existing data source topics. These aliases behave exactly like the original data source topics – in short, Foxglove Studio panels can subscribe to both the original and aliased topics.

To create a topic alias extension, you must first register it in the Foxglove extension template’s activate” function. Foxglove provides a registerTopicAliases` function that takes in two arguments:

  • topics – List of data source’s original topics
  • globalVariables – Record of global variables set in your Foxglove Studio layout

You can then populate the function with logic that returns a list of aliased topics based on your provided mappings – in this case, we reference the $camera variable value to determine which original data source topic we alias to /selected_camera_image:

import { ExtensionContext } from "@foxglove/extension";

export function activate(extensionContext: ExtensionContext): void {
  // Register a topic alias function that takes the current list of datasource topics and
  // global variables and outputs a list of topic aliases.
  extensionContext.registerTopicAliases((args) => {
    const { globalVariables } = args;
    // Output a list of aliased topics, in this case influenced by the current value of
    // the global variable `camera`.
    const camera = globalVariables["camera"] ?? "FRONT";
    return [
      { sourceTopicName: `/CAM_${camera}/image_rect_compressed`, name: `/selected_camera_image` },
      { sourceTopicName: "/imu", name: "/aliased_imu" },
      { sourceTopicName: "/odom", name: "/aliased_odom" },
    ];
  });
}

Once you've output your desired alias mappings, Foxglove Studio takes care of the rest. All aliases behave just like the original topics – panels and layouts can seamlessly transition to subscribing to them in addition to the original topics. The aliasing function will also be rerun automatically whenever the data source topics or global variables change, ensuring that your aliases remain accurate and up-to-date.

Trying it out

Whether you're working with large-scale datasets or simply seeking a more efficient way to wade through your topics, topic aliases can help you focus on the aspects of your data most relevant to you.

We hope topic alias extensions prove to be a valuable addition to your robotics team’s data analysis toolkit. If you have any questions or feedback, reach out to us in the Foxglove Slack community or contact us directly.


Read more:

Spotlight: Using Web-Based Technologies to Make Robotics Accessible to All
interview
visualization
Spotlight: Using Web-Based Technologies to Make Robotics Accessible to All

Robotics researcher Ruffin White talks about lowering the barrier to entry in robotics education and research

Ruffin WhiteRuffin WhiteRuffin White
Esther WeonEsther WeonEsther Weon
10 min read
Introducing Custom Properties in Foxglove Data Platform
article
data management
Introducing Custom Properties in Foxglove Data Platform

Add metadata to your team’s devices for discoverability and search

Esther WeonEsther WeonEsther Weon
3 min read

Get blog posts sent directly to your inbox.

Ready to try Foxglove?

Get started for free