AdvantageKit Lesson

AdvantageKit: The Robot's Black Box Recorder

AdvantageKit is an advanced logging framework that acts like a "black box" flight recorder for our robot. It records nearly every piece of data—motor outputs, sensor inputs, joystick commands, and more—allowing us to replay a match and diagnose complex issues with perfect clarity.

Why We Use AdvantageKit

On our team, we don't guess—we use data. AdvantageKit is the tool that provides this data. It's the key to solving intermittent, match-specific bugs that are impossible to reproduce in the shop. It allows us to make data-driven decisions to improve robot performance and is a fundamental part of our engineering process.

The Three Main Components

1. The Logger

This is the core of the framework. The `Logger` runs on the robot and automatically captures data every 20ms, saving it to a `.wpilog` file. It's incredibly efficient and can record thousands of data points without slowing the robot down.

2. "Logged I/O" Pattern

To make logging effortless, we structure our subsystems using a "Logged I/O" pattern. We create a special inner class or interface (usually called `IO`) that contains all the raw inputs (from sensors) and outputs (to motors). AdvantageKit automatically logs every field in this interface.

public class IntakeSubsystem extends SubsystemBase {
    // This special interface defines everything that will be logged.
    public interface IO {
        @Log
        public default void setVoltage(double volts) {}

        @Log
        public default double getAppliedVoltage() { return 0; }
        
        @Log
        public default boolean getBeamBreakSensorTripped() { return false; }
    }

    private final IO m_io;

    // ... in periodic() ...
    // Now we use the methods from our IO interface
    m_io.setVoltage(targetVoltage);
    boolean hasNote = m_io.getBeamBreakSensorTripped();
}
    

With this structure, the voltage of our intake motor and the state of our sensor are automatically logged on every robot cycle without any extra code in the subsystem itself!

3. AdvantageScope

After a match, we download the `.wpilog` file and open it in AdvantageScope, a desktop application that brings the data to life. It allows us to scrub the timeline of a match, create graphs overlaying any variable, and visualize the robot's movement on the field based on its logged odometry.

Test Your Knowledge

Question: An autonomous routine mysteriously fails, but only during one specific match. What is the most effective way to diagnose this intermittent issue?