mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[epilogue] Allow configuring logging period and logging period offset (#6893)
This commit is contained in:
@@ -52,6 +52,9 @@ public class EpilogueGenerator {
|
||||
out.println("package edu.wpi.first.epilogue;");
|
||||
out.println();
|
||||
|
||||
out.println("import static edu.wpi.first.units.Units.Seconds;");
|
||||
out.println();
|
||||
|
||||
loggerClassNames.stream()
|
||||
.sorted()
|
||||
.forEach(
|
||||
@@ -150,6 +153,13 @@ public class EpilogueGenerator {
|
||||
*/
|
||||
""");
|
||||
out.println(" public static void bind(" + robotClassName + " robot) {");
|
||||
out.println(" if (config.loggingPeriod == null) {");
|
||||
out.println(" config.loggingPeriod = Seconds.of(robot.getPeriod());");
|
||||
out.println(" }");
|
||||
out.println(" if (config.loggingPeriodOffset == null) {");
|
||||
out.println(" config.loggingPeriodOffset = config.loggingPeriod.divide(2);");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
out.println(" robot.addPeriodic(() -> {");
|
||||
out.println(" long start = System.nanoTime();");
|
||||
out.println(
|
||||
@@ -158,7 +168,8 @@ public class EpilogueGenerator {
|
||||
+ ".tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);");
|
||||
out.println(
|
||||
" edu.wpi.first.networktables.NetworkTableInstance.getDefault().getEntry(\"Epilogue/Stats/Last Run\").setDouble((System.nanoTime() - start) / 1e6);");
|
||||
out.println(" }, robot.getPeriod(), robot.getPeriod() / 2);");
|
||||
out.println(
|
||||
" }, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class EpilogueGeneratorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
import static edu.wpi.first.units.Units.Seconds;
|
||||
|
||||
import edu.wpi.first.epilogue.ExampleLogger;
|
||||
|
||||
public final class Epilogue {
|
||||
@@ -77,6 +79,8 @@ class EpilogueGeneratorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
import static edu.wpi.first.units.Units.Seconds;
|
||||
|
||||
import edu.wpi.first.epilogue.ExampleLogger;
|
||||
|
||||
public final class Epilogue {
|
||||
@@ -119,6 +123,8 @@ class EpilogueGeneratorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
import static edu.wpi.first.units.Units.Seconds;
|
||||
|
||||
import edu.wpi.first.epilogue.ExampleLogger;
|
||||
|
||||
public final class Epilogue {
|
||||
@@ -150,11 +156,18 @@ class EpilogueGeneratorTest {
|
||||
* loop.
|
||||
*/
|
||||
public static void bind(edu.wpi.first.epilogue.Example robot) {
|
||||
if (config.loggingPeriod == null) {
|
||||
config.loggingPeriod = Seconds.of(robot.getPeriod());
|
||||
}
|
||||
if (config.loggingPeriodOffset == null) {
|
||||
config.loggingPeriodOffset = config.loggingPeriod.divide(2);
|
||||
}
|
||||
|
||||
robot.addPeriodic(() -> {
|
||||
long start = System.nanoTime();
|
||||
exampleLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
|
||||
edu.wpi.first.networktables.NetworkTableInstance.getDefault().getEntry("Epilogue/Stats/Last Run").setDouble((System.nanoTime() - start) / 1e6);
|
||||
}, robot.getPeriod(), robot.getPeriod() / 2);
|
||||
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
|
||||
}
|
||||
}
|
||||
""";
|
||||
@@ -179,6 +192,8 @@ class EpilogueGeneratorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
import static edu.wpi.first.units.Units.Seconds;
|
||||
|
||||
import edu.wpi.first.epilogue.AlphaBotLogger;
|
||||
import edu.wpi.first.epilogue.BetaBotLogger;
|
||||
|
||||
@@ -212,11 +227,18 @@ class EpilogueGeneratorTest {
|
||||
* loop.
|
||||
*/
|
||||
public static void bind(edu.wpi.first.epilogue.AlphaBot robot) {
|
||||
if (config.loggingPeriod == null) {
|
||||
config.loggingPeriod = Seconds.of(robot.getPeriod());
|
||||
}
|
||||
if (config.loggingPeriodOffset == null) {
|
||||
config.loggingPeriodOffset = config.loggingPeriod.divide(2);
|
||||
}
|
||||
|
||||
robot.addPeriodic(() -> {
|
||||
long start = System.nanoTime();
|
||||
alphaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
|
||||
edu.wpi.first.networktables.NetworkTableInstance.getDefault().getEntry("Epilogue/Stats/Last Run").setDouble((System.nanoTime() - start) / 1e6);
|
||||
}, robot.getPeriod(), robot.getPeriod() / 2);
|
||||
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,11 +250,18 @@ class EpilogueGeneratorTest {
|
||||
* loop.
|
||||
*/
|
||||
public static void bind(edu.wpi.first.epilogue.BetaBot robot) {
|
||||
if (config.loggingPeriod == null) {
|
||||
config.loggingPeriod = Seconds.of(robot.getPeriod());
|
||||
}
|
||||
if (config.loggingPeriodOffset == null) {
|
||||
config.loggingPeriodOffset = config.loggingPeriod.divide(2);
|
||||
}
|
||||
|
||||
robot.addPeriodic(() -> {
|
||||
long start = System.nanoTime();
|
||||
betaBotLogger.tryUpdate(config.dataLogger.getSubLogger(config.root), robot, config.errorHandler);
|
||||
edu.wpi.first.networktables.NetworkTableInstance.getDefault().getEntry("Epilogue/Stats/Last Run").setDouble((System.nanoTime() - start) / 1e6);
|
||||
}, robot.getPeriod(), robot.getPeriod() / 2);
|
||||
}, config.loggingPeriod.in(Seconds), config.loggingPeriodOffset.in(Seconds));
|
||||
}
|
||||
}
|
||||
""";
|
||||
@@ -272,6 +301,8 @@ class EpilogueGeneratorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
import static edu.wpi.first.units.Units.Seconds;
|
||||
|
||||
import edu.wpi.first.epilogue.ExampleLogger;
|
||||
import edu.wpi.first.epilogue.CustomLogger;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import edu.wpi.first.epilogue.logging.NTDataLogger;
|
||||
import edu.wpi.first.epilogue.logging.errors.ErrorHandler;
|
||||
import edu.wpi.first.epilogue.logging.errors.ErrorPrinter;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.units.Measure;
|
||||
import edu.wpi.first.units.Time;
|
||||
|
||||
/**
|
||||
* A configuration object to be used by the generated {@code Epilogue} class to customize its
|
||||
@@ -23,6 +25,18 @@ public class EpilogueConfiguration {
|
||||
*/
|
||||
public DataLogger dataLogger = new NTDataLogger(NetworkTableInstance.getDefault());
|
||||
|
||||
/**
|
||||
* The period Epilogue will log at. By default this is the period that the robot runs at. This is
|
||||
* the field used by bind to configure speed when adding the periodic logging function
|
||||
*/
|
||||
public Measure<Time> loggingPeriod;
|
||||
|
||||
/**
|
||||
* The offset from the periodic run that Epilogue will log at. By default this will be half of the
|
||||
* robots period. This is the field used by bind when adding the periodic logging function
|
||||
*/
|
||||
public Measure<Time> loggingPeriodOffset;
|
||||
|
||||
/**
|
||||
* The minimum importance level of data to be logged. Defaults to debug, which logs data of all
|
||||
* importance levels. Any data tagged with an importance level lower than this will not be logged.
|
||||
|
||||
@@ -160,4 +160,8 @@
|
||||
<Match>
|
||||
<Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS" />
|
||||
</Match>
|
||||
<Match>
|
||||
<Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD" />
|
||||
<Class name="edu.wpi.first.epilogue.EpilogueConfiguration" />
|
||||
</Match>
|
||||
</FindBugsFilter>
|
||||
|
||||
Reference in New Issue
Block a user