Skip to content

Commit

Permalink
Add WPILOGWriter constructor with default log path
Browse files Browse the repository at this point in the history
"/U/logs" on the RIO and "logs" in sim
  • Loading branch information
jwbonner committed Dec 15, 2023
1 parent 9a2f4ff commit e575b87
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The user program is responsible for configuring and initializing the logging fra
Logger.recordMetadata("ProjectName", "MyProject"); // Set a metadata value

if (isReal()) {
Logger.addDataReceiver(new WPILOGWriter("/U")); // Log to a USB stick
Logger.addDataReceiver(new WPILOGWriter()); // Log to a USB stick ("/U/logs")
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
new PowerDistribution(1, ModuleType.kRev); // Enables power distribution logging
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void robotInit() {
// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick
Logger.addDataReceiver(new WPILOGWriter("/U"));
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void robotInit() {
// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick
Logger.addDataReceiver(new WPILOGWriter("/U"));
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

Expand Down
4 changes: 2 additions & 2 deletions example_projects/skeleton/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public void robotInit() {
// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick
Logger.addDataReceiver(new WPILOGWriter("/U"));
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void robotInit() {
// Set up data receivers & replay source
switch (Constants.currentMode) {
case REAL:
// Running on a real robot, log to a USB stick
Logger.addDataReceiver(new WPILOGWriter("/U"));
// Running on a real robot, log to a USB stick ("/U/logs")
Logger.addDataReceiver(new WPILOGWriter());
Logger.addDataReceiver(new NT4Publisher());
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
public class WPILOGWriter implements LogDataReceiver {
private static final double timestampUpdateDelay = 5.0; // Wait several seconds after DS attached to ensure
// timestamp/timezone is updated
private static final String defaultPathRio = "/U/logs";
private static final String defaultPathSim = "logs";
private static final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yy-MM-dd_HH-mm-ss");

private String folder;
Expand Down Expand Up @@ -99,6 +101,18 @@ public WPILOGWriter(String path) {
this(path, 0.1);
}

/**
* Create a new WPILOGWriter for writing to a ".wpilog" file.
*
* <p>
* The logs will be saved to "/U/logs" on the RIO and "logs" in sim. The
* filename will be generated based on the current time and match number (if
* applicable).
*/
public WPILOGWriter() {
this(RobotBase.isSimulation() ? defaultPathSim : defaultPathRio);
}

public void start() {
// Create folder if necessary
File logFolder = new File(folder);
Expand Down

0 comments on commit e575b87

Please sign in to comment.