AdvantageKit 2024: Log Replay, Again!

AdvantageKit is a log replay and simulation framework developed by Team 6328. Its core objective is to enable all code logic to be replayed in simulation based on a log file, so you can debug complex issues, log new fields that were never recorded in the first place, and even retune compatible systems without needing a real robot. For more details, check out the What is AdvantageKit? page or my conference from the 2023 Championship:

AdvantageKit has grown significantly since its introduction in 2021 and is now used by dozens of teams on the world stage. AdvantageKit split from its sister project AdvantageScope for the 2023 season, so AdvantageKit is not required to use AdvantageScope. AdvantageScope is included in the WPILib installer for 2024, but AdvantageKit remains a fully independent project which will not be integrated with WPILib.

What’s New?

AdvantageKit now supports WPILib 2024.1.1-beta-2! Remember that AdvantageKit should only be used with the WPILib version specified in each set of release notes. For a full 2024 changelog, check the GitHub release.

Structured Data Logging

AdvantageKit now supports struct & protobuf encoding for supported objects like Pose3d, Trajectory, and SwerveModuleState. These objects can be logged as outputs or inputs, and many can also be stored as arrays. Expect compatibility to improve over time as more classes are supported natively by WPILib.

The syntax for logging a supported object as an output is the same as previous versions of AdvantageKit (see the example below). However, these types are now identifiable in AdvantageScope; you can examine individual components with human-friendly names, and it’s impossible to mix up 2D and 3D objects. Support for structured data was added in AdvantageScope 2024 beta 3.

Logger.recordOutput(“MyPose”, new Pose2d());
Logger.recordOutput(“MyPoses”, new Pose2d(), new Pose2d());

These objects can also be used as input types. Need to log a robot pose from a vision subsystem or a swerve module rotation from your drive? You can now use objects like Pose3d or Rotation2d with AutoLog, including arrays:

@AutoLog
public class MyInputs {
    public Rotation2d myRotation = new Rotation2d();
    public Pose3d[] myPoses = new Pose3d[] {};
}

Internally, AdvantageKit supports both simple structs (with WPILib’s encoding system) and protobufs. Structs are more efficient but less flexible for complex data types. Many classes in WPILib support both systems, but the default logging calls in AdvantageKit will select the most efficient encoding automatically.

Swerve Template Project

In addition to the skeleton and differential drive templates, AdvantageKit now includes a swerve drive template! This template supports odometry, physics simulation, simple field-oriented drive, and autos with PathPlanner. As swerve becomes more common, we hope this serves as a useful resource and starting point for teams looking to adopt AdvantageKit.

You can download the swerve template project as a zip file from the latest release. All of the example projects have also been updated to use Phoenix 6 for the CTRE IO implementations.

Simplified Syntax

Several classes including Logger now have static interfaces rather than using singletons. This makes all of your logging calls more concise and readable:

Logger.recordOutput(“MyField”, 3.14); // 2024 interface
Logger.getInstance().recordOutput(“MyField”, 3.14); // 2023 interface

Calls to getInstance() are still supported for backwards compatibility, but are marked with a deprecation warning.

What’s Next?

AdvantageKit 2024 beta 1 is now released! You can see the full changelog on the GitHub releases page. Updated documentation is available here. To get started, check out the installation guide. We would welcome feedback and bug reports on this thread or the issues page.

We’re grateful to everyone who has adopted AdvantageKit and provided valuable feedback over the past two years. We hope you enjoy running it in your 2024 robot projects at last! :partying_face:

53 Likes

Looking forward to digging in and developing a full season with AdvantageKit this year!

Might be obvious to but was a tripping point for me in setting up from scratch again but if you are using AdvantageScope and AdvantageKit with the new protobufs and/or structs make sure you have selected your live source to be NetworkTables (Advantage Kit) in you preferences!

Otherwise was a very smooth port from our 2023 codebase.

1 Like

You shouldn’t actually need to select AdvantageKit mode for the structured data to work properly, but there are some bugs in AdvantageScope that I’m still tracking down which can cause the data to not be decoded under some circumstances. Changing the live source and/or live mode is often a decent workaround (in general I would suggest using the AdvantageKit NT mode with AdvantageKit anyway). Those workarounds shouldn’t be necessary in the future though.

1 Like

AdvantageKit Swerve Template PSA

For anyone trying out AdvantageKit’s new swerve template on the Talon FX, note that there is an issue which results in incorrect inversions for the drive and turn motors. The necessary fix is here, and the swerve template attached to the beta release on GitHub has also been updated. The Spark Max implementation is not affected.

