[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

@@ -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}};