mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[commands] Move GroupedCommands to CommandScheduler (#4728)
Move the command group checking functionality from CommandGroupBase into CommandScheduler. Update references to grouping as composition for clarity (because explicitly grouping isn't the only way to do it). Deprecate the static factory methods parallel, race, and deadline in CommandGroupBase in favor of the identical ones in Commands.
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandPtr.h"
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
@@ -118,12 +117,8 @@ void CommandScheduler::Schedule(Command* command) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command->IsGrouped()) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse,
|
||||
"A command that is part of a command group "
|
||||
"cannot be independently scheduled");
|
||||
return;
|
||||
}
|
||||
RequireUngrouped(command);
|
||||
|
||||
if (m_impl->disabled ||
|
||||
(frc::RobotState::IsDisabled() && !command->RunsWhenDisabled()) ||
|
||||
m_impl->scheduledCommands.contains(command)) {
|
||||
@@ -307,6 +302,7 @@ void CommandScheduler::SetDefaultCommand(Subsystem* subsystem,
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Default commands must require their subsystem!");
|
||||
}
|
||||
RequireUngrouped(defaultCommand.get());
|
||||
|
||||
SetDefaultCommandImpl(subsystem, std::move(defaultCommand).Unwrap());
|
||||
}
|
||||
@@ -436,6 +432,28 @@ void CommandScheduler::OnCommandFinish(Action action) {
|
||||
m_impl->finishActions.emplace_back(std::move(action));
|
||||
}
|
||||
|
||||
void CommandScheduler::RequireUngrouped(const Command* command) {
|
||||
if (command->IsComposed()) {
|
||||
throw FRC_MakeError(
|
||||
frc::err::CommandIllegalUse,
|
||||
"Commands cannot be added to more than one CommandGroup");
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::RequireUngrouped(
|
||||
std::span<const std::unique_ptr<Command>> commands) {
|
||||
for (auto&& command : commands) {
|
||||
RequireUngrouped(command.get());
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::RequireUngrouped(
|
||||
std::initializer_list<const Command*> commands) {
|
||||
for (auto&& command : commands) {
|
||||
RequireUngrouped(command);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::InitSendable(nt::NTSendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Scheduler");
|
||||
builder.SetUpdateTable(
|
||||
|
||||
Reference in New Issue
Block a user