Loading...
Loading...
AdvantageKit logging framework best practices for FRC Java robots (2026 / AKit 4.x). Use when implementing or reviewing AdvantageKit IO layers, Logger usage, replay-compatible subsystem design, signal logging, output logging, or deterministic simulation. Triggers on: AdvantageKit, Logger.recordOutput, Logger.processInputs, LoggedRobot, IO interfaces, IOInputs, AutoLog annotation, replay, log-replay, non-deterministic, or any AdvantageKit-related robot code task.
npx skill4agent add yeti-robotics/robot-skills advantagekitDocumentation sourced from docs.advantagekit.org. AdvantageKit is developed by Littleton Robotics (FRC 6328).
updateInputs()@AutoLogprocessInputsperiodic()@AutoLog<ClassName>AutoLogged// DriveIO.java
public interface DriveIO {
@AutoLog
class DriveIOInputs {
public double leftPositionRad = 0.0;
public double rightPositionRad = 0.0;
public double leftVelocityRadPerSec = 0.0;
public double rightVelocityRadPerSec = 0.0;
public double[] appliedVolts = new double[] {};
}
default void updateInputs(DriveIOInputs inputs) {}
default void setVoltage(double leftVolts, double rightVolts) {}
}
// Drive.java
public class Drive extends SubsystemBase {
private final DriveIO io;
private final DriveIOInputsAutoLogged inputs = new DriveIOInputsAutoLogged();
public Drive(DriveIO io) {
this.io = io;
}
@Override
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Drive", inputs);
// All logic uses inputs.leftPositionRad, etc. — never calls hardware directly
}
public void setVoltage(double left, double right) {
io.setVoltage(left, right);
}
}DriveIOSparkMaxDriveIOSimDriveIORobotContainerRobot.isReal()isSimulation()Logger.start()RobotContainerpublic class Robot extends LoggedRobot {
private RobotContainer robotContainer;
@Override
public void robotInit() {
// Configure data receivers BEFORE start()
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
Logger.start(); // ← must be first
robotContainer = new RobotContainer(); // ← safe to create subsystems now
}
}| Rule | Reason |
|---|---|
| Hardware access only inside IO implementations | Ensures all inputs are logged and replayable |
Use | FPGA timestamps are non-deterministic |
| Call logging APIs from main thread only | |
| Don't read subsystem inputs in constructors | Inputs are stale until first |
| Test replay regularly during development | Catches non-determinism early |
Logger.recordOutput("Drive/LeftVelocityError", setpoint - inputs.leftVelocityRadPerSec);
Logger.recordOutput("Odometry/Robot", poseEstimator.getEstimatedPosition());
Logger.recordOutput("Mechanism", mechanism2d);@AutoLogAutoLoggedMeasureLoggedDashboardChooserLoggedNetworkNumber