[commands] Define order of parallel groups (#6602)

This commit is contained in:
Joseph Eng
2024-06-01 12:01:15 -07:00
committed by GitHub
parent 7751f6d1d2
commit 1828fdaaa4
6 changed files with 296 additions and 9 deletions

View File

@@ -5,7 +5,7 @@
package edu.wpi.first.wpilibj2.command;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -19,7 +19,9 @@ import java.util.Map;
*/
public class ParallelCommandGroup extends Command {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
// LinkedHashMap guarantees we iterate over commands in the order they were added (Note that
// changing the value associated with a command does NOT change the order)
private final Map<Command, Boolean> m_commands = new LinkedHashMap<>();
private boolean m_runWhenDisabled = true;
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;

View File

@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj2.command;
import edu.wpi.first.util.sendable.SendableBuilder;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -22,7 +22,9 @@ import java.util.Map;
*/
public class ParallelDeadlineGroup extends Command {
// maps commands in this composition to whether they are still running
private final Map<Command, Boolean> m_commands = new HashMap<>();
// LinkedHashMap guarantees we iterate over commands in the order they were added (Note that
// changing the value associated with a command does NOT change the order)
private final Map<Command, Boolean> m_commands = new LinkedHashMap<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;
private Command m_deadline;
@@ -39,8 +41,8 @@ public class ParallelDeadlineGroup extends Command {
* @throws IllegalArgumentException if the deadline command is also in the otherCommands argument
*/
public ParallelDeadlineGroup(Command deadline, Command... otherCommands) {
addCommands(otherCommands);
setDeadline(deadline);
addCommands(otherCommands);
}
/**

View File

@@ -5,7 +5,7 @@
package edu.wpi.first.wpilibj2.command;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
/**
@@ -19,7 +19,8 @@ import java.util.Set;
* <p>This class is provided by the NewCommands VendorDep
*/
public class ParallelRaceGroup extends Command {
private final Set<Command> m_commands = new HashSet<>();
// LinkedHashSet guarantees we iterate over commands in the order they were added
private final Set<Command> m_commands = new LinkedHashSet<>();
private boolean m_runWhenDisabled = true;
private boolean m_finished = true;
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;