[epilogue] Add Epilogue.update() (#7047)

Currently, users can only invoke Epilogue via Epilogue.bind(TimedRobot). This PR adds a new method Epilogue.update(TimedRobot) so that Epilogue can manually called, in case a user is seeking more deterministic timing of their logs in reference to their control loops.
This commit is contained in:
Bryce Roethel
2024-09-07 22:59:49 -04:00
committed by GitHub
parent c8dab95ea7
commit 115ffa3396
2 changed files with 56 additions and 16 deletions

View File

@@ -140,6 +140,25 @@ public class EpilogueGenerator {
for (TypeElement mainRobotClass : mainRobotClasses) {
String robotClassName = mainRobotClass.getQualifiedName().toString();
out.println();
out.print(
"""
/**
* Updates Epilogue. This must be called periodically in order for Epilogue to record
* new values. Alternatively, {@code bind()} can be used to update at an offset from
* the main robot loop.
*/
""");
out.println(" public static void update(" + robotClassName + " robot) {");
out.println(" long start = System.nanoTime();");
out.println(
" "
+ StringUtils.loggerFieldName(mainRobotClass)
+ ".tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);");
out.println(
" config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);");
out.println(" }");
out.println();
out.print(
"""
@@ -161,13 +180,7 @@ public class EpilogueGenerator {
out.println(" }");
out.println();
out.println(" robot.addPeriodic(() -> {");
out.println(" long start = System.nanoTime();");
out.println(
" "
+ StringUtils.loggerFieldName(mainRobotClass)
+ ".tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);");
out.println(
" config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);");
out.println(" update(robot);");
out.println(
" }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));");
out.println(" }");

View File

@@ -147,6 +147,17 @@ class EpilogueGeneratorTest {
return importance.compareTo(config.minimumImportance) >= 0;
}
/**
* Updates Epilogue. This must be called periodically in order for Epilogue to record
* new values. Alternatively, {@code bind()} can be used to update at an offset from
* the main robot loop.
*/
public static void update(edu.wpi.first.epilogue.Example robot) {
long start = System.nanoTime();
exampleLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);
}
/**
* Binds Epilogue updates to a timed robot's update period. Log calls will be made at the
* same update rate as the robot's loop function, but will be offset by a full phase
@@ -164,9 +175,7 @@ class EpilogueGeneratorTest {
}
robot.addPeriodic(() -> {
long start = System.nanoTime();
exampleLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);
update(robot);
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
}
}
@@ -218,6 +227,17 @@ class EpilogueGeneratorTest {
return importance.compareTo(config.minimumImportance) >= 0;
}
/**
* Updates Epilogue. This must be called periodically in order for Epilogue to record
* new values. Alternatively, {@code bind()} can be used to update at an offset from
* the main robot loop.
*/
public static void update(edu.wpi.first.epilogue.AlphaBot robot) {
long start = System.nanoTime();
alphaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);
}
/**
* Binds Epilogue updates to a timed robot's update period. Log calls will be made at the
* same update rate as the robot's loop function, but will be offset by a full phase
@@ -235,12 +255,21 @@ class EpilogueGeneratorTest {
}
robot.addPeriodic(() -> {
long start = System.nanoTime();
alphaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);
update(robot);
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
}
/**
* Updates Epilogue. This must be called periodically in order for Epilogue to record
* new values. Alternatively, {@code bind()} can be used to update at an offset from
* the main robot loop.
*/
public static void update(edu.wpi.first.epilogue.BetaBot robot) {
long start = System.nanoTime();
betaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log(\"Epilogue/Stats/Last Run\", (System.nanoTime() - start) / 1e6);
}
/**
* Binds Epilogue updates to a timed robot's update period. Log calls will be made at the
* same update rate as the robot's loop function, but will be offset by a full phase
@@ -258,9 +287,7 @@ class EpilogueGeneratorTest {
}
robot.addPeriodic(() -> {
long start = System.nanoTime();
betaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
config.dataLogger.log("Epilogue/Stats/Last Run", (System.nanoTime() - start) / 1e6);
update(robot);
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
}
}