mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] RepeatCommand: restart on following iteration (#4706)
This fixes InstantCommand.repeatedly().
This commit is contained in:
@@ -16,15 +16,20 @@ RepeatCommand::RepeatCommand(std::unique_ptr<Command>&& command) {
|
||||
}
|
||||
|
||||
void RepeatCommand::Initialize() {
|
||||
m_ended = false;
|
||||
m_command->Initialize();
|
||||
}
|
||||
|
||||
void RepeatCommand::Execute() {
|
||||
if (m_ended) {
|
||||
m_ended = false;
|
||||
m_command->Initialize();
|
||||
}
|
||||
m_command->Execute();
|
||||
if (m_command->IsFinished()) {
|
||||
// restart command
|
||||
m_command->End(false);
|
||||
m_command->Initialize();
|
||||
m_ended = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,3 +44,7 @@ void RepeatCommand::End(bool interrupted) {
|
||||
bool RepeatCommand::RunsWhenDisabled() const {
|
||||
return m_command->RunsWhenDisabled();
|
||||
}
|
||||
|
||||
Command::InterruptionBehavior RepeatCommand::GetInterruptionBehavior() const {
|
||||
return m_command->GetInterruptionBehavior();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user