[commands] Merge CommandBase into Command and SubsystemBase into Subsystem (#5392)

Moves all CommandBase functionality into Command and deprecates CommandBase for removal.
Moves all SubsystemBase functionality into Subsystem and deprecates SubsystemBase for removal.
Adds a function to CommandScheduler to remove all registered Subsystems.
This commit is contained in:
Ryan Blue
2023-07-14 01:12:01 -04:00
committed by GitHub
parent 7ac932996a
commit aaea85ff16
176 changed files with 887 additions and 910 deletions

View File

@@ -7,6 +7,10 @@ package edu.wpi.first.wpilibj2.command;
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.util.function.BooleanConsumer;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BooleanSupplier;
@@ -20,12 +24,19 @@ import java.util.function.BooleanSupplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public interface Command {
public abstract class Command implements Sendable {
protected Set<Subsystem> m_requirements = new HashSet<>();
protected Command() {
String name = getClass().getName();
SendableRegistry.add(this, name.substring(name.lastIndexOf('.') + 1));
}
/** The initial subroutine of a command. Called once when the command is initially scheduled. */
default void initialize() {}
public void initialize() {}
/** The main body of a command. Called repeatedly while the command is scheduled. */
default void execute() {}
public void execute() {}
/**
* The action to take when the command ends. Called when either the command finishes normally, or
@@ -36,7 +47,7 @@ public interface Command {
*
* @param interrupted whether the command was interrupted/canceled
*/
default void end(boolean interrupted) {}
public void end(boolean interrupted) {}
/**
* Whether the command has finished. Once a command finishes, the scheduler will call its end()
@@ -44,7 +55,7 @@ public interface Command {
*
* @return whether the command has finished.
*/
default boolean isFinished() {
public boolean isFinished() {
return false;
}
@@ -60,7 +71,63 @@ public interface Command {
* @return the set of subsystems that are required
* @see InterruptionBehavior
*/
Set<Subsystem> getRequirements();
public Set<Subsystem> getRequirements() {
return m_requirements;
}
/**
* Adds the specified subsystems to the requirements of the command. The scheduler will prevent
* two commands that require the same subsystem from being scheduled simultaneously.
*
* <p>Note that the scheduler determines the requirements of a command when it is scheduled, so
* this method should normally be called from the command's constructor.
*
* @param requirements the requirements to add
*/
public final void addRequirements(Subsystem... requirements) {
for (Subsystem requirement : requirements) {
m_requirements.add(requireNonNullParam(requirement, "requirement", "addRequirements"));
}
}
/**
* Gets the name of this Command.
*
* <p>By default, the simple class name is used. This can be changed with {@link
* #setName(String)}.
*
* @return The display name of the Command
*/
public String getName() {
return SendableRegistry.getName(this);
}
/**
* Sets the name of this Command.
*
* @param name The display name of the Command.
*/
public void setName(String name) {
SendableRegistry.setName(this, name);
}
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
* Decorates this command with a timeout. If the specified timeout is exceeded before the command
@@ -75,7 +142,7 @@ public interface Command {
* @param seconds the timeout duration
* @return the command with the timeout added
*/
default ParallelRaceGroup withTimeout(double seconds) {
public ParallelRaceGroup withTimeout(double seconds) {
return raceWith(new WaitCommand(seconds));
}
@@ -93,7 +160,7 @@ public interface Command {
* @return the command with the interrupt condition added
* @see #onlyWhile(BooleanSupplier)
*/
default ParallelRaceGroup until(BooleanSupplier condition) {
public ParallelRaceGroup until(BooleanSupplier condition) {
return raceWith(new WaitUntilCommand(condition));
}
@@ -111,7 +178,7 @@ public interface Command {
* @return the command with the run condition added
* @see #until(BooleanSupplier)
*/
default ParallelRaceGroup onlyWhile(BooleanSupplier condition) {
public ParallelRaceGroup onlyWhile(BooleanSupplier condition) {
return until(() -> !condition.getAsBoolean());
}
@@ -128,7 +195,7 @@ public interface Command {
* @param requirements the required subsystems
* @return the decorated command
*/
default SequentialCommandGroup beforeStarting(Runnable toRun, Subsystem... requirements) {
public SequentialCommandGroup beforeStarting(Runnable toRun, Subsystem... requirements) {
return beforeStarting(new InstantCommand(toRun, requirements));
}
@@ -144,7 +211,7 @@ public interface Command {
* @param before the command to run before this one
* @return the decorated command
*/
default SequentialCommandGroup beforeStarting(Command before) {
public SequentialCommandGroup beforeStarting(Command before) {
return new SequentialCommandGroup(before, this);
}
@@ -161,7 +228,7 @@ public interface Command {
* @param requirements the required subsystems
* @return the decorated command
*/
default SequentialCommandGroup andThen(Runnable toRun, Subsystem... requirements) {
public SequentialCommandGroup andThen(Runnable toRun, Subsystem... requirements) {
return andThen(new InstantCommand(toRun, requirements));
}
@@ -178,7 +245,7 @@ public interface Command {
* @param next the commands to run next
* @return the decorated command
*/
default SequentialCommandGroup andThen(Command... next) {
public SequentialCommandGroup andThen(Command... next) {
SequentialCommandGroup group = new SequentialCommandGroup(this);
group.addCommands(next);
return group;
@@ -198,7 +265,7 @@ public interface Command {
* @param parallel the commands to run in parallel
* @return the decorated command
*/
default ParallelDeadlineGroup deadlineWith(Command... parallel) {
public ParallelDeadlineGroup deadlineWith(Command... parallel) {
return new ParallelDeadlineGroup(this, parallel);
}
@@ -216,7 +283,7 @@ public interface Command {
* @param parallel the commands to run in parallel
* @return the decorated command
*/
default ParallelCommandGroup alongWith(Command... parallel) {
public ParallelCommandGroup alongWith(Command... parallel) {
ParallelCommandGroup group = new ParallelCommandGroup(this);
group.addCommands(parallel);
return group;
@@ -236,7 +303,7 @@ public interface Command {
* @param parallel the commands to run in parallel
* @return the decorated command
*/
default ParallelRaceGroup raceWith(Command... parallel) {
public ParallelRaceGroup raceWith(Command... parallel) {
ParallelRaceGroup group = new ParallelRaceGroup(this);
group.addCommands(parallel);
return group;
@@ -254,7 +321,7 @@ public interface Command {
*
* @return the decorated command
*/
default RepeatCommand repeatedly() {
public RepeatCommand repeatedly() {
return new RepeatCommand(this);
}
@@ -265,7 +332,7 @@ public interface Command {
*
* @return the decorated command
*/
default ProxyCommand asProxy() {
public ProxyCommand asProxy() {
return new ProxyCommand(this);
}
@@ -284,7 +351,7 @@ public interface Command {
* @return the decorated command
* @see #onlyIf(BooleanSupplier)
*/
default ConditionalCommand unless(BooleanSupplier condition) {
public ConditionalCommand unless(BooleanSupplier condition) {
return new ConditionalCommand(new InstantCommand(), this, condition);
}
@@ -303,7 +370,7 @@ public interface Command {
* @return the decorated command
* @see #unless(BooleanSupplier)
*/
default ConditionalCommand onlyIf(BooleanSupplier condition) {
public ConditionalCommand onlyIf(BooleanSupplier condition) {
return unless(() -> !condition.getAsBoolean());
}
@@ -313,7 +380,7 @@ public interface Command {
* @param doesRunWhenDisabled true to run when disabled.
* @return the decorated command
*/
default WrapperCommand ignoringDisable(boolean doesRunWhenDisabled) {
public WrapperCommand ignoringDisable(boolean doesRunWhenDisabled) {
return new WrapperCommand(this) {
@Override
public boolean runsWhenDisabled() {
@@ -328,7 +395,7 @@ public interface Command {
* @param interruptBehavior the desired interrupt behavior
* @return the decorated command
*/
default WrapperCommand withInterruptBehavior(InterruptionBehavior interruptBehavior) {
public WrapperCommand withInterruptBehavior(InterruptionBehavior interruptBehavior) {
return new WrapperCommand(this) {
@Override
public InterruptionBehavior getInterruptionBehavior() {
@@ -345,7 +412,7 @@ public interface Command {
* interrupted.
* @return the decorated command
*/
default WrapperCommand finallyDo(BooleanConsumer end) {
public WrapperCommand finallyDo(BooleanConsumer end) {
requireNonNullParam(end, "end", "Command.finallyDo()");
return new WrapperCommand(this) {
@Override
@@ -363,7 +430,7 @@ public interface Command {
* @param handler a lambda to run when the command is interrupted
* @return the decorated command
*/
default WrapperCommand handleInterrupt(Runnable handler) {
public WrapperCommand handleInterrupt(Runnable handler) {
requireNonNullParam(handler, "handler", "Command.handleInterrupt()");
return finallyDo(
interrupted -> {
@@ -374,7 +441,7 @@ public interface Command {
}
/** Schedules this command. */
default void schedule() {
public void schedule() {
CommandScheduler.getInstance().schedule(this);
}
@@ -384,7 +451,7 @@ public interface Command {
*
* @see CommandScheduler#cancel(Command...)
*/
default void cancel() {
public void cancel() {
CommandScheduler.getInstance().cancel(this);
}
@@ -394,7 +461,7 @@ public interface Command {
*
* @return Whether the command is scheduled.
*/
default boolean isScheduled() {
public boolean isScheduled() {
return CommandScheduler.getInstance().isScheduled(this);
}
@@ -404,7 +471,7 @@ public interface Command {
* @param requirement the subsystem to inquire about
* @return whether the subsystem is required
*/
default boolean hasRequirement(Subsystem requirement) {
public boolean hasRequirement(Subsystem requirement) {
return getRequirements().contains(requirement);
}
@@ -414,7 +481,7 @@ public interface Command {
* @return a variant of {@link InterruptionBehavior}, defaulting to {@link
* InterruptionBehavior#kCancelSelf kCancelSelf}.
*/
default InterruptionBehavior getInterruptionBehavior() {
public InterruptionBehavior getInterruptionBehavior() {
return InterruptionBehavior.kCancelSelf;
}
@@ -424,43 +491,52 @@ public interface Command {
*
* @return whether the command should run when the robot is disabled
*/
default boolean runsWhenDisabled() {
public boolean runsWhenDisabled() {
return false;
}
/**
* Gets the name of this Command. Defaults to the simple class name if not overridden.
*
* @return The display name of the Command
*/
default String getName() {
return this.getClass().getSimpleName();
}
/**
* Sets the name of this Command. Nullop if not overridden.
*
* @param name The display name of the Command.
*/
default void setName(String name) {}
/**
* Decorates this Command with a name.
*
* @param name name
* @return the decorated Command
*/
default WrapperCommand withName(String name) {
public WrapperCommand withName(String name) {
WrapperCommand wrapper = new WrapperCommand(Command.this) {};
wrapper.setName(name);
return wrapper;
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Command");
builder.addStringProperty(".name", this::getName, null);
builder.addBooleanProperty(
"running",
this::isScheduled,
value -> {
if (value) {
if (!isScheduled()) {
schedule();
}
} else {
if (isScheduled()) {
cancel();
}
}
});
builder.addBooleanProperty(
".isParented", () -> CommandScheduler.getInstance().isComposed(this), null);
builder.addStringProperty(
"interruptBehavior", () -> getInterruptionBehavior().toString(), null);
builder.addBooleanProperty("runsWhenDisabled", this::runsWhenDisabled, null);
}
/**
* An enum describing the command's behavior when another command with a shared requirement is
* scheduled.
*/
enum InterruptionBehavior {
public enum InterruptionBehavior {
/**
* This command ends, {@link #end(boolean) end(true)} is called, and the incoming command is
* scheduled normally.

View File

@@ -4,107 +4,16 @@
package edu.wpi.first.wpilibj2.command;
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
import java.util.HashSet;
import java.util.Set;
/**
* A {@link Sendable} base class for {@link Command}s.
*
* <p>This class is provided by the NewCommands VendorDep
*
* @deprecated All functionality provided by {@link CommandBase} has been merged into {@link
* Command}. Use {@link Command} instead.
*/
public abstract class CommandBase implements Sendable, Command {
protected Set<Subsystem> m_requirements = new HashSet<>();
protected CommandBase() {
String name = getClass().getName();
SendableRegistry.add(this, name.substring(name.lastIndexOf('.') + 1));
}
/**
* Adds the specified subsystems to the requirements of the command. The scheduler will prevent
* two commands that require the same subsystem from being scheduled simultaneously.
*
* <p>Note that the scheduler determines the requirements of a command when it is scheduled, so
* this method should normally be called from the command's constructor.
*
* @param requirements the requirements to add
*/
public final void addRequirements(Subsystem... requirements) {
for (Subsystem requirement : requirements) {
m_requirements.add(requireNonNullParam(requirement, "requirement", "addRequirements"));
}
}
@Override
public Set<Subsystem> getRequirements() {
return m_requirements;
}
@Override
public String getName() {
return SendableRegistry.getName(this);
}
/**
* Sets the name of this Command.
*
* @param name name
*/
@Override
public void setName(String name) {
SendableRegistry.setName(this, name);
}
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
public String getSubsystem() {
return SendableRegistry.getSubsystem(this);
}
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
public void setSubsystem(String subsystem) {
SendableRegistry.setSubsystem(this, subsystem);
}
/**
* Initializes this sendable. Useful for allowing implementations to easily extend SendableBase.
*
* @param builder the builder used to construct this sendable
*/
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Command");
builder.addStringProperty(".name", this::getName, null);
builder.addBooleanProperty(
"running",
this::isScheduled,
value -> {
if (value) {
if (!isScheduled()) {
schedule();
}
} else {
if (isScheduled()) {
cancel();
}
}
});
builder.addBooleanProperty(
".isParented", () -> CommandScheduler.getInstance().isComposed(this), null);
builder.addStringProperty(
"interruptBehavior", () -> getInterruptionBehavior().toString(), null);
builder.addBooleanProperty("runsWhenDisabled", this::runsWhenDisabled, null);
}
}
@Deprecated(since = "2024", forRemoval = true)
@SuppressWarnings("PMD.AbstractClassWithoutAnyMethod")
public abstract class CommandBase extends Command {}

View File

@@ -362,6 +362,15 @@ public final class CommandScheduler implements NTSendable, AutoCloseable {
m_subsystems.keySet().removeAll(Set.of(subsystems));
}
/**
* Un-registers all registered Subsystems with the scheduler. All currently registered subsystems
* will no longer have their periodic block called, and will not have their default command
* scheduled.
*/
public void unregisterAllSubsystems() {
m_subsystems.clear();
}
/**
* Sets the default command for a subsystem. Registers that subsystem if it is not already
* registered. Default commands will run whenever there is no other command currently scheduled

View File

@@ -21,7 +21,7 @@ public final class Commands {
*
* @return the command
*/
public static CommandBase none() {
public static Command none() {
return new InstantCommand();
}
@@ -35,7 +35,7 @@ public final class Commands {
* @return the command
* @see InstantCommand
*/
public static CommandBase runOnce(Runnable action, Subsystem... requirements) {
public static Command runOnce(Runnable action, Subsystem... requirements) {
return new InstantCommand(action, requirements);
}
@@ -47,7 +47,7 @@ public final class Commands {
* @return the command
* @see RunCommand
*/
public static CommandBase run(Runnable action, Subsystem... requirements) {
public static Command run(Runnable action, Subsystem... requirements) {
return new RunCommand(action, requirements);
}
@@ -61,7 +61,7 @@ public final class Commands {
* @return the command
* @see StartEndCommand
*/
public static CommandBase startEnd(Runnable start, Runnable end, Subsystem... requirements) {
public static Command startEnd(Runnable start, Runnable end, Subsystem... requirements) {
return new StartEndCommand(start, end, requirements);
}
@@ -74,7 +74,7 @@ public final class Commands {
* @param requirements subsystems the action requires
* @return the command
*/
public static CommandBase runEnd(Runnable run, Runnable end, Subsystem... requirements) {
public static Command runEnd(Runnable run, Runnable end, Subsystem... requirements) {
requireNonNullParam(end, "end", "Command.runEnd");
return new FunctionalCommand(
() -> {}, run, interrupted -> end.run(), () -> false, requirements);
@@ -87,7 +87,7 @@ public final class Commands {
* @return the command
* @see PrintCommand
*/
public static CommandBase print(String message) {
public static Command print(String message) {
return new PrintCommand(message);
}
@@ -100,7 +100,7 @@ public final class Commands {
* @return the command
* @see WaitCommand
*/
public static CommandBase waitSeconds(double seconds) {
public static Command waitSeconds(double seconds) {
return new WaitCommand(seconds);
}
@@ -111,7 +111,7 @@ public final class Commands {
* @return the command
* @see WaitUntilCommand
*/
public static CommandBase waitUntil(BooleanSupplier condition) {
public static Command waitUntil(BooleanSupplier condition) {
return new WaitUntilCommand(condition);
}
@@ -126,7 +126,7 @@ public final class Commands {
* @return the command
* @see ConditionalCommand
*/
public static CommandBase either(Command onTrue, Command onFalse, BooleanSupplier selector) {
public static Command either(Command onTrue, Command onFalse, BooleanSupplier selector) {
return new ConditionalCommand(onTrue, onFalse, selector);
}
@@ -138,7 +138,7 @@ public final class Commands {
* @return the command
* @see SelectCommand
*/
public static CommandBase select(Map<Object, Command> commands, Supplier<Object> selector) {
public static Command select(Map<Object, Command> commands, Supplier<Object> selector) {
return new SelectCommand(commands, selector);
}
@@ -149,7 +149,7 @@ public final class Commands {
* @return the command group
* @see SequentialCommandGroup
*/
public static CommandBase sequence(Command... commands) {
public static Command sequence(Command... commands) {
return new SequentialCommandGroup(commands);
}
@@ -164,7 +164,7 @@ public final class Commands {
* @see SequentialCommandGroup
* @see Command#repeatedly()
*/
public static CommandBase repeatingSequence(Command... commands) {
public static Command repeatingSequence(Command... commands) {
return sequence(commands).repeatedly();
}
@@ -175,7 +175,7 @@ public final class Commands {
* @return the command
* @see ParallelCommandGroup
*/
public static CommandBase parallel(Command... commands) {
public static Command parallel(Command... commands) {
return new ParallelCommandGroup(commands);
}
@@ -187,7 +187,7 @@ public final class Commands {
* @return the command group
* @see ParallelRaceGroup
*/
public static CommandBase race(Command... commands) {
public static Command race(Command... commands) {
return new ParallelRaceGroup(commands);
}
@@ -200,7 +200,7 @@ public final class Commands {
* @return the command group
* @see ParallelDeadlineGroup
*/
public static CommandBase deadline(Command deadline, Command... commands) {
public static Command deadline(Command deadline, Command... commands) {
return new ParallelDeadlineGroup(deadline, commands);
}

View File

@@ -19,7 +19,7 @@ import java.util.function.BooleanSupplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ConditionalCommand extends CommandBase {
public class ConditionalCommand extends Command {
private final Command m_onTrue;
private final Command m_onFalse;
private final BooleanSupplier m_condition;

View File

@@ -17,7 +17,7 @@ import java.util.function.Consumer;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class FunctionalCommand extends CommandBase {
public class FunctionalCommand extends Command {
protected final Runnable m_onInit;
protected final Runnable m_onExecute;
protected final Consumer<Boolean> m_onEnd;

View File

@@ -38,7 +38,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class MecanumControllerCommand extends CommandBase {
public class MecanumControllerCommand extends Command {
private final Timer m_timer = new Timer();
private final boolean m_usePID;
private final Trajectory m_trajectory;

View File

@@ -17,7 +17,7 @@ import edu.wpi.first.wpilibj.Notifier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class NotifierCommand extends CommandBase {
public class NotifierCommand extends Command {
protected final Notifier m_notifier;
protected final double m_period;

View File

@@ -18,7 +18,7 @@ import java.util.function.DoubleSupplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class PIDCommand extends CommandBase {
public class PIDCommand extends Command {
protected final PIDController m_controller;
protected DoubleSupplier m_measurement;
protected DoubleSupplier m_setpoint;

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 SubsystemBase {
public abstract class PIDSubsystem extends Subsystem {
protected final PIDController m_controller;
protected boolean m_enabled;

View File

@@ -17,7 +17,7 @@ import java.util.Map;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ParallelCommandGroup extends CommandBase {
public class ParallelCommandGroup extends Command {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;

View File

@@ -20,7 +20,7 @@ import java.util.Map;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ParallelDeadlineGroup extends CommandBase {
public class ParallelDeadlineGroup extends Command {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;

View File

@@ -18,7 +18,7 @@ import java.util.Set;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ParallelRaceGroup extends CommandBase {
public class ParallelRaceGroup extends Command {
private final Set<Command> m_commands = new HashSet<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;

View File

@@ -20,7 +20,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ProfiledPIDCommand extends CommandBase {
public class ProfiledPIDCommand extends Command {
protected final ProfiledPIDController m_controller;
protected DoubleSupplier m_measurement;
protected Supplier<State> m_goal;

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 SubsystemBase {
public abstract class ProfiledPIDSubsystem extends Subsystem {
protected final ProfiledPIDController m_controller;
protected boolean m_enabled;

View File

@@ -15,7 +15,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ProxyCommand extends CommandBase {
public class ProxyCommand extends Command {
private final Supplier<Command> m_supplier;
private Command m_command;

View File

@@ -33,7 +33,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class RamseteCommand extends CommandBase {
public class RamseteCommand extends Command {
private final Timer m_timer = new Timer();
private final boolean m_usePID;
private final Trajectory m_trajectory;

View File

@@ -19,7 +19,7 @@ import edu.wpi.first.util.sendable.SendableBuilder;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class RepeatCommand extends CommandBase {
public class RepeatCommand extends Command {
protected final Command m_command;
private boolean m_ended;

View File

@@ -13,7 +13,7 @@ import java.util.Set;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class ScheduleCommand extends CommandBase {
public class ScheduleCommand extends Command {
private final Set<Command> m_toSchedule;
/**

View File

@@ -20,7 +20,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class SelectCommand extends CommandBase {
public class SelectCommand extends Command {
private final Map<Object, Command> m_commands;
private final Supplier<Object> m_selector;
private Command m_selectedCommand;

View File

@@ -17,7 +17,7 @@ import java.util.List;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class SequentialCommandGroup extends CommandBase {
public class SequentialCommandGroup extends Command {
private final List<Command> m_commands = new ArrayList<>();
private int m_currentCommandIndex = -1;
private boolean m_runWhenDisabled = true;

View File

@@ -4,6 +4,10 @@
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
@@ -13,29 +17,34 @@ package edu.wpi.first.wpilibj2.command;
* 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 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>Subsystems are automatically registered with the default scheduler in order for the {@link
* Subsystem#periodic()} method to be called.
*
* <p>This class is provided by the NewCommands VendorDep
*/
public interface Subsystem {
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);
}
/**
* 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.
*/
default void periodic() {}
public 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.
*/
default void simulationPeriodic() {}
public void simulationPeriodic() {}
/**
* Sets the default {@link Command} of the subsystem. The default command will be automatically
@@ -46,7 +55,7 @@ public interface Subsystem {
*
* @param defaultCommand the default command to associate with this subsystem
*/
default void setDefaultCommand(Command defaultCommand) {
public void setDefaultCommand(Command defaultCommand) {
CommandScheduler.getInstance().setDefaultCommand(this, defaultCommand);
}
@@ -54,7 +63,7 @@ public interface Subsystem {
* Removes the default command for the subsystem. This will not cancel the default command if it
* is currently running.
*/
default void removeDefaultCommand() {
public void removeDefaultCommand() {
CommandScheduler.getInstance().removeDefaultCommand(this);
}
@@ -64,7 +73,7 @@ public interface Subsystem {
*
* @return the default command associated with this subsystem
*/
default Command getDefaultCommand() {
public Command getDefaultCommand() {
return CommandScheduler.getInstance().getDefaultCommand(this);
}
@@ -74,15 +83,51 @@ public interface Subsystem {
*
* @return the scheduled command currently requiring this subsystem
*/
default Command getCurrentCommand() {
public 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.
*/
default void register() {
public void register() {
CommandScheduler.getInstance().registerSubsystem(this);
}
@@ -93,7 +138,7 @@ public interface Subsystem {
* @return the command
* @see InstantCommand
*/
default CommandBase runOnce(Runnable action) {
public Command runOnce(Runnable action) {
return Commands.runOnce(action, this);
}
@@ -105,7 +150,7 @@ public interface Subsystem {
* @return the command
* @see RunCommand
*/
default CommandBase run(Runnable action) {
public Command run(Runnable action) {
return Commands.run(action, this);
}
@@ -118,7 +163,7 @@ public interface Subsystem {
* @return the command
* @see StartEndCommand
*/
default CommandBase startEnd(Runnable start, Runnable end) {
public Command startEnd(Runnable start, Runnable end) {
return Commands.startEnd(start, end, this);
}
@@ -130,7 +175,33 @@ public interface Subsystem {
* @param end the action to run on interrupt
* @return the command
*/
default CommandBase runEnd(Runnable run, Runnable end) {
public 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,84 +4,15 @@
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.
*/
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);
}
}
@Deprecated(since = "2024", forRemoval = true)
@SuppressWarnings("PMD.AbstractClassWithoutAnyMethod")
public abstract class SubsystemBase extends Subsystem {}

View File

@@ -31,7 +31,7 @@ import java.util.function.Supplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class SwerveControllerCommand extends CommandBase {
public class SwerveControllerCommand extends Command {
private final Timer m_timer = new Timer();
private final Trajectory m_trajectory;
private final Supplier<Pose2d> m_pose;

View File

@@ -16,7 +16,7 @@ import java.util.function.Consumer;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class TrapezoidProfileCommand extends CommandBase {
public class TrapezoidProfileCommand extends Command {
private final TrapezoidProfile m_profile;
private final Consumer<State> m_output;

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 SubsystemBase {
public abstract class TrapezoidProfileSubsystem extends Subsystem {
private final double m_period;
private final TrapezoidProfile.Constraints m_constraints;

View File

@@ -13,7 +13,7 @@ import edu.wpi.first.wpilibj.Timer;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class WaitCommand extends CommandBase {
public class WaitCommand extends Command {
protected Timer m_timer = new Timer();
private final double m_duration;

View File

@@ -15,7 +15,7 @@ import java.util.function.BooleanSupplier;
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class WaitUntilCommand extends CommandBase {
public class WaitUntilCommand extends Command {
private final BooleanSupplier m_condition;
/**

View File

@@ -14,7 +14,7 @@ import java.util.Set;
* added to any other composition or scheduled individually, and the composition requires all
* subsystems its components require.
*/
public abstract class WrapperCommand extends CommandBase {
public abstract class WrapperCommand extends Command {
protected final Command m_command;
/**

View File

@@ -4,6 +4,9 @@
#include "frc2/command/Command.h"
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
#include "frc2/command/CommandHelper.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/ConditionalCommand.h"
@@ -19,6 +22,10 @@
using namespace frc2;
Command::Command() {
wpi::SendableRegistry::Add(this, GetTypeName(*this));
}
Command::~Command() {
CommandScheduler::GetInstance().Cancel(this);
}
@@ -32,6 +39,42 @@ void Command::Initialize() {}
void Command::Execute() {}
void Command::End(bool interrupted) {}
wpi::SmallSet<Subsystem*, 4> Command::GetRequirements() const {
return m_requirements;
}
void Command::AddRequirements(std::initializer_list<Subsystem*> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void Command::AddRequirements(std::span<Subsystem* const> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void Command::AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void Command::AddRequirements(Subsystem* requirement) {
m_requirements.insert(requirement);
}
void Command::SetName(std::string_view name) {
wpi::SendableRegistry::SetName(this, name);
}
std::string Command::GetName() const {
return wpi::SendableRegistry::GetName(this);
}
std::string Command::GetSubsystem() const {
return wpi::SendableRegistry::GetSubsystem(this);
}
void Command::SetSubsystem(std::string_view subsystem) {
wpi::SendableRegistry::SetSubsystem(this, subsystem);
}
CommandPtr Command::WithTimeout(units::second_t duration) && {
return std::move(*this).ToPtr().WithTimeout(duration);
}
@@ -125,12 +168,6 @@ bool Command::HasRequirement(Subsystem* requirement) const {
return hasRequirement;
}
std::string Command::GetName() const {
return GetTypeName(*this);
}
void Command::SetName(std::string_view name) {}
bool Command::IsComposed() const {
return m_isComposed;
}
@@ -139,6 +176,39 @@ void Command::SetComposed(bool isComposed) {
m_isComposed = isComposed;
}
void Command::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Command");
builder.AddStringProperty(
".name", [this] { return GetName(); }, nullptr);
builder.AddBooleanProperty(
"running", [this] { return IsScheduled(); },
[this](bool value) {
bool isScheduled = IsScheduled();
if (value && !isScheduled) {
Schedule();
} else if (!value && isScheduled) {
Cancel();
}
});
builder.AddBooleanProperty(
".isParented", [this] { return IsComposed(); }, nullptr);
builder.AddStringProperty(
"interruptBehavior",
[this] {
switch (GetInterruptionBehavior()) {
case Command::InterruptionBehavior::kCancelIncoming:
return "kCancelIncoming";
case Command::InterruptionBehavior::kCancelSelf:
return "kCancelSelf";
default:
return "Invalid";
}
},
nullptr);
builder.AddBooleanProperty(
"runsWhenDisabled", [this] { return RunsWhenDisabled(); }, nullptr);
}
namespace frc2 {
bool RequirementsDisjoint(Command* first, Command* second) {
bool disjoint = true;

View File

@@ -3,82 +3,3 @@
// the WPILib BSD license file in the root directory of this project.
#include "frc2/command/CommandBase.h"
#include <wpi/sendable/SendableBuilder.h>
#include <wpi/sendable/SendableRegistry.h>
using namespace frc2;
CommandBase::CommandBase() {
wpi::SendableRegistry::Add(this, GetTypeName(*this));
}
void CommandBase::AddRequirements(
std::initializer_list<Subsystem*> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void CommandBase::AddRequirements(std::span<Subsystem* const> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void CommandBase::AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements) {
m_requirements.insert(requirements.begin(), requirements.end());
}
void CommandBase::AddRequirements(Subsystem* requirement) {
m_requirements.insert(requirement);
}
wpi::SmallSet<Subsystem*, 4> CommandBase::GetRequirements() const {
return m_requirements;
}
void CommandBase::SetName(std::string_view name) {
wpi::SendableRegistry::SetName(this, name);
}
std::string CommandBase::GetName() const {
return wpi::SendableRegistry::GetName(this);
}
std::string CommandBase::GetSubsystem() const {
return wpi::SendableRegistry::GetSubsystem(this);
}
void CommandBase::SetSubsystem(std::string_view subsystem) {
wpi::SendableRegistry::SetSubsystem(this, subsystem);
}
void CommandBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Command");
builder.AddStringProperty(
".name", [this] { return GetName(); }, nullptr);
builder.AddBooleanProperty(
"running", [this] { return IsScheduled(); },
[this](bool value) {
bool isScheduled = IsScheduled();
if (value && !isScheduled) {
Schedule();
} else if (!value && isScheduled) {
Cancel();
}
});
builder.AddBooleanProperty(
".isParented", [this] { return IsComposed(); }, nullptr);
builder.AddStringProperty(
"interruptBehavior",
[this] {
switch (GetInterruptionBehavior()) {
case Command::InterruptionBehavior::kCancelIncoming:
return "kCancelIncoming";
case Command::InterruptionBehavior::kCancelSelf:
return "kCancelSelf";
default:
return "Invalid";
}
},
nullptr);
builder.AddBooleanProperty(
"runsWhenDisabled", [this] { return RunsWhenDisabled(); }, nullptr);
}

View File

@@ -236,12 +236,12 @@ CommandPtr CommandPtr::WithName(std::string_view name) && {
return std::move(wrapper).ToPtr();
}
CommandBase* CommandPtr::get() const& {
Command* CommandPtr::get() const& {
AssertValid();
return m_ptr.get();
}
std::unique_ptr<CommandBase> CommandPtr::Unwrap() && {
std::unique_ptr<Command> CommandPtr::Unwrap() && {
AssertValid();
return std::move(m_ptr);
}

View File

@@ -291,6 +291,10 @@ void CommandScheduler::UnregisterSubsystem(
}
}
void CommandScheduler::UnregisterAllSubsystems() {
m_impl->subsystems.clear();
}
void CommandScheduler::SetDefaultCommand(Subsystem* subsystem,
CommandPtr&& defaultCommand) {
if (!defaultCommand.get()->HasRequirement(subsystem)) {

View File

@@ -66,7 +66,7 @@ Command::InterruptionBehavior ConditionalCommand::GetInterruptionBehavior()
}
void ConditionalCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddStringProperty(
"onTrue", [this] { return m_onTrue->GetName(); }, nullptr);
builder.AddStringProperty(

View File

@@ -97,7 +97,7 @@ void ParallelDeadlineGroup::SetDeadline(std::unique_ptr<Command>&& deadline) {
}
void ParallelDeadlineGroup::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddStringProperty(
"deadline", [this] { return m_deadline->GetName(); }, nullptr);

View File

@@ -41,7 +41,7 @@ bool ProxyCommand::IsFinished() {
}
void ProxyCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddStringProperty(
"proxied",
[this] {

View File

@@ -161,7 +161,7 @@ bool RamseteCommand::IsFinished() {
}
void RamseteCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddDoubleProperty(
"leftVelocity", [this] { return m_prevSpeeds.left.value(); }, nullptr);
builder.AddDoubleProperty(

View File

@@ -56,7 +56,7 @@ Command::InterruptionBehavior RepeatCommand::GetInterruptionBehavior() const {
}
void RepeatCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddStringProperty(
"command", [this] { return m_command->GetName(); }, nullptr);
}

View File

@@ -83,7 +83,7 @@ void SequentialCommandGroup::AddCommands(
}
void SequentialCommandGroup::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddIntegerProperty(
"index", [this] { return m_currentCommandIndex; }, nullptr);
}

View File

@@ -8,6 +8,12 @@
#include "frc2/command/Commands.h"
using namespace frc2;
Subsystem::Subsystem() {
wpi::SendableRegistry::AddLW(this, GetTypeName(*this));
CommandScheduler::GetInstance().RegisterSubsystem({this});
}
Subsystem::~Subsystem() {
CommandScheduler::GetInstance().UnregisterSubsystem(this);
}
@@ -33,6 +39,26 @@ Command* Subsystem::GetCurrentCommand() const {
return CommandScheduler::GetInstance().Requiring(this);
}
std::string Subsystem::GetName() const {
return wpi::SendableRegistry::GetName(this);
}
void Subsystem::SetName(std::string_view name) {
wpi::SendableRegistry::SetName(this, name);
}
std::string Subsystem::GetSubsystem() const {
return wpi::SendableRegistry::GetSubsystem(this);
}
void Subsystem::SetSubsystem(std::string_view name) {
wpi::SendableRegistry::SetSubsystem(this, name);
}
void Subsystem::AddChild(std::string name, wpi::Sendable* child) {
wpi::SendableRegistry::AddLW(child, GetSubsystem(), name);
}
void Subsystem::Register() {
return CommandScheduler::GetInstance().RegisterSubsystem(this);
}
@@ -54,3 +80,33 @@ CommandPtr Subsystem::RunEnd(std::function<void()> run,
std::function<void()> end) {
return cmd::RunEnd(std::move(run), std::move(end), {this});
}
void Subsystem::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(
".hasDefault", [this] { return GetDefaultCommand() != nullptr; },
nullptr);
builder.AddStringProperty(
".default",
[this]() -> std::string {
auto command = GetDefaultCommand();
if (command == nullptr) {
return "none";
}
return command->GetName();
},
nullptr);
builder.AddBooleanProperty(
".hasCommand", [this] { return GetCurrentCommand() != nullptr; },
nullptr);
builder.AddStringProperty(
".command",
[this]() -> std::string {
auto command = GetCurrentCommand();
if (command == nullptr) {
return "none";
}
return command->GetName();
},
nullptr);
}

View File

@@ -12,57 +12,4 @@
using namespace frc2;
SubsystemBase::SubsystemBase() {
wpi::SendableRegistry::AddLW(this, GetTypeName(*this));
CommandScheduler::GetInstance().RegisterSubsystem({this});
}
void SubsystemBase::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Subsystem");
builder.AddBooleanProperty(
".hasDefault", [this] { return GetDefaultCommand() != nullptr; },
nullptr);
builder.AddStringProperty(
".default",
[this]() -> std::string {
auto command = GetDefaultCommand();
if (command == nullptr) {
return "none";
}
return command->GetName();
},
nullptr);
builder.AddBooleanProperty(
".hasCommand", [this] { return GetCurrentCommand() != nullptr; },
nullptr);
builder.AddStringProperty(
".command",
[this]() -> std::string {
auto command = GetCurrentCommand();
if (command == nullptr) {
return "none";
}
return command->GetName();
},
nullptr);
}
std::string SubsystemBase::GetName() const {
return wpi::SendableRegistry::GetName(this);
}
void SubsystemBase::SetName(std::string_view name) {
wpi::SendableRegistry::SetName(this, name);
}
std::string SubsystemBase::GetSubsystem() const {
return wpi::SendableRegistry::GetSubsystem(this);
}
void SubsystemBase::SetSubsystem(std::string_view name) {
wpi::SendableRegistry::SetSubsystem(this, name);
}
void SubsystemBase::AddChild(std::string name, wpi::Sendable* child) {
wpi::SendableRegistry::AddLW(child, GetSubsystem(), name);
}
SubsystemBase::SubsystemBase() {}

View File

@@ -30,7 +30,7 @@ bool WaitCommand::RunsWhenDisabled() const {
}
void WaitCommand::InitSendable(wpi::SendableBuilder& builder) {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddDoubleProperty(
"duration", [this] { return m_duration.value(); }, nullptr);
}

View File

@@ -13,6 +13,7 @@
#include <units/time.h>
#include <wpi/Demangle.h>
#include <wpi/SmallSet.h>
#include <wpi/sendable/Sendable.h>
#include "frc2/command/Subsystem.h"
@@ -41,10 +42,9 @@ std::string GetTypeName(const T& type) {
* @see CommandScheduler
* @see CommandHelper
*/
class Command {
class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
public:
Command() = default;
virtual ~Command();
~Command() override;
Command(const Command&) = default;
Command& operator=(const Command& rhs);
@@ -92,7 +92,91 @@ class Command {
* @return the set of subsystems that are required
* @see InterruptionBehavior
*/
virtual wpi::SmallSet<Subsystem*, 4> GetRequirements() const = 0;
virtual wpi::SmallSet<Subsystem*, 4> GetRequirements() const;
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(std::initializer_list<Subsystem*> requirements);
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(std::span<Subsystem* const> requirements);
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);
/**
* Adds the specified Subsystem requirement to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirement the Subsystem requirement to add
*/
void AddRequirements(Subsystem* requirement);
/**
* Gets the name of this Command.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Command.
*
* @param name name
*/
void SetName(std::string_view name);
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
void SetSubsystem(std::string_view subsystem);
/**
* An enum describing the command's behavior when another command with a
@@ -345,28 +429,19 @@ class Command {
return InterruptionBehavior::kCancelSelf;
}
/**
* Gets the name of this Command. Defaults to the simple class name if not
* overridden.
*
* @return The display name of the Command
*/
virtual std::string GetName() const;
/**
* Sets the name of this Command. Nullop if not overridden.
*
* @param name The display name of the Command.
*/
virtual void SetName(std::string_view name);
/**
* Transfers ownership of this command to a unique pointer. Used for
* decorator methods.
*/
virtual CommandPtr ToPtr() && = 0;
void InitSendable(wpi::SendableBuilder& builder) override;
protected:
Command();
wpi::SmallSet<Subsystem*, 4> m_requirements;
/**
* Transfers ownership of this command to a unique pointer. Used for
* decorator methods.

View File

@@ -4,14 +4,7 @@
#pragma once
#include <initializer_list>
#include <span>
#include <string>
#include <string_view>
#include <wpi/SmallSet.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include <wpi/deprecated.h>
#include "frc2/command/Command.h"
@@ -20,106 +13,13 @@ namespace frc2 {
* A Sendable base class for Commands.
*
* This class is provided by the NewCommands VendorDep
*
* @deprecated All functionality provided by CommandBase has been merged into
* Command. Use Command instead.
*/
class CommandBase : public Command,
public wpi::Sendable,
public wpi::SendableHelper<CommandBase> {
public:
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(std::initializer_list<Subsystem*> requirements);
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(std::span<Subsystem* const> requirements);
/**
* Adds the specified Subsystem requirements to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirements the Subsystem requirements to add
*/
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);
/**
* Adds the specified Subsystem requirement to the command.
*
* The scheduler will prevent two commands that require the same subsystem
* from being scheduled simultaneously.
*
* Note that the scheduler determines the requirements of a command when it
* is scheduled, so this method should normally be called from the command's
* constructor.
*
* @param requirement the Subsystem requirement to add
*/
void AddRequirements(Subsystem* requirement);
/**
* Gets the Subsystem requirements of the command.
*
* @return the Command's Subsystem requirements
*/
wpi::SmallSet<Subsystem*, 4> GetRequirements() const override;
/**
* Sets the name of this Command.
*
* @param name name
*/
void SetName(std::string_view name) override;
/**
* Gets the name of this Command.
*
* @return Name
*/
std::string GetName() const override;
/**
* Gets the subsystem name of this Command.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Command.
*
* @param subsystem subsystem name
*/
void SetSubsystem(std::string_view subsystem);
void InitSendable(wpi::SendableBuilder& builder) override;
class [[deprecated("Use Command instead")]] CommandBase : public Command {
protected:
WPI_DEPRECATED("Use Command instead")
CommandBase();
wpi::SmallSet<Subsystem*, 4> m_requirements;
};
} // namespace frc2

View File

@@ -13,7 +13,7 @@
#include <utility>
#include <vector>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
namespace frc2 {
/**
@@ -28,7 +28,7 @@ namespace frc2 {
*/
class CommandPtr final {
public:
explicit CommandPtr(std::unique_ptr<CommandBase>&& command)
explicit CommandPtr(std::unique_ptr<Command>&& command)
: m_ptr(std::move(command)) {}
template <std::derived_from<Command> T>
@@ -269,15 +269,15 @@ class CommandPtr final {
/**
* Get a raw pointer to the held command.
*/
CommandBase* get() const&;
Command* get() const&;
// Prevent calls on a temporary, as the returned pointer would be invalid
CommandBase* get() && = delete;
Command* get() && = delete;
/**
* Convert to the underlying unique_ptr.
*/
std::unique_ptr<CommandBase> Unwrap() &&;
std::unique_ptr<Command> Unwrap() &&;
/**
* Schedules this command.
@@ -336,7 +336,7 @@ class CommandPtr final {
std::vector<CommandPtr>&& vec);
private:
std::unique_ptr<CommandBase> m_ptr;
std::unique_ptr<Command> m_ptr;
void AssertValid() const;
};

View File

@@ -158,6 +158,13 @@ class CommandScheduler final : public nt::NTSendable,
void UnregisterSubsystem(std::initializer_list<Subsystem*> subsystems);
void UnregisterSubsystem(std::span<Subsystem* const> subsystems);
/**
* Un-registers all registered Subsystems with the scheduler. All currently
* registered subsystems will no longer have their periodic block called, and
* will not have their default command scheduled.
*/
void UnregisterAllSubsystems();
/**
* Sets the default command for a subsystem. Registers that subsystem if it
* is not already registered. Default commands will run whenever there is no

View File

@@ -9,7 +9,7 @@
#include <memory>
#include <utility>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -26,8 +26,7 @@ namespace frc2 {
*
* @see ScheduleCommand
*/
class ConditionalCommand
: public CommandHelper<CommandBase, ConditionalCommand> {
class ConditionalCommand : public CommandHelper<Command, ConditionalCommand> {
public:
/**
* Creates a new ConditionalCommand.

View File

@@ -8,7 +8,7 @@
#include <initializer_list>
#include <span>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -21,7 +21,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class FunctionalCommand : public CommandHelper<CommandBase, FunctionalCommand> {
class FunctionalCommand : public CommandHelper<Command, FunctionalCommand> {
public:
/**
* Creates a new FunctionalCommand.

View File

@@ -23,7 +23,7 @@
#include <units/velocity.h>
#include <units/voltage.h>
#include "CommandBase.h"
#include "Command.h"
#include "CommandHelper.h"
#pragma once
@@ -51,7 +51,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
class MecanumControllerCommand
: public CommandHelper<CommandBase, MecanumControllerCommand> {
: public CommandHelper<Command, MecanumControllerCommand> {
public:
/**
* Constructs a new MecanumControllerCommand that when executed will follow

View File

@@ -11,7 +11,7 @@
#include <frc/Notifier.h>
#include <units/time.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -27,7 +27,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class NotifierCommand : public CommandHelper<CommandBase, NotifierCommand> {
class NotifierCommand : public CommandHelper<Command, NotifierCommand> {
public:
/**
* Creates a new NotifierCommand.

View File

@@ -10,7 +10,7 @@
#include <frc/controller/PIDController.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -24,7 +24,7 @@ namespace frc2 {
*
* @see PIDController
*/
class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
class PIDCommand : public CommandHelper<Command, PIDCommand> {
public:
/**
* Creates a new PIDCommand, which controls the given output with a

View File

@@ -6,7 +6,7 @@
#include <frc/controller/PIDController.h>
#include "frc2/command/SubsystemBase.h"
#include "frc2/command/Subsystem.h"
namespace frc2 {
/**
@@ -17,7 +17,7 @@ namespace frc2 {
*
* @see PIDController
*/
class PIDSubsystem : public SubsystemBase {
class PIDSubsystem : public Subsystem {
public:
/**
* Creates a new PIDSubsystem.

View File

@@ -33,7 +33,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
class ParallelCommandGroup
: public CommandHelper<CommandBase, ParallelCommandGroup> {
: public CommandHelper<Command, ParallelCommandGroup> {
public:
/**
* Creates a new ParallelCommandGroup. The given commands will be executed

View File

@@ -34,7 +34,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
class ParallelDeadlineGroup
: public CommandHelper<CommandBase, ParallelDeadlineGroup> {
: public CommandHelper<Command, ParallelDeadlineGroup> {
public:
/**
* Creates a new ParallelDeadlineGroup. The given commands (including the

View File

@@ -32,7 +32,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class ParallelRaceGroup : public CommandHelper<CommandBase, ParallelRaceGroup> {
class ParallelRaceGroup : public CommandHelper<Command, ParallelRaceGroup> {
public:
/**
* Creates a new ParallelCommandRace. The given commands will be executed

View File

@@ -12,7 +12,7 @@
#include <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -28,7 +28,7 @@ namespace frc2 {
*/
template <class Distance>
class ProfiledPIDCommand
: public CommandHelper<CommandBase, ProfiledPIDCommand<Distance>> {
: public CommandHelper<Command, ProfiledPIDCommand<Distance>> {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;

View File

@@ -7,7 +7,7 @@
#include <frc/controller/ProfiledPIDController.h>
#include <units/time.h>
#include "frc2/command/SubsystemBase.h"
#include "frc2/command/Subsystem.h"
namespace frc2 {
/**
@@ -19,7 +19,7 @@ namespace frc2 {
* @see ProfiledPIDController
*/
template <class Distance>
class ProfiledPIDSubsystem : public SubsystemBase {
class ProfiledPIDSubsystem : public Subsystem {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;

View File

@@ -9,7 +9,7 @@
#include <wpi/FunctionExtras.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/SetUtilities.h"
@@ -21,7 +21,7 @@ namespace frc2 {
*
* <p>This class is provided by the NewCommands VendorDep
*/
class ProxyCommand : public CommandHelper<CommandBase, ProxyCommand> {
class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
public:
/**
* Creates a new ProxyCommand that schedules the supplied command when

View File

@@ -19,7 +19,7 @@
#include <units/length.h>
#include <units/voltage.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -42,7 +42,7 @@ namespace frc2 {
* @see RamseteController
* @see Trajectory
*/
class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
class RamseteCommand : public CommandHelper<Command, RamseteCommand> {
public:
/**
* Constructs a new RamseteCommand that, when executed, will follow the

View File

@@ -13,7 +13,7 @@
#include <memory>
#include <utility>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -29,7 +29,7 @@ namespace frc2 {
*
* <p>This class is provided by the NewCommands VendorDep
*/
class RepeatCommand : public CommandHelper<CommandBase, RepeatCommand> {
class RepeatCommand : public CommandHelper<Command, RepeatCommand> {
public:
/**
* Creates a new RepeatCommand. Will run another command repeatedly,

View File

@@ -8,7 +8,7 @@
#include <wpi/SmallVector.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/SetUtilities.h"
@@ -21,7 +21,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class ScheduleCommand : public CommandHelper<CommandBase, ScheduleCommand> {
class ScheduleCommand : public CommandHelper<Command, ScheduleCommand> {
public:
/**
* Creates a new ScheduleCommand that schedules the given commands when

View File

@@ -18,7 +18,7 @@
#include <wpi/sendable/SendableBuilder.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/PrintCommand.h"
namespace frc2 {
@@ -35,7 +35,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
template <typename Key>
class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
class SelectCommand : public CommandHelper<Command, SelectCommand<Key>> {
public:
/**
* Creates a new SelectCommand.
@@ -113,7 +113,7 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
}
void InitSendable(wpi::SendableBuilder& builder) override {
CommandBase::InitSendable(builder);
Command::InitSendable(builder);
builder.AddStringProperty(
"selected",

View File

@@ -37,7 +37,7 @@ const size_t invalid_index = std::numeric_limits<size_t>::max();
* This class is provided by the NewCommands VendorDep
*/
class SequentialCommandGroup
: public CommandHelper<CommandBase, SequentialCommandGroup> {
: public CommandHelper<Command, SequentialCommandGroup> {
public:
/**
* Creates a new SequentialCommandGroup. The given commands will be run

View File

@@ -5,8 +5,11 @@
#pragma once
#include <concepts>
#include <string>
#include <utility>
#include <wpi/sendable/Sendable.h>
#include "frc2/command/CommandScheduler.h"
namespace frc2 {
@@ -23,22 +26,19 @@ class CommandPtr;
* subsystem should generally remain encapsulated and not be shared by other
* parts of the robot.
*
* <p>Subsystems must be registered with the scheduler with the
* <p>Subsystems are automatically registered with the scheduler with the
* CommandScheduler.RegisterSubsystem() method in order for the
* Periodic() method to be called. It is recommended that this method be called
* from the constructor of users' Subsystem implementations. The
* SubsystemBase class offers a simple base for user implementations
* that handles this.
* Periodic() method to be called.
*
* This class is provided by the NewCommands VendorDep
*
* @see Command
* @see CommandScheduler
* @see SubsystemBase
*/
class Subsystem {
class Subsystem : public wpi::Sendable, public wpi::SendableHelper<Subsystem> {
public:
virtual ~Subsystem();
~Subsystem() override;
/**
* This method is called periodically by the CommandScheduler. Useful for
* updating subsystem-specific state that you don't want to offload to a
@@ -110,6 +110,43 @@ class Subsystem {
*/
void Register();
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
void SetName(std::string_view name);
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Subsystem.
*
* @param name subsystem name
*/
void SetSubsystem(std::string_view name);
/**
* Associate a Sendable with this Subsystem.
* Also update the child's name.
*
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string name, wpi::Sendable* child);
/**
* Constructs a command that runs an action once and finishes. Requires this
* subsystem.
@@ -147,5 +184,10 @@ class Subsystem {
*/
[[nodiscard]]
CommandPtr RunEnd(std::function<void()> run, std::function<void()> end);
void InitSendable(wpi::SendableBuilder& builder) override;
protected:
Subsystem();
};
} // namespace frc2

View File

@@ -4,11 +4,7 @@
#pragma once
#include <string>
#include <string_view>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
#include <wpi/deprecated.h>
#include "frc2/command/Subsystem.h"
@@ -18,51 +14,13 @@ namespace frc2 {
* provides a more intuitive method for setting the default command.
*
* This class is provided by the NewCommands VendorDep
*
* @deprecated All functionality provided by SubsystemBase has been merged into
* Subsystem. Use Subsystem instead.
*/
class SubsystemBase : public Subsystem,
public wpi::Sendable,
public wpi::SendableHelper<SubsystemBase> {
public:
void InitSendable(wpi::SendableBuilder& builder) override;
/**
* Gets the name of this Subsystem.
*
* @return Name
*/
std::string GetName() const;
/**
* Sets the name of this Subsystem.
*
* @param name name
*/
void SetName(std::string_view name);
/**
* Gets the subsystem name of this Subsystem.
*
* @return Subsystem name
*/
std::string GetSubsystem() const;
/**
* Sets the subsystem name of this Subsystem.
*
* @param name subsystem name
*/
void SetSubsystem(std::string_view name);
/**
* Associate a Sendable with this Subsystem.
* Also update the child's name.
*
* @param name name to give child
* @param child sendable
*/
void AddChild(std::string name, wpi::Sendable* child);
class [[deprecated("Use Subsystem instead")]] SubsystemBase : public Subsystem {
protected:
WPI_DEPRECATED("Use Subsystem instead")
SubsystemBase();
};
} // namespace frc2

View File

@@ -21,7 +21,7 @@
#include <units/time.h>
#include <units/voltage.h>
#include "CommandBase.h"
#include "Command.h"
#include "CommandHelper.h"
#pragma once
@@ -51,7 +51,7 @@ namespace frc2 {
*/
template <size_t NumModules>
class SwerveControllerCommand
: public CommandHelper<CommandBase, SwerveControllerCommand<NumModules>> {
: public CommandHelper<Command, SwerveControllerCommand<NumModules>> {
using voltsecondspermeter =
units::compound_unit<units::voltage::volt, units::second,
units::inverse<units::meter>>;

View File

@@ -11,7 +11,7 @@
#include <frc/Timer.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -25,7 +25,7 @@ namespace frc2 {
*/
template <class Distance>
class TrapezoidProfileCommand
: public CommandHelper<CommandBase, TrapezoidProfileCommand<Distance>> {
: public CommandHelper<Command, TrapezoidProfileCommand<Distance>> {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;

View File

@@ -7,7 +7,7 @@
#include <frc/trajectory/TrapezoidProfile.h>
#include <units/time.h>
#include "frc2/command/SubsystemBase.h"
#include "frc2/command/Subsystem.h"
namespace frc2 {
/**
@@ -18,7 +18,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
template <class Distance>
class TrapezoidProfileSubsystem : public SubsystemBase {
class TrapezoidProfileSubsystem : public Subsystem {
using Distance_t = units::unit_t<Distance>;
using Velocity =
units::compound_unit<Distance, units::inverse<units::seconds>>;

View File

@@ -7,7 +7,7 @@
#include <frc/Timer.h>
#include <units/time.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -16,7 +16,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class WaitCommand : public CommandHelper<CommandBase, WaitCommand> {
class WaitCommand : public CommandHelper<Command, WaitCommand> {
public:
/**
* Creates a new WaitCommand. This command will do nothing, and end after the

View File

@@ -8,7 +8,7 @@
#include <units/time.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -18,7 +18,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class WaitUntilCommand : public CommandHelper<CommandBase, WaitUntilCommand> {
class WaitUntilCommand : public CommandHelper<Command, WaitUntilCommand> {
public:
/**
* Creates a new WaitUntilCommand that ends after a given condition becomes

View File

@@ -13,7 +13,7 @@
#include <memory>
#include <utility>
#include "frc2/command/CommandBase.h"
#include "frc2/command/Command.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -24,7 +24,7 @@ namespace frc2 {
* <p>Wrapped commands may only be used through the wrapper, trying to directly
* schedule them or add them to a group will throw an exception.
*/
class WrapperCommand : public CommandHelper<CommandBase, WrapperCommand> {
class WrapperCommand : public CommandHelper<Command, WrapperCommand> {
public:
/**
* Wrap a command.

View File

@@ -15,7 +15,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementInterruptTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
MockCommandHolder interruptedHolder = new MockCommandHolder(true, requirement);
Command interrupted = interruptedHolder.getMock();
@@ -42,7 +42,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementUninterruptibleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
Command notInterrupted =
new RunCommand(() -> {}, requirement)
@@ -61,7 +61,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void defaultCommandRequirementErrorTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem system = new SubsystemBase() {};
Subsystem system = new Subsystem() {};
Command missingRequirement = new WaitUntilCommand(() -> false);

View File

@@ -21,7 +21,7 @@ class CommandSendableButtonTest extends CommandTestBase {
private AtomicInteger m_schedule;
private AtomicInteger m_cancel;
private BooleanPublisher m_publish;
private CommandBase m_command;
private Command m_command;
@BeforeEach
void setUp() {

View File

@@ -23,6 +23,7 @@ public class CommandTestBase {
CommandScheduler.getInstance().enable();
CommandScheduler.getInstance().getActiveButtonLoop().clear();
CommandScheduler.getInstance().clearComposedCommands();
CommandScheduler.getInstance().unregisterAllSubsystems();
setDSEnabled(true);
}

View File

@@ -46,9 +46,9 @@ class ConditionalCommandTest extends CommandTestBase {
@Test
void conditionalCommandRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -14,7 +14,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem hasDefaultCommand = new SubsystemBase() {};
Subsystem hasDefaultCommand = new Subsystem() {};
MockCommandHolder defaultHolder = new MockCommandHolder(true, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();
@@ -29,7 +29,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandInterruptResumeTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem hasDefaultCommand = new SubsystemBase() {};
Subsystem hasDefaultCommand = new Subsystem() {};
MockCommandHolder defaultHolder = new MockCommandHolder(true, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();
@@ -54,7 +54,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandDisableResumeTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem hasDefaultCommand = new SubsystemBase() {};
Subsystem hasDefaultCommand = new Subsystem() {};
MockCommandHolder defaultHolder = new MockCommandHolder(false, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();

View File

@@ -90,10 +90,10 @@ class ParallelCommandGroupTest extends CommandTestBase
@Test
void parallelGroupRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
Subsystem system4 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -115,9 +115,9 @@ class ParallelCommandGroupTest extends CommandTestBase
@Test
void parallelGroupRequirementErrorTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();

View File

@@ -87,10 +87,10 @@ class ParallelDeadlineGroupTest extends CommandTestBase
@Test
void parallelDeadlineRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
Subsystem system4 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -112,9 +112,9 @@ class ParallelDeadlineGroupTest extends CommandTestBase
@Test
void parallelDeadlineRequirementErrorTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();

View File

@@ -92,10 +92,10 @@ class ParallelRaceGroupTest extends CommandTestBase
@Test
void parallelRaceRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
Subsystem system4 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -117,9 +117,9 @@ class ParallelRaceGroupTest extends CommandTestBase
@Test
void parallelRaceRequirementErrorTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();
@@ -131,8 +131,8 @@ class ParallelRaceGroupTest extends CommandTestBase
@Test
void parallelRaceOnlyCallsEndOnceTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1);
Command command1 = command1Holder.getMock();

View File

@@ -48,7 +48,7 @@ class SchedulerTest extends CommandTestBase {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger(0);
Subsystem system =
new SubsystemBase() {
new Subsystem() {
@Override
public void periodic() {
counter.incrementAndGet();
@@ -67,7 +67,7 @@ class SchedulerTest extends CommandTestBase {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger(0);
Subsystem system =
new SubsystemBase() {
new Subsystem() {
@Override
public void periodic() {
counter.incrementAndGet();

View File

@@ -25,9 +25,9 @@ class SchedulingRecursionTest extends CommandTestBase {
void cancelFromInitialize(InterruptionBehavior interruptionBehavior) {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean hasOtherRun = new AtomicBoolean();
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
Command selfCancels =
new CommandBase() {
new Command() {
{
addRequirements(requirement);
}
@@ -62,9 +62,9 @@ class SchedulingRecursionTest extends CommandTestBase {
void defaultCommandGetsRescheduledAfterSelfCanceling(InterruptionBehavior interruptionBehavior) {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean hasOtherRun = new AtomicBoolean();
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
Command selfCancels =
new CommandBase() {
new Command() {
{
addRequirements(requirement);
}
@@ -100,7 +100,7 @@ class SchedulingRecursionTest extends CommandTestBase {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger();
Command selfCancels =
new CommandBase() {
new Command() {
@Override
public void end(boolean interrupted) {
counter.incrementAndGet();
@@ -119,10 +119,10 @@ class SchedulingRecursionTest extends CommandTestBase {
void scheduleFromEndCancel() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger();
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
InstantCommand other = new InstantCommand(() -> {}, requirement);
Command selfCancels =
new CommandBase() {
new Command() {
{
addRequirements(requirement);
}
@@ -146,10 +146,10 @@ class SchedulingRecursionTest extends CommandTestBase {
void scheduleFromEndInterrupt() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger();
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
InstantCommand other = new InstantCommand(() -> {}, requirement);
Command selfCancels =
new CommandBase() {
new Command() {
{
addRequirements(requirement);
}
@@ -175,11 +175,11 @@ class SchedulingRecursionTest extends CommandTestBase {
void scheduleInitializeFromDefaultCommand(InterruptionBehavior interruptionBehavior) {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicInteger counter = new AtomicInteger();
Subsystem requirement = new SubsystemBase() {};
Subsystem requirement = new Subsystem() {};
Command other =
new InstantCommand(() -> {}, requirement).withInterruptBehavior(interruptionBehavior);
Command defaultCommand =
new CommandBase() {
new Command() {
{
addRequirements(requirement);
}

View File

@@ -75,10 +75,10 @@ class SelectCommandTest extends CommandTestBase implements MultiCompositionTestB
@Test
void selectCommandRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
Subsystem system4 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -100,10 +100,10 @@ class SequentialCommandGroupTest extends CommandTestBase
@Test
void sequentialGroupRequirementTest() {
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
Subsystem system1 = new Subsystem() {};
Subsystem system2 = new Subsystem() {};
Subsystem system3 = new Subsystem() {};
Subsystem system4 = new Subsystem() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -11,12 +11,14 @@ CommandTestBase::CommandTestBase() {
scheduler.CancelAll();
scheduler.Enable();
scheduler.GetActiveButtonLoop()->Clear();
scheduler.UnregisterAllSubsystems();
SetDSEnabled(true);
}
CommandTestBase::~CommandTestBase() {
CommandScheduler::GetInstance().GetActiveButtonLoop()->Clear();
CommandScheduler::GetInstance().UnregisterAllSubsystems();
}
CommandScheduler CommandTestBase::GetScheduler() {

View File

@@ -12,14 +12,14 @@
#include "frc2/command/CommandHelper.h"
#include "frc2/command/CommandScheduler.h"
#include "frc2/command/SetUtilities.h"
#include "frc2/command/SubsystemBase.h"
#include "frc2/command/Subsystem.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "make_vector.h"
namespace frc2 {
class TestSubsystem : public SubsystemBase {
class TestSubsystem : public Subsystem {
public:
explicit TestSubsystem(std::function<void()> periodic = [] {})
: m_periodic{periodic} {}
@@ -32,7 +32,7 @@ class TestSubsystem : public SubsystemBase {
/**
* NOTE: Moving mock objects causes EXPECT_CALL to not work correctly!
*/
class MockCommand : public CommandHelper<CommandBase, MockCommand> {
class MockCommand : public CommandHelper<Command, MockCommand> {
public:
MOCK_CONST_METHOD0(GetRequirements, wpi::SmallSet<Subsystem*, 4>());
MOCK_METHOD0(IsFinished, bool());
@@ -107,12 +107,14 @@ class CommandTestBaseWithParam : public ::testing::TestWithParam<T> {
scheduler.CancelAll();
scheduler.Enable();
scheduler.GetActiveButtonLoop()->Clear();
scheduler.UnregisterAllSubsystems();
SetDSEnabled(true);
}
~CommandTestBaseWithParam() override {
CommandScheduler::GetInstance().GetActiveButtonLoop()->Clear();
CommandScheduler::GetInstance().UnregisterAllSubsystems();
}
protected:

View File

@@ -17,6 +17,7 @@
#include <frc/simulation/SimHooks.h>
#include <frc/trajectory/TrajectoryGenerator.h>
#include "CommandTestBase.h"
#include "gtest/gtest.h"
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
@@ -87,7 +88,7 @@ class MecanumControllerCommandTest : public ::testing::Test {
};
TEST_F(MecanumControllerCommandTest, ReachesReference) {
frc2::Subsystem subsystem;
frc2::TestSubsystem subsystem;
auto waypoints =
std::vector{frc::Pose2d{0_m, 0_m, 0_rad}, frc::Pose2d{1_m, 5_m, 3_rad}};

View File

@@ -14,7 +14,7 @@ class SchedulingRecursionTest
: public CommandTestBaseWithParam<Command::InterruptionBehavior> {};
class SelfCancellingCommand
: public CommandHelper<CommandBase, SelfCancellingCommand> {
: public CommandHelper<Command, SelfCancellingCommand> {
public:
SelfCancellingCommand(CommandScheduler* scheduler, Subsystem* requirement,
Command::InterruptionBehavior interruptionBehavior =
@@ -76,7 +76,7 @@ TEST_P(SchedulingRecursionTest,
EXPECT_TRUE(hasOtherRun);
}
class CancelEndCommand : public CommandHelper<CommandBase, CancelEndCommand> {
class CancelEndCommand : public CommandHelper<Command, CancelEndCommand> {
public:
CancelEndCommand(CommandScheduler* scheduler, int& counter)
: m_scheduler(scheduler), m_counter(counter) {}

View File

@@ -18,6 +18,7 @@
#include <frc/simulation/SimHooks.h>
#include <frc/trajectory/TrajectoryGenerator.h>
#include "CommandTestBase.h"
#include "gtest/gtest.h"
#define EXPECT_NEAR_UNITS(val1, val2, eps) \
@@ -72,7 +73,7 @@ class SwerveControllerCommandTest : public ::testing::Test {
};
TEST_F(SwerveControllerCommandTest, ReachesReference) {
frc2::Subsystem subsystem;
frc2::TestSubsystem subsystem;
auto waypoints =
std::vector{frc::Pose2d{0_m, 0_m, 0_rad}, frc::Pose2d{1_m, 5_m, 3_rad}};

View File

@@ -4,18 +4,18 @@
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/Command.h>
#include <frc2/command/CommandHelper.h>
/**
* An example command.
*
* <p>Note that this extends CommandHelper, rather extending CommandBase
* <p>Note that this extends CommandHelper, rather extending Command
* directly; this is crucially important, or else the decorator functions in
* Command will *not* work!
*/
class ReplaceMeCommand2
: public frc2::CommandHelper<frc2::CommandBase, ReplaceMeCommand2> {
: public frc2::CommandHelper<frc2::Command, ReplaceMeCommand2> {
public:
ReplaceMeCommand2();

View File

@@ -4,9 +4,9 @@
#pragma once
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
class ReplaceMeSubsystem2 : public frc2::SubsystemBase {
class ReplaceMeSubsystem2 : public frc2::Subsystem {
public:
ReplaceMeSubsystem2();

View File

@@ -8,11 +8,11 @@
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/MotorControllerGroup.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
#include "Constants.h"
class DriveSubsystem : public frc2::SubsystemBase {
class DriveSubsystem : public frc2::Subsystem {
public:
DriveSubsystem();

View File

@@ -11,11 +11,11 @@
#include <frc/motorcontrol/MotorControllerGroup.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/Commands.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
#include "Constants.h"
class DriveSubsystem : public frc2::SubsystemBase {
class DriveSubsystem : public frc2::Subsystem {
public:
DriveSubsystem();

View File

@@ -8,13 +8,13 @@
#include <frc/controller/SimpleMotorFeedforward.h>
#include <frc/drive/DifferentialDrive.h>
#include <frc/trajectory/TrapezoidProfile.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
#include <units/length.h>
#include "Constants.h"
#include "ExampleSmartMotorController.h"
class DriveSubsystem : public frc2::SubsystemBase {
class DriveSubsystem : public frc2::Subsystem {
public:
DriveSubsystem();

View File

@@ -8,11 +8,11 @@
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/MotorControllerGroup.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
#include "Constants.h"
class DriveSubsystem : public frc2::SubsystemBase {
class DriveSubsystem : public frc2::Subsystem {
public:
DriveSubsystem();

View File

@@ -4,7 +4,7 @@
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/Command.h>
#include <frc2/command/CommandHelper.h>
#include "subsystems/Claw.h"
@@ -12,7 +12,7 @@
/**
* Closes the claw until the limit switch is tripped.
*/
class CloseClaw : public frc2::CommandHelper<frc2::CommandBase, CloseClaw> {
class CloseClaw : public frc2::CommandHelper<frc2::Command, CloseClaw> {
public:
explicit CloseClaw(Claw& claw);
void Initialize() override;

View File

@@ -4,7 +4,7 @@
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/Command.h>
#include <frc2/command/CommandHelper.h>
#include "subsystems/Elevator.h"
@@ -17,7 +17,7 @@
* commands using the elevator should make sure they disable PID!
*/
class SetElevatorSetpoint
: public frc2::CommandHelper<frc2::CommandBase, SetElevatorSetpoint> {
: public frc2::CommandHelper<frc2::Command, SetElevatorSetpoint> {
public:
explicit SetElevatorSetpoint(double setpoint, Elevator& elevator);
void Initialize() override;

View File

@@ -4,7 +4,7 @@
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/Command.h>
#include <frc2/command/CommandHelper.h>
#include "subsystems/Wrist.h"
@@ -15,7 +15,7 @@
* Other commands using the wrist should make sure they disable PID!
*/
class SetWristSetpoint
: public frc2::CommandHelper<frc2::CommandBase, SetWristSetpoint> {
: public frc2::CommandHelper<frc2::Command, SetWristSetpoint> {
public:
explicit SetWristSetpoint(double setpoint, Wrist& wrist);
void Initialize() override;

View File

@@ -4,7 +4,7 @@
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/Command.h>
#include <frc2/command/CommandHelper.h>
#include "subsystems/Drivetrain.h"
@@ -12,7 +12,7 @@
/**
* Have the robot drive tank style using the PS3 Joystick until interrupted.
*/
class TankDrive : public frc2::CommandHelper<frc2::CommandBase, TankDrive> {
class TankDrive : public frc2::CommandHelper<frc2::Command, TankDrive> {
public:
TankDrive(std::function<double()> left, std::function<double()> right,
Drivetrain& drivetrain);

View File

@@ -6,14 +6,14 @@
#include <frc/DigitalInput.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
/**
* The claw subsystem is a simple system with a motor for opening and closing.
* If using stronger motors, you should probably use a sensor so that the
* motors don't stall.
*/
class Claw : public frc2::SubsystemBase {
class Claw : public frc2::Subsystem {
public:
Claw();

View File

@@ -10,7 +10,7 @@
#include <frc/drive/DifferentialDrive.h>
#include <frc/motorcontrol/MotorControllerGroup.h>
#include <frc/motorcontrol/PWMSparkMax.h>
#include <frc2/command/SubsystemBase.h>
#include <frc2/command/Subsystem.h>
namespace frc {
class Joystick;
@@ -21,7 +21,7 @@ class Joystick;
* the robots chassis. These include four drive motors, a left and right encoder
* and a gyro.
*/
class Drivetrain : public frc2::SubsystemBase {
class Drivetrain : public frc2::Subsystem {
public:
Drivetrain();

Some files were not shown because too many files have changed in this diff Show More