# Using Similarity Search to Classify Events in Drone Racing Logs

- **URL**: https://www.roboto.ai/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/
- **Date**: 2024-11-14
- **Author**: Yves Albers, Co-founder & CTO
- **Category**: Product
- **Tags**: similarity-search, drone-racing, imu, events
- **Read time**: 15 min
- **Status**: Historical post. Describes Roboto as of November 14, 2024; the current product is at https://www.roboto.ai/platform.md

> Learn how to use the Roboto SDK to quickly find patterns in your log data!

---

As an engineer analyzing robot logs, you're likely asking questions such as:

- Have we encountered this type of issue before?
- How often does this event occur?
- Can we identify similar events in past logs?
- Can we set up alerts to catch this issue if it happens again?

Answering these questions is essential for diagnosing system behaviors, anticipating potential failures, and continuously improving your robot's performance.

However, answering them presents two key challenges:

1. **Data volume and format**: Robots generate huge amounts of data--sometimes tens or hundreds of gigabytes per mission--stored in specialized formats like ROS bags or MCAP files. Parsing these logs to extract relevant segments is typically manual and labor-intensive. This gets even worse when dealing with log data from fleets of robots.
1. **Data diversity and pattern complexity:** Robot logs are multimodal, containing a wide variety of sensor data. While simple issues can be flagged by looking for discrete values or conditions (e.g., vehicle_gps_lost = True), more complex events--such as repeated instability in drone flights or subtle gripper failures--demand more advanced methods.

At Roboto, our goal is to address challenge (1) by making it easier to retrieve task-specific data at scale, allowing you to manage and analyze large datasets more effectively. In parallel, we're expanding our tooling to help address challenge (2) as well--building features that identify and classify complex patterns in multimodal data.

In this post, we'll walk through an example where we use our [Python SDK](https://www.roboto.ai/docs/learn/sdk) to retrieve IMU data from drone racing logs and then leverage _signal similarity search_ to identify and classify patterns.

## **Scenario**

- _As a systems engineer, you're tasked with investigating hard landings in your drone's latest flight campaign. To do this, you need to generate landing videos from the drone's forward-facing camera and extract the corresponding IMU signals. These will then be reviewed by the controls team to assess performance._

While this sounds straightforward, the challenge is that your ROS bags contain raw IMU and image data--there are no annotations or flags indicating hard landing events. As a result, you'd typically need to:

1. Download dozens of raw flight logs, each several gigabytes in size.
2. Manually review flights to identify hard landings and record the timestamps.
3. Write custom scripts to extract images and IMU signals, then compile them into videos.
4. Upload these videos to a storage system for shared access.

This would be painstaking, and could take several days with a large number of logs.

Instead of manually reviewing every flight, we're going to use Roboto to find and retrieve hard landings automatically:

1. **Single Annotation**: Use Roboto's visualizer to annotate an exemplary hard landing event.
2. **Data Retrieval**: Use Roboto's SDK to efficiently retrieve IMU signals from flights to search.
3. **Similarity Search**: Use similarity search to identify other hard landings in the IMU signals.
4. **Artifact Generation**: Generate clips of the relevant landing sequences.

This approach will streamline the entire process and save considerable time.

## **Prerequisites**