While the Spark Max implementation was thoroughly tested before release, I only recently had the chance to properly test out the swerve template on a Talon FX swerve. If you encounter issues with the swerve template (or any other aspect of the AdvantageKit beta), we welcome your feedback on the GitHub issues page.

3 Likes

Wanted to ask, are you looking into distributing AdvantageKit differently, like via JitPack or something? That would make importing it much nicer in the long term.

This is definitely on our backlog. We did the prerequisite work to distribute on Maven central, we just haven’t gotten around to setting the rest up. This seems to be an issue multiple people have raised, so I’ll look at trying to get this done sooner.

We’re also planning on shipping a zipped vendordep release that allows users to locally install the libs for those that can’t access GitHub Packages due to school firewall restrictions. I’ll make a post about that when that’s ready.

3 Likes

This is the feature I’ve been waiting for, to make advantage kit immediately beneficial with the simplest of integrations. Thanks for the great work, keep it up.

Does JitPack not serve your needs? Took me like 5 minutes to setup. Dead simple to release on.

Just curious.

Advantagekit is not built with any of the build tools supported by JitPack; it is currently a (rather involved) Bazel build. JitPack also does not to my knowledge support the zip publishing needed to publish a WPILib vendordep with native components.

2 Likes

Ah I see. Good to know.

AdvantageKit 2024 Beta 2

Beta 2 of AdvantageKit is now released with support for WPILib 2024.1.1-beta-3. The full changelog can be found on the GitHub release. Remember that AdvantageKit should only be used with the WPILib version specified in each set of release notes.

To update, choose the “WPILib: Manage Vendor Libraries” command in VSCode and click “Check for updates (online)”. The WPILib version can be updated at the top of “build.gradle”.

1 Like

We are having a repeated issue with Advantagekit and are wondering if there is a possible solution. Randomly, after we deploy to the robot and try to drive it, the robot crashes due to it trying to allocate too much memory. Any help would be appreciated!

The 2024 WPILib/RIO beta has severe memory issues on the RIO 1 after deploying code (see here). There have been memory issues related to repeated deploys for many years, but it got much worse for 2024. I’ve observed similar behavior in my testing, where the code begins crashing repeatedly with memory errors after only a few deploys. The underlying issue is unrelated to AdvantageKit as far as I can tell, except that AdvantageKit increases the complexity of the code and might make it appear a bit faster. Unfortunately that means there’s not much to be done on the AdvantageKit side of things. Until the issue is fixed, the best solution is to reboot the RIO when you get a memory error.

3 Likes

My kingdom for a robot controller that isn’t a potato…

7 Likes

We accidentally logged our wheel speeds as “PutString” on smart dashboard. Is there any way to tell advantage scope to treat a field as a number and let us graph it?

That just means it would take longer to hit the OOM condition. The issue probably lies in how the old robot program is killed before the new one is started.

3 Likes

So this is not a persistent error that occurs from multiple deploys, only when there are multiple deploys without restarting the rio? Does restart robot code resolve the issue or does it require the entire rio to restart?

1 Like

There’s no way to override a field type, since it would be problematic to try that with a field that doesn’t have data interpretable as a number. If you need to access data from a log file (and thus can’t switch the type), here’s a potential workaround:

  1. Export the field in a CSV format. You can go to “File” > “Export Data…” and under “Prefixes” enter the key of the field you want to look at. Leave the other options at their defaults.
  2. Open the CSV file in Excel (or your choice of spreadsheet program). You should be able to switch the cell types for the data column to “number” if it doesn’t do so automatically.
  3. Create a line graph or scatter plot using the timestamp and data columns.

It’s obviously not ideal, but this way you can at least look at the logged values on a graph.

It occurs when deploying multiple times without restarting the RIO. All of the memory ends up allocated to old robot programs that aren’t running anymore, meaning the new robot program fails to start since it can’t allocate the required memory (and repeatedly restarts after each crash). This means that restarting the robot code doesn’t fix the issue; the code is already restarting continuously because it can’t allocate the required memory. Rebooting the RIO seems to be the only solution right now.

1 Like

@jonahb55 I love all of the new improvements, really excited to take our advantage kit usage to the next level next year! I was playing with swerve example project in the simulator and wasn’t able to get the odometry to show up in advantageScope, nor was I able to see the measured/setpoint values change for the swerve modules. I can see the voltage setpoint react to my controller input, but the swerve module values and odometry don’t seem to be updating. Would you be able to verify if it works in simulation for you?