mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] C++: Add CommandPtr overload for SetDefaultCommand (#4488)
This commit is contained in:
@@ -296,6 +296,20 @@ void CommandScheduler::UnregisterSubsystem(
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::SetDefaultCommand(Subsystem* subsystem,
|
||||
CommandPtr&& defaultCommand) {
|
||||
if (!defaultCommand.get()->HasRequirement(subsystem)) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Default commands must require their subsystem!");
|
||||
}
|
||||
if (defaultCommand.get()->IsFinished()) {
|
||||
throw FRC_MakeError(frc::err::CommandIllegalUse, "{}",
|
||||
"Default commands should not end!");
|
||||
}
|
||||
|
||||
SetDefaultCommandImpl(subsystem, std::move(defaultCommand).Unwrap());
|
||||
}
|
||||
|
||||
Command* CommandScheduler::GetDefaultCommand(const Subsystem* subsystem) const {
|
||||
auto&& find = m_impl->subsystems.find(subsystem);
|
||||
if (find != m_impl->subsystems.end()) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
#include "frc2/command/CommandPtr.h"
|
||||
|
||||
using namespace frc2;
|
||||
Subsystem::~Subsystem() {
|
||||
CommandScheduler::GetInstance().UnregisterSubsystem(this);
|
||||
@@ -13,6 +15,11 @@ void Subsystem::Periodic() {}
|
||||
|
||||
void Subsystem::SimulationPeriodic() {}
|
||||
|
||||
void Subsystem::SetDefaultCommand(CommandPtr&& defaultCommand) {
|
||||
CommandScheduler::GetInstance().SetDefaultCommand(this,
|
||||
std::move(defaultCommand));
|
||||
}
|
||||
|
||||
Command* Subsystem::GetDefaultCommand() const {
|
||||
return CommandScheduler::GetInstance().GetDefaultCommand(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user