Introducing: Logging with AdvantageKit

One of 6328’s key projects this offseason was to develop our own Java framework for data logging in robot code. We created AdvantageKit, a library that we plan to expand with a variety of useful tools for building robot code.

Lots of logging frameworks already exist in FRC, from built-in tools like the Driver Station and Network Tables to custom solutions for logging more detailed information. However, most systems exist around the same fundamental idea; record a limited set of values explicitly provided by the code. That could include sensor data, PID error, odometry pose, internal state, etc. While this has enormous value, it doesn’t solve the eternal sentiment when something goes wrong: “If only we were logging one extra field!”

Logging in AdvantageKit is built around a different principle, often used in industry. Instead of logging specific output values from the user code, it records all of the data flowing into the robot code. Every sensor value, joystick press, Network Tables update, and much more is logged every loop cycle. After a match, these values can be replayed to the robot code in a simulator. Since every input command is the same, all of the internal logic of the code is replayed exactly. This allows us to log extra fields after the fact, or add breakpoints and inspect the code line by line. This technique means that logging is more than just a tool for checking on specific issues; it’s also a safety net that can be used to verify how any part of the code functions.

This certainly isn’t a new idea in FRC, but one of our key goals was to find ways that we could support this high level of logging in a way that might be accessible to more teams. That means reducing the changes required to user code as much as possible, and building on top of existing frameworks (like command-based WPILib). Data is recorded and replayed in the background wherever possible. For inputs not built in to WPILib, hardware interaction in each subsystem is separated into an “IO layer” with an interface and one or more implementations. This structure allows the logging framework to inject input data in the simulator while using a default implementation that doesn’t require real hardware. As a bonus, it also makes it simple to replace the “real” hardware implementation with a physics simulator.

We created a custom viewer application called Advantage Scope, which reads data saved by the robot code in our custom binary format. The app includes visualization tools like line graphs and field maps, plus a few extra tricks; it can download log files from a RIO over SFTP, view data live over the network, or convert the data to a CSV for other tools.

advantage-scope

As part of 6328’s efforts with the #openalliance, all of our code is open source and available on GitHub. Most of the critical components already include documentation, and we’re working on filling in the gaps. Make sure to also keep an eye out for 6328’s 2022 build thread, where we’ll be sure to give updates on our progress with AdvantageKit (and lots of other software topics). We hope this work proves helpful (or at least interesting) to other teams thinking about options for data logging in robot code.

Useful Links

Scroll to Top