For this example, we ingested 25 drone flights as ROS bags from [UZH-FPV Drone Racing](https://fpv.ifi.uzh.ch/). The flights cover various drone racing scenes, both indoor and outdoor, using forward and downward-facing cameras.

To reproduce the steps below: [create](https://app.roboto.ai/signup) your own account, then [install](https://github.com/roboto-ai/roboto-python-sdk/?tab=readme-ov-file#install-python-sdk) the Python SDK and [configure](https://www.roboto.ai/docs/getting-started/programmatic-access) a personal access token. You can see the flight logs in the public [collection](https://app.roboto.ai/collections/cl_pxlseuhim8ym) on Roboto and run the [notebook](https://github.com/roboto-ai/roboto-python-sdk/blob/main/examples/similarity-search.ipynb) by following the [README](https://github.com/roboto-ai/roboto-python-sdk/tree/main/examples) in the repository.

## **Single Annotation**

Our first task is to use Roboto's visualizer to annotate an exemplary hard landing event. This will serve as a reference to find other hard landings afterwards.

1. Open a dataset in the visualizer. Create panels for the image topics, and plot the \[x, y, z\] values from /snappy_imu/linear_acceleration. Refer to our guide: [**Visualizing ROS Data**](https://www.roboto.ai/docs/user-guides/working-with-ros-logs/visualize-ros)
2. Identify the drone's landing by looking for spikes in the linear acceleration signals, indicating contact with the ground.
3. Create an event around the landing, setting the Event Scope to "All Topics in this Panel." Refer to our guide: [**Create Events on Data**](https://www.roboto.ai/docs/user-guides/create-events-on-data)

![Creating an event in the Roboto visualizer. Data is from UZH-FPV Drone Racing.](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-107-6716cb38d253f69345d361ca_6716be841624d43c1c084943_.gif)

## **Data Retrieval**

We can use the Roboto SDK to access the public log collection and set up a query client.

Next, we call [roboto_search.find_topics](https://www.roboto.ai/docs/reference/python-sdk/roboto/roboto_search#roboto.roboto_search.RobotoSearch.find_topics) to retrieve all topics named /snappy_imu using [RoboQL](https://www.roboto.ai/docs/roboql/overview) syntax. This search can be further refined by adding specific metadata, such as drone software version, or applying tags like "outdoor" to narrow the results.

```python
import roboto

query_client = roboto.query.QueryClient(
    owner_org_id="og_najtcyyee2qa"  # Drone Racing (public)
)
roboto_search = roboto.RobotoSearch(query_client)

topics_to_search = roboto_search.find_topics(
    "topic.name = '/snappy_imu'"
)
```

## **Similarity Search**

Now that we've defined our search space (the /snappy_imu topics we just retrieved), we can initiate our similarity search using the event we created earlier.

1. **Get the Event:** Get the event using [roboto.Event.from_id](https://www.roboto.ai/docs/reference/python-sdk/roboto/domain/events#roboto.domain.events.Event.from_id). The event is pointing to the specific IMU signals that we annotated.
2. **Extract Data from the Event:** Extract the linear_acceleration and angular_velocity data from the IMU event into a pandas dataframe; this will serve as the query signal.
3. **Find Similar Signals:** Run the similarity search using the query signal with [roboto.analytics.find_similar_signals](https://www.roboto.ai/docs/reference/python-sdk/roboto/analytics#roboto.analytics.find_similar_signals).

```python
import roboto.analytics
event = roboto.Event.from_id("ev_6funfjngoznn17x3")
query_signal = event.get_data_as_df(
    message_paths_include=["linear_acceleration", "angular_velocity"]
)
matches = roboto.analytics.find_similar_signals(
    query_signal,
    topics_to_search,
    max_matches_per_topic=1,
    normalize=True)
```

With the code above, finding similar patterns in other flights becomes
straightforward. We're able to precisely retrieve and search the IMU data,
avoiding the need to download and process entire logs.

## **Artifact Generation**

Finally, we can run some utility code to generate artifacts and visualize the results.

```python
from notebook_utils.match_results import print_match_results
print_match_results(
    matches[:5],
    image_topic="/snappy_cam/stereo_l",
)
```

**Hard Landings**

The first column shows the distance scores of the closest matches. The second column shows the plots of the matched IMU subsequences, and the third column shows the corresponding image sequences for each match. The first row, with a distance score of zero, represents the query signal. As expected, the top matches correspond to hard landing sequences in other flights.

    Distance
    Match
    Camera
    Link

    0.0
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-108-landing_0_plot.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-109-landing_0_gif.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_na8g8v4fp89gogtjvhj6)
    

    
        197.692
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-110-landing_1_plot.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-111-landing_1_gif.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_vyjnylri1v407kfv1ng1)
    

    
        200.808
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-112-landing_2_plot.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-113-landing_2_gif.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_zavcwv1iqnh4ic69jeam)
    

    
        202.806
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-114-landing_3_plot.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-115-landing_3_gif.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_z8lj0a8f110wrv0h9oxm)
    

    
        203.873
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-116-landing_4_plot.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-117-landing_4_gif.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_8lepzuglmspy7rcg2df3)
    



**How does find_similar_signals work?**

The [find_similar_signals](https://www.roboto.ai/docs/reference/python-sdk/roboto/analytics#roboto.analytics.find_similar_signals) search is powered by [Mueen's Algorithm for Similarity Search (MASS)](https://www.cs.unm.edu/~mueen/FastestSimilaritySearch.html), which uses Euclidean distance profiles to identify matching subsequences in time-series data. We apply this method across multiple signals, then combine the results to find the closest match. This approach has also proven effective for detecting other types of events. Let's explore a few more cases.

**Calibration Sequences**

We looked for IMU patterns which correspond to the calibration sequence of the downward-facing camera before takeoff. The results look great!

    Distance
    Match
    Camera
    Link

    0.0
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-118-0_plot_calib.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-119-0_calib_gif_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_na8g8v4fp89gogtjvhj6)
    

    
        344.632
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-120-1_plot_calib.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-121-1_calib_gif_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_vyjnylri1v407kfv1ng1)
    

    
        350.469
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-122-2_plot_calib.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-123-2_calib_gif_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_zavcwv1iqnh4ic69jeam)
    

    
        375.138
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-124-3_plot_calib.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-125-3_calib_gif_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_z8lj0a8f110wrv0h9oxm)
    

    
        432.65
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-126-4_plot_calib.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-127-4_calib_gif_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_8lepzuglmspy7rcg2df3)
    



