Skip to main content

Supported Types

Data is stored using string keys where slashes are used to denote subtables (similar to NetworkTables). Like NetworkTables, all logged values are persistent (they will continue to appear on subsequent cycles until updated).

Simple

The following simple data types are currently supported:

  • Single values: boolean, int, long, float, double, String
  • Arrays: boolean[], int[], long[], float[], double[], String[], byte[]
  • 2D Arrays: boolean[][], int[][], long[][], float[][], double[][], String[][], byte[][]

Structured

Many WPILib classes can be serialized to binary data using structs or protobufs. Supported classes include Translation2d, Pose3d, and SwerveModuleState with more coming soon. These classes can be logged as single values, arrays, or 2D arrays just like any simple type, and used as input or output fields.

danger

Protobuf logging can take an extended period (>100ms) the first time that a value with any given type is logged. Subsequent logging calls using an object of the same type will be significantly faster. Protobuf values should always be logged for the first time when the robot is disabled.

This issue is not applicable to struct logging, which is the default for all data types.

Records

Custom record classes can be logged as structs, including support for single values, arrays, and 2D arrays as inputs or outputs. This enables efficient logging of custom complex data types, such as pose observations (check the vision template for examples).

danger

Record logging can take an extended period (>100ms) the first time that a value with any given type is logged. Subsequent logging calls using an object of the same type will be significantly faster. Record values should always be logged for the first time when the robot is disabled.

Note that record fields must use only the following struct-compatible types:

  • Primitives: boolean, short, int, long, float, double
  • Enum values
  • Struct-compatible types (Pose2d, SwerveModuleState, etc.)
  • Record values (i.e. nested records)
warning

Array types are not supported for record fields. We recommend logging using multiple top-level record arrays as needed.

Units

WPILib includes a units library that can be used to simplify unit conversions. Measure objects can be logged and replayed by AdvantageKit. These values will be stored in the log as doubles using the base unit for the measurement type (e.g. distances will always be logged in meters).

Enums

Enum values can be logged and replayed by AdvantageKit. These values will be stored in the log as string values (using the name() method).

Suppliers (Output Only)

Primitive suppliers (BooleanSupplier, IntSupplier, LongSupplier, and DoubleSupplier) can be used in place of their single values for output logging, including annotation logging with @AutoLogOutput. One application of this feature is logging Trigger values, which extend from BooleanSupplier.

Mechanisms (Output Only)

AdvantageKit can log 2D mechanism objects as outputs, which can be viewed using AdvantageScope. If not using @AutoLogOutput, note that the logging call only records the current state of the Mechanism2d and so it must be called periodically.

warning

Mechanism objects must use the LoggedMechanism2d class to be compatible with AdvantageKit. This class is otherwise equivalent to the standard Mechanism2d class. Equivalent LoggedMechanismRoot2d, LoggedMechanismObject2d, and LoggedMechanismLigament2d classes are also provided.

public class Example {
@AutoLogOutput // Auto logged as "Example/Mechanism"
private LoggedMechanism2d mechanism = new LoggedMechanism2d(3, 3);

public void periodic() {
// Alternative approach if not using @AutoLogOutput
// (Must be called periodically)
Logger.recordOutput("Example/Mechanism", mechanism);
}
}