Gray Matter LogoGray Matter Workshop

Implementing Logging

Setting Up Data Logging

Implementing logging in your robot code is straightforward with WPILib's DataLogManager. This section shows you how to enable logging, publish data to NetworkTables, and view logs with AdvantageScope.

Key Concept: A few lines of code unlock comprehensive data logging for debugging and analysis.

Using WPILib Epilogue

WPILib 2025+ includes Epilogue, an annotation-based logging framework that automatically generates logging code at compile time. Instead of manually publishing data to NetworkTables, you simply annotate your classes with @Logged.

Subsystem with @Logged AnnotationJAVA

Epilogue Benefits

  • Zero boilerplate: No SmartDashboard.put() calls in periodic()
  • Compile-time generation: Efficient code with no runtime overhead
  • Automatic discovery: Logs all public fields/getters unless marked @NotLogged
  • Built into WPILib 2025: No extra dependencies required
WPILib Epilogue Documentation

DataLogManager Examples

To log data from your subsystems, publish it to NetworkTables using SmartDashboard or NetworkTableInstance. DataLogManager will automatically capture it.

πŸ“Š Subsystem Telemetry Example
Subsystem with TelemetryJAVA
πŸ—ΊοΈ Logging Robot Pose
Swerve Drive Odometry LoggingJAVA

Performance Considerations

  • Don't overdo it: Logging too much data can impact loop timing
  • Use appropriate keys: Organize data with hierarchical keys (e.g., "Subsystem/Parameter")
  • Avoid String spam: Strings are expensive to log at high frequency
  • Consider sampling rate: Not all data needs 50Hz logging

Workshop Code Implementation

For this workshop we will use DataLogManager and Epilogue, as they work perfectly together and are built into WPILib.

Robot.java - Adding Logging

Loading file...

RobotContainer.java

RobotContainer.java includes logging setup for subsystems and commands. This helps track which commands are running and monitor subsystem state.

Loading file...

πŸ”§ Subsystem Logging Example

Subsystems use Epilogue's @Logged annotation to automatically log data. This example shows the CommandSwerveDrivetrain with Epilogue logging enabled.

Loading file...

AdvantageScope

AdvantageScope is a powerful log visualization tool that can both read .wpilog files for post-match analysis and connect to your robot in real-time for live data monitoring.

πŸ“‘ Real-Time Data Viewing

AdvantageScope can connect to your robot while it's running to view live data through NetworkTables.

  1. Open AdvantageScope on your driver station
  2. Select "Connect to Robot" from the menu
  3. Enter your team number or robot IP address (e.g., roborio-TEAM-frc.local)
  4. AdvantageScope connects via NetworkTables
  5. Add graphs and visualizations to monitor data in real-time
  6. Perfect for tuning PID controllers and debugging sensors

πŸ“₯ Post-Match Log Analysis

Download and analyze logs using AdvantageScope's built-in tools.

  1. Open Preferences (App > Show Preferences)
  2. Update the robot address and log folder if needed
  3. Click "File" > "Download Logs..."
  4. Select the logs you want to download (newest at top)
  5. Click the download symbol (↓) and select a save location
  6. Open the downloaded .wpilog file
  7. Add line graphs or use 3D field view for analysis

NetworkTables Connection

When connecting to your robot in real-time, AdvantageScope uses NetworkTables to subscribe to the data being published by your robot code. This means:

  • You can see live sensor values and motor outputs as your robot runs
  • Changes to PID gains or other parameters can be tested immediately
  • No need to wait for match completion to download and analyze logs
  • Real-time data is not automatically saved unless DataLogManager is enabled

AdvantageScope Pro Tips

  • Overlay multiple signals: Compare target vs actual values on same graph
  • Video sync: Sync log data with match video for context
  • Save layouts: Create reusable dashboard layouts for quick analysis
AdvantageScope Documentation

Logging Best Practices

βœ… Do

  • Log sensor inputs and motor outputs
  • Use hierarchical key naming (Subsystem/Parameter)
  • Log target setpoints alongside actual values
  • Include timestamps for event logging
  • Download logs after every match
  • Review logs between matches to catch issues

❌ Don't

  • Log high-frequency strings (use numbers/booleans)
  • Publish the same data multiple times
  • Ignore loop overrun warnings from excessive logging

Additional Resources

What's Next?

Up Next: Drive to Point

With logging configured, you're ready to implement autonomous navigation using PID controllers to drive to specific field positions with precise control.