Skip to content

Logging

I am starting this documentation to track the though process of how we want logging to be done on the robot.

Resources: - FRC Team 6328 - Mechanical Advantage's presentation on logging at Champ's 2023 - AdvantageKit - Further examples of how to use that are listed in the README of this repo - AdvantageScope - Log viewer for both WPILib logs as well as AdvantageKit logs - WPILib Datalog documentation

Starting off, I think it is essential to get the basics of "Level 2" logging down before even attempting AdvantageKit. While it is a nice goal to have, it is definitely more of an offseason type of code-revamp. WPILib logging is much more attainable and most likely doable this season.

Importance of logging

Logging can provide so many benefits to the team: - Driver feedback during the match - Code crash investigation/debugging - Tuning PID loops - Re-creating a match timeline of events

WPILib Logging

The following summarizations come from here.

  • DataLogManager is a wrapper class around the DataLog WPILib class.
  • All Logging file I/O is handled is a thread separate to robot code.
  • "Log files are initially named FRC_TBD_{random}.wpilog until the DS connects. After the DS connects, the log file is renamed to FRC_yyyyMMdd_HHmmss.wpilog (where the date/time is UTC). If the FMS is connected and provides a match number, the log file is renamed to FRC_yyyyMMdd_HHmmss_{event}_{match}.wpilog."
  • USB flash drives need to be formatted as FAT32 to work with the roboRIO.
  • Logging can be started very simply:
    // Starts recording to data log
    DataLogManager.start();
    
    This can be put in RobotContainer's constructor or even better (because it happens sooner) robotInit(). Future Mark here: This really doesn't provide any advantage, because RobotContainer gets defined first thing in robotInit() anyway. So to keep the Robot.java class clean, just put it in RobotContainer.
  • DataLogManager.log() can be used as a replacement to System.out.println(). It places the messages both in the messages entry in the log as well as printing to DriverStation like normal.
  • By default, DataLogManager does not record joystick data. This can be started by performing the following:
    // Record both DS control and joystick data
    DriverStation.startDataLog(DataLogManager.getLog());
    
    // (alternatively) Record only DS control data
    DriverStation.startDataLog(DataLogManager.getLog(), false);
    
    I'm unsure of what the difference in the statements above really mean as of right now.

Sendables

Sendable is a java interface which many WPILib classes implement. Because of this, instead of pushing specific values, a class that implements sendable can push the whole class and all values at once. For example:

SmartDashboard.putData("Arm PID", armPIDController);

Unlike printing a value, Sendables only need to be sent to the dashboard once for their values to continually update