Dynamically rename topics to better organize and navigate complex datasets
Until now, Foxglove 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.
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 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 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.
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 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 topicsglobalVariables
– Record of global variables set in your Foxglove layoutYou 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" },
];
});
}
language-typescript
Once you've output your desired alias mappings, Foxglove 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.
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 our Discord community or contact us directly.