[commands] Revert SubsystemBase deprecation/removal (#5634)

This commit is contained in:
Ryan Blue
2023-09-14 23:56:48 -04:00
committed by GitHub
parent bc7f23a632
commit 3b79cb6ed3
80 changed files with 370 additions and 375 deletions

View File

@@ -14,7 +14,7 @@ import edu.wpi.first.math.controller.PIDController;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public abstract class PIDSubsystem extends Subsystem {
public abstract class PIDSubsystem extends SubsystemBase {
protected final PIDController m_controller;
protected boolean m_enabled;

View File

@@ -16,7 +16,7 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public abstract class ProfiledPIDSubsystem extends Subsystem {
public abstract class ProfiledPIDSubsystem extends SubsystemBase {
protected final ProfiledPIDController m_controller;
protected boolean m_enabled;

View File

@@ -4,10 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* A robot subsystem. Subsystems are the basic unit of robot organization in the Command-based
* framework; they encapsulate low-level hardware objects (motor controllers, sensors, etc.) and
@@ -17,34 +13,29 @@ import edu.wpi.first.util.sendable.SendableRegistry;
* their {@link Command#getRequirements()} method, and resources used within a subsystem should
* generally remain encapsulated and not be shared by other parts of the robot.
*
* <p>Subsystems are automatically registered with the default scheduler in order for the {@link
* Subsystem#periodic()} method to be called.
* <p>Subsystems must be registered with the scheduler with the {@link
* CommandScheduler#registerSubsystem(Subsystem...)} method in order for the {@link
* Subsystem#periodic()} method to be called. It is recommended that this method be called from the
* constructor of users' Subsystem implementations. The {@link SubsystemBase} class offers a simple
* base for user implementations that handles this.
*
* <p>This class is provided by the NewCommands VendorDep
*/
public abstract class Subsystem implements Sendable {
/** Constructor. */
public Subsystem() {
String name = this.getClass().getSimpleName();
name = name.substring(name.lastIndexOf('.') + 1);
SendableRegistry.addLW(this, name, name);
CommandScheduler.getInstance().registerSubsystem(this);
}
public interface Subsystem {
/**
* This method is called periodically by the {@link CommandScheduler}. Useful for updating
* subsystem-specific state that you don't want to offload to a {@link Command}. Teams should try
* to be consistent within their own codebases about which responsibilities will be handled by
* Commands, and which will be handled here.
*/
public void periodic() {}
default void periodic() {}
/**
* This method is called periodically by the {@link CommandScheduler}. Useful for updating
* subsystem-specific state that needs to be maintained for simulations, such as for updating
* {@link edu.wpi.first.wpilibj.simulation} classes and setting simulated sensor readings.
*/
public void simulationPeriodic() {}
default void simulationPeriodic() {}
/**
* Sets the default {@link Command} of the subsystem. The default command will be automatically
@@ -55,7 +46,7 @@ public abstract class Subsystem implements Sendable {
*
* @param defaultCommand the default command to associate with this subsystem
*/
public void setDefaultCommand(Command defaultCommand) {
default void setDefaultCommand(Command defaultCommand) {
CommandScheduler.getInstance().setDefaultCommand(this, defaultCommand);
}
@@ -63,7 +54,7 @@ public abstract class Subsystem implements Sendable {
* Removes the default command for the subsystem. This will not cancel the default command if it
* is currently running.
*/
public void removeDefaultCommand() {
default void removeDefaultCommand() {
CommandScheduler.getInstance().removeDefaultCommand(this);
}
@@ -73,7 +64,7 @@ public abstract class Subsystem implements Sendable {
*
* @return the default command associated with this subsystem
*/
public Command getDefaultCommand() {
default Command getDefaultCommand() {
return CommandScheduler.getInstance().getDefaultCommand(this);
}
@@ -83,51 +74,15 @@ public abstract class Subsystem implements Sendable {
*
* @return the scheduled command currently requiring this subsystem
*/
public Command getCurrentCommand() {
default Command getCurrentCommand() {
return CommandScheduler.getInstance().requiring(this);
}
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
public String getName() {
return SendableRegistry.getName(this);
}
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
public void setName(String name) {
SendableRegistry.setName(this, name);
}
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
/**
* Sets the subsystem name of this Subsystem.
*
* @param subsystem subsystem name
*/
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
* Registers this subsystem with the {@link CommandScheduler}, allowing its {@link
* Subsystem#periodic()} method to be called when the scheduler runs.
*/
public void register() {
default void register() {
CommandScheduler.getInstance().registerSubsystem(this);
}
@@ -138,7 +93,7 @@ public abstract class Subsystem implements Sendable {
* @return the command
* @see InstantCommand
*/
public Command runOnce(Runnable action) {
default Command runOnce(Runnable action) {
return Commands.runOnce(action, this);
}
@@ -150,7 +105,7 @@ public abstract class Subsystem implements Sendable {
* @return the command
* @see RunCommand
*/
public Command run(Runnable action) {
default Command run(Runnable action) {
return Commands.run(action, this);
}
@@ -163,7 +118,7 @@ public abstract class Subsystem implements Sendable {
* @return the command
* @see StartEndCommand
*/
public Command startEnd(Runnable start, Runnable end) {
default Command startEnd(Runnable start, Runnable end) {
return Commands.startEnd(start, end, this);
}
@@ -175,33 +130,7 @@ public abstract class Subsystem implements Sendable {
* @param end the action to run on interrupt
* @return the command
*/
public Command runEnd(Runnable run, Runnable end) {
default Command runEnd(Runnable run, Runnable end) {
return Commands.runEnd(run, end, this);
}
/**
* Associates a {@link Sendable} with this Subsystem. Also update the child's name.
*
* @param name name to give child
* @param child sendable
*/
public void addChild(String name, Sendable child) {
SendableRegistry.addLW(child, getSubsystem(), name);
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Subsystem");
builder.addBooleanProperty(".hasDefault", () -> getDefaultCommand() != null, null);
builder.addStringProperty(
".default",
() -> getDefaultCommand() != null ? getDefaultCommand().getName() : "none",
null);
builder.addBooleanProperty(".hasCommand", () -> getCurrentCommand() != null, null);
builder.addStringProperty(
".command",
() -> getCurrentCommand() != null ? getCurrentCommand().getName() : "none",
null);
}
}

View File

@@ -4,15 +4,84 @@
package edu.wpi.first.wpilibj2.command;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/**
* A base for subsystems that handles registration in the constructor, and provides a more intuitive
* method for setting the default command.
*
* <p>This class is provided by the NewCommands VendorDep
*
* @deprecated All functionality provided by {@link SubsystemBase} has been merged into {@link
* Subsystem}. Use {@link Subsystem} instead.
*/
@Deprecated(since = "2024", forRemoval = true)
@SuppressWarnings("PMD.AbstractClassWithoutAnyMethod")
public abstract class SubsystemBase extends Subsystem {}
public abstract class SubsystemBase implements Subsystem, Sendable {
/** Constructor. */
public SubsystemBase() {
String name = this.getClass().getSimpleName();
name = name.substring(name.lastIndexOf('.') + 1);
SendableRegistry.addLW(this, name, name);
CommandScheduler.getInstance().registerSubsystem(this);
}
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
public String getName() {
return SendableRegistry.getName(this);
}
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
public void setName(String name) {
SendableRegistry.setName(this, name);
}
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
/**
* Sets the subsystem name of this Subsystem.
*
* @param subsystem subsystem name
*/
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
* Associates a {@link Sendable} with this Subsystem. Also update the child's name.
*
* @param name name to give child
* @param child sendable
*/
public void addChild(String name, Sendable child) {
SendableRegistry.addLW(child, getSubsystem(), name);
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Subsystem");
builder.addBooleanProperty(".hasDefault", () -> getDefaultCommand() != null, null);
builder.addStringProperty(
".default",
() -> getDefaultCommand() != null ? getDefaultCommand().getName() : "none",
null);
builder.addBooleanProperty(".hasCommand", () -> getCurrentCommand() != null, null);
builder.addStringProperty(
".command",
() -> getCurrentCommand() != null ? getCurrentCommand().getName() : "none",
null);
}
}

View File

@@ -14,7 +14,7 @@ import edu.wpi.first.math.trajectory.TrapezoidProfile;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public abstract class TrapezoidProfileSubsystem extends Subsystem {
public abstract class TrapezoidProfileSubsystem extends SubsystemBase {
private final double m_period;
private final TrapezoidProfile m_profile;