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.
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
DataLogManager Examples
To log data from your subsystems, publish it to NetworkTables using SmartDashboard or NetworkTableInstance. DataLogManager will automatically capture it.
π Subsystem Telemetry Example
πΊοΈ Logging Robot Pose
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.
- Open AdvantageScope on your driver station
- Select "Connect to Robot" from the menu
- Enter your team number or robot IP address (e.g., roborio-TEAM-frc.local)
- AdvantageScope connects via NetworkTables
- Add graphs and visualizations to monitor data in real-time
- Perfect for tuning PID controllers and debugging sensors
π₯ Post-Match Log Analysis
Download and analyze logs using AdvantageScope's built-in tools.
- Open Preferences (App > Show Preferences)
- Update the robot address and log folder if needed
- Click "File" > "Download Logs..."
- Select the logs you want to download (newest at top)
- Click the download symbol (β) and select a save location
- Open the downloaded .wpilog file
- 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
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.