mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[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:
@@ -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() {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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}};
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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}};
|
||||
|
||||
Reference in New Issue
Block a user