diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index e0b2bd4713a..364140134a1 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -586,11 +586,10 @@ public WrapperCommand withName(String name) { * one or more requirements with a command * that will be added to it. * - * @param parallelGroup The parallel group command. * @param toAdd The command that will be added to the parallel group. */ - protected void ensureDisjointRequirements(Command parallelGroup, Command toAdd) { - var sharedRequirements = new HashSet<>(parallelGroup.getRequirements()); + protected void ensureDisjointRequirements(Command toAdd) { + var sharedRequirements = new HashSet<>(getRequirements()); sharedRequirements.retainAll(toAdd.getRequirements()); if (!sharedRequirements.isEmpty()) { StringBuilder sharedRequirementsStr = new StringBuilder(); diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java index 0199576bd0a..b77f30adcec 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelCommandGroup.java @@ -50,7 +50,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - Commands.ensureDisjointRequirements(this, command); + ensureDisjointRequirements(command); m_commands.put(command, false); addRequirements(command.getRequirements()); m_runWhenDisabled &= command.runsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java index 3539e3e5c03..cf923113c64 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroup.java @@ -80,7 +80,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - Commands.ensureDisjointRequirements(this, command); + ensureDisjointRequirements(command); m_commands.put(command, false); addRequirements(command.getRequirements()); m_runWhenDisabled &= command.runsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java index 238c01ba9e8..becfc20e4fa 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroup.java @@ -51,7 +51,7 @@ public final void addCommands(Command... commands) { CommandScheduler.getInstance().registerComposedCommands(commands); for (Command command : commands) { - Commands.ensureDisjointRequirements(this, command); + ensureDisjointRequirements(command); m_commands.add(command); addRequirements(command.getRequirements()); m_runWhenDisabled &= command.runsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp index 4bb8ddadfb8..d8d6e86a26c 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Command.cpp @@ -218,9 +218,7 @@ void Command::InitSendable(wpi::SendableBuilder& builder) { "runsWhenDisabled", [this] { return RunsWhenDisabled(); }, nullptr); } -namespace frc2 { - -void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd) { +void EnsureDisjointRequirements(Command* toAdd) { std::string sharedRequirementsStr = ""; bool hasSharedRequirements = false; auto&& requirementsToAdd = toAdd->GetRequirements(); @@ -236,12 +234,11 @@ void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd) { } if (hasSharedRequirements) { throw FRC_MakeError( - frc::err::CommandIllegalUse, - "Command {} could not be added to this parallel group" - " because the subsystems [{}] are already required in this command." - " Multiple commands in a parallel composition cannot require the " - "same subsystems.", - toAdd->GetName(), sharedRequirementsStr); + frc::err::CommandIllegalUse, + "Command {} could not be added to this Parallel Group" + " because the subsystems [{}] are already required in this command." + " Multiple commands in a parallel composition cannot require the " + "same subsystems.", + command->GetName(), sharedRequirementsStr); } } -} // namespace frc2 diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp index 0c00b158574..72458ccb71d 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelCommandGroup.cpp @@ -76,7 +76,7 @@ void ParallelCommandGroup::AddCommands( } for (auto&& command : commands) { - EnsureDisjointRequirements(this, command.get()); + EnsureDisjointRequirements(command.get()); command->SetComposed(true); AddRequirements(command->GetRequirements()); m_runWhenDisabled &= command->RunsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp index 75bcfaea4dd..b4c217306c8 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelDeadlineGroup.cpp @@ -76,7 +76,7 @@ void ParallelDeadlineGroup::AddCommands( } for (auto&& command : commands) { - EnsureDisjointRequirements(this, command.get()); + EnsureDisjointRequirements(command.get()); command->SetComposed(true); AddRequirements(command->GetRequirements()); m_runWhenDisabled &= command->RunsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp index 9ef5083d5c9..f6413feb28d 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/ParallelRaceGroup.cpp @@ -63,7 +63,7 @@ void ParallelRaceGroup::AddCommands( } for (auto&& command : commands) { - EnsureDisjointRequirements(this, command.get()); + EnsureDisjointRequirements(command.get()); command->SetComposed(true); AddRequirements(command->GetRequirements()); m_runWhenDisabled &= command->RunsWhenDisabled(); diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h index 21d90fb0c9f..ee3a50898ce 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Command.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Command.h @@ -485,20 +485,19 @@ class Command : public wpi::Sendable, public wpi::SendableHelper { protected: Command(); + /** + * Throws an error if a parallel group already shares + * one or more requirements with a command + * that will be added to it. + * + * @param parallelGroup The parallel group command. + * @param toAdd The command that will be added to the parallel group. + */ + void EnsureDisjointRequirements(Command* toAdd); + private: /// Requirements set. wpi::SmallSet m_requirements; std::optional m_previousComposition; }; - -/** - * Throws an error if a parallel group already shares - * one or more requirements with a command - * that will be added to it. - * - * @param parallelGroup The parallel group command. - * @param toAdd The command that will be added to the parallel group. - */ -void EnsureDisjointRequirements(Command* parallelGroup, Command* toAdd); -} // namespace frc2