**Left Turns**

Finally, we tried to find similarly aggressive left turns. The results qualitatively make sense.

Note that we only used _angular_velocity_ to find turns, as it directly captures rotational motion. Dropping _linear_acceleration_ makes sense because turns are primarily characterized by changes in angular velocity, while linear acceleration data may introduce noise unrelated to the rotational dynamics of the turn. It's generally a good idea to experiment with including different signals in the similarity search to better capture events.

    Distance
    Match
    Camera
    Link

    0.0
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-128-671551798cd33c5e6e23e1f7_0_plot_turn.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-129-0_turn_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_na8g8v4fp89gogtjvhj6)
    

    
        151.711
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-130-67155179876d15f5abbfa312_1_plot_turn.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-131-1_turn_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_vyjnylri1v407kfv1ng1)
    

    
        155.657
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-132-67155179b81c8725ef345f5a_2_plot_turn.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-133-2_turn_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_zavcwv1iqnh4ic69jeam)
    

    
        156.782
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-134-67155179822287f94111ba00_3_plot_turn.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-135-3_turn_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_z8lj0a8f110wrv0h9oxm)
    

    
        157.566
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-136-67155179b3d3434dc37641f8_4_plot_turn.png)
    
    
        ![](https://www.roboto.ai/uploads/blog/using-similarity-search-to-classify-events-in-drone-racing-logs/img-137-4_turn_reduced.gif)
    
    
        [
            View in Roboto
        ](https://app.roboto.ai/files/fl_8lepzuglmspy7rcg2df3)
    

**Limitations**

The approach using Euclidean distance profiles may struggle in a few cases. First, noise or signal distortions can cause the algorithm to misinterpret small variations as dissimilar, leading to missed matches. Second, temporal misalignment can prevent the algorithm from recognizing similar events that are slightly shifted in time, a problem better handled by methods like [Dynamic Time Warping (DTW)](https://en.wikipedia.org/wiki/Dynamic_time_warping). Additionally, events with different semantic meanings--such as a takeoff versus manually lifting the drone - can have similar IMU signatures, potentially leading to false positives.

**Conclusion**

In this post, we showed how Roboto's SDK makes it easy to extract slices of your robotics data so you can focus on more advanced tasks, like finding events using similarity search.

By simplifying the retrieval process, we've demonstrated how you can streamline workflows that usually take hours into minutes. We're excited to continue adding new techniques for pattern matching in robotics data, so stay tuned for more features and examples soon. In the meantime, give it a try with your own data and let us know what you find!

_This demo and the accompanying open source notebook use data from_ [_UZH-FPV Drone Racing_](https://fpv.ifi.uzh.ch/)_, published by the Robotics and Perception Group (RPG) at the University of Zurich._

---
Roboto is the analytics engine for robotics and Physical AI. Learn more at https://www.roboto.ai or book a demo at https://www.roboto.ai/request-demo/.