Fix small logic error in ParallelDeadlineGroup (#2095)

This commit is contained in:
Oblarg
2019-11-18 18:33:45 -05:00
committed by Peter Johnson
parent 6f6c6da9f5
commit 0e83c65d27
3 changed files with 14 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
//maps commands in this group to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;
private Command m_deadline;
/**
@@ -57,7 +58,7 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
public final void addCommands(Command... commands) {
requireUngrouped(commands);
if (m_commands.containsValue(true)) {
if (!m_finished) {
throw new IllegalStateException(
"Commands cannot be added to a CommandGroup while the group is running");
}
@@ -81,6 +82,7 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
commandRunning.getKey().initialize();
commandRunning.setValue(true);
}
m_finished = false;
}
@Override
@@ -93,6 +95,9 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
if (commandRunning.getKey().isFinished()) {
commandRunning.getKey().end(false);
commandRunning.setValue(false);
if (commandRunning.getKey() == m_deadline) {
m_finished = true;
}
}
}
}
@@ -108,7 +113,7 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
@Override
public boolean isFinished() {
return m_deadline.isFinished();
return m_finished;
}
@Override

View File

@@ -21,7 +21,7 @@ void ParallelDeadlineGroup::Initialize() {
commandRunning.first->Initialize();
commandRunning.second = true;
}
isRunning = true;
m_finished = false;
}
void ParallelDeadlineGroup::Execute() {
@@ -31,6 +31,9 @@ void ParallelDeadlineGroup::Execute() {
if (commandRunning.first->IsFinished()) {
commandRunning.first->End(false);
commandRunning.second = false;
if (commandRunning.first.get() == m_deadline) {
m_finished = true;
}
}
}
}
@@ -41,10 +44,9 @@ void ParallelDeadlineGroup::End(bool interrupted) {
commandRunning.first->End(true);
}
}
isRunning = false;
}
bool ParallelDeadlineGroup::IsFinished() { return m_deadline->IsFinished(); }
bool ParallelDeadlineGroup::IsFinished() { return m_finished; }
bool ParallelDeadlineGroup::RunsWhenDisabled() const {
return m_runWhenDisabled;
@@ -56,7 +58,7 @@ void ParallelDeadlineGroup::AddCommands(
return;
}
if (isRunning) {
if (!m_finished) {
wpi_setWPIErrorWithContext(CommandIllegalUse,
"Commands cannot be added to a CommandGroup "
"while the group is running");

View File

@@ -101,7 +101,7 @@ class ParallelDeadlineGroup
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
Command* m_deadline;
bool m_runWhenDisabled{true};
bool isRunning = false;
bool m_finished{true};
};
} // namespace frc2