Skip to content

Commit

Permalink
[commands] SubsystemBase: allow setting name in constructor (#6052)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oblarg authored Dec 16, 2023
1 parent 0b4c6a1 commit a004c9e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* <p>This class is provided by the NewCommands VendorDep
*/
public abstract class SubsystemBase implements Subsystem, Sendable {
/** Constructor. */
/** Constructor. Telemetry/log name defaults to the classname. */
@SuppressWarnings("this-escape")
public SubsystemBase() {
String name = this.getClass().getSimpleName();
Expand All @@ -24,6 +24,17 @@ public SubsystemBase() {
CommandScheduler.getInstance().registerSubsystem(this);
}

/**
* Constructor.
*
* @param name Name of the subsystem for telemetry and logging.
*/
@SuppressWarnings("this-escape")
public SubsystemBase(String name) {
SendableRegistry.addLW(this, name, name);
CommandScheduler.getInstance().registerSubsystem(this);
}

/**
* Gets the name of this Subsystem.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ SubsystemBase::SubsystemBase() {
CommandScheduler::GetInstance().RegisterSubsystem({this});
}

SubsystemBase::SubsystemBase(std::string_view name) {
wpi::SendableRegistry::AddLW(this, name);
CommandScheduler::GetInstance().RegisterSubsystem({this});
}

void SubsystemBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ class SubsystemBase : public Subsystem,
void AddChild(std::string name, wpi::Sendable* child);

protected:
/**
* Constructor. Telemetry/log name defaults to the classname.
*/
SubsystemBase();
/**
* Constructor.
*
* @param name Name of the subsystem for telemetry and logging.
*/
explicit SubsystemBase(std::string_view name);
};
} // namespace frc2

0 comments on commit a004c9e

Please sign in to comment.