44
55package org .wpilib .command2 ;
66
7- import org .wpilib .util .sendable .Sendable ;
8- import org .wpilib .util .sendable .SendableBuilder ;
9- import org .wpilib .util .sendable .SendableRegistry ;
7+ import org .wpilib .telemetry .TelemetryLoggable ;
8+ import org .wpilib .telemetry .TelemetryTable ;
109
1110/**
1211 * A base for subsystems that handles registration in the constructor, and provides a more intuitive
1312 * method for setting the default command.
1413 *
1514 * <p>This class is provided by the NewCommands VendorDep
1615 */
17- public abstract class SubsystemBase implements Subsystem , Sendable {
16+ public abstract class SubsystemBase implements Subsystem , TelemetryLoggable {
1817 /** Constructor. Telemetry/log name defaults to the classname. */
1918 @ SuppressWarnings ("this-escape" )
2019 public SubsystemBase () {
2120 String name = this .getClass ().getSimpleName ();
22- name = name .substring (name .lastIndexOf ('.' ) + 1 );
23- SendableRegistry .add (this , name , name );
21+ m_name = name .substring (name .lastIndexOf ('.' ) + 1 );
2422 CommandScheduler .getInstance ().registerSubsystem (this );
2523 }
2624
@@ -31,7 +29,7 @@ public SubsystemBase() {
3129 */
3230 @ SuppressWarnings ("this-escape" )
3331 public SubsystemBase (String name ) {
34- SendableRegistry . add ( this , name , name ) ;
32+ m_name = name ;
3533 CommandScheduler .getInstance ().registerSubsystem (this );
3634 }
3735
@@ -42,7 +40,7 @@ public SubsystemBase(String name) {
4240 */
4341 @ Override
4442 public String getName () {
45- return SendableRegistry . getName ( this ) ;
43+ return m_name ;
4644 }
4745
4846 /**
@@ -51,50 +49,24 @@ public String getName() {
5149 * @param name name
5250 */
5351 public void setName (String name ) {
54- SendableRegistry . setName ( this , name ) ;
52+ m_name = name ;
5553 }
5654
57- /**
58- * Gets the subsystem name of this Subsystem.
59- *
60- * @return Subsystem name
61- */
62- public String getSubsystem () {
63- return SendableRegistry .getSubsystem (this );
64- }
65-
66- /**
67- * Sets the subsystem name of this Subsystem.
68- *
69- * @param subsystem subsystem name
70- */
71- public void setSubsystem (String subsystem ) {
72- SendableRegistry .setSubsystem (this , subsystem );
73- }
55+ @ Override
56+ public void updateTelemetry (TelemetryTable table ) {
57+ var defaultCommand = getDefaultCommand ();
58+ table .log (".hasDefault" , defaultCommand != null );
59+ table .log (".default" , defaultCommand != null ? defaultCommand .getName () : "none" );
7460
75- /**
76- * Associates a {@link Sendable} with this Subsystem. Also update the child's name.
77- *
78- * @param name name to give child
79- * @param child sendable
80- */
81- public void addChild (String name , Sendable child ) {
82- SendableRegistry .add (child , getSubsystem (), name );
61+ var currentCommand = getCurrentCommand ();
62+ table .log (".hasCommand" , currentCommand != null );
63+ table .log (".command" , currentCommand != null ? currentCommand .getName () : "none" );
8364 }
8465
8566 @ Override
86- public void initSendable (SendableBuilder builder ) {
87- builder .setSmartDashboardType ("Subsystem" );
88-
89- builder .addBooleanProperty (".hasDefault" , () -> getDefaultCommand () != null , null );
90- builder .addStringProperty (
91- ".default" ,
92- () -> getDefaultCommand () != null ? getDefaultCommand ().getName () : "none" ,
93- null );
94- builder .addBooleanProperty (".hasCommand" , () -> getCurrentCommand () != null , null );
95- builder .addStringProperty (
96- ".command" ,
97- () -> getCurrentCommand () != null ? getCurrentCommand ().getName () : "none" ,
98- null );
67+ public String getTelemetryType () {
68+ return "Subsystem" ;
9969 }
70+
71+ private String m_name ;
10072}
0 commit comments