[commands] Add GetName to Subsystem, use in Scheduler tracer epochs (#5836)

This commit is contained in:
Ryan Blue
2023-12-01 02:10:53 -05:00
committed by GitHub
parent ac7d726ac3
commit 1144115da0
9 changed files with 37 additions and 8 deletions

View File

@@ -261,7 +261,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
if (RobotBase.isSimulation()) {
subsystem.simulationPeriodic();
}
m_watchdog.addEpoch(subsystem.getClass().getSimpleName() + ".periodic()");
m_watchdog.addEpoch(subsystem.getName() + ".periodic()");
}
// Cache the active instance to avoid concurrency problems if setActiveLoop() is called from

View File

@@ -40,6 +40,15 @@ public interface Subsystem {
*/
default void simulationPeriodic() {}
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
default String getName() {
return this.getClass().getSimpleName();
}
/**
* Sets the default {@link Command} of the subsystem. The default command will be automatically
* scheduled when no other commands are scheduled that require the subsystem. Default commands

View File

@@ -28,6 +28,7 @@ public abstract class SubsystemBase implements Subsystem, Sendable {
*
* @return Name
*/
@Override
public String getName() {
return SendableRegistry.getName(this);
}