diff --git a/wpilibNewCommands/build.gradle b/wpilibNewCommands/build.gradle index 3b4693f5484..1e78c3712cc 100644 --- a/wpilibNewCommands/build.gradle +++ b/wpilibNewCommands/build.gradle @@ -104,4 +104,10 @@ test { outputs.upToDateWhen {false} showStandardStreams = true } + doFirst { + jvmArgs = [ + '--add-opens', 'java.base/jdk.internal.vm=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + ] + } } diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj3/command/async/AsyncCommand.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj3/command/async/AsyncCommand.java index a6d346704b0..4479d3fc597 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj3/command/async/AsyncCommand.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj3/command/async/AsyncCommand.java @@ -3,6 +3,8 @@ import edu.wpi.first.units.Measure; import edu.wpi.first.units.Time; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; @@ -107,6 +109,17 @@ default boolean requires(HardwareResource resource) { return requirements().contains(resource); } + /** + * Checks if this command conflicts with another command. + * + * @param other the commands to check against + * @return true if both commands require at least one of the same resource, false if both commands + * have completely different requirements + */ + default boolean conflictsWith(AsyncCommand other) { + return !Collections.disjoint(requirements(), other.requirements()); + } + /** * Creates an async command that does not require any hardware; that is, it does not affect the * state of any physical objects. This is useful for commands that do some house cleaning work @@ -126,7 +139,7 @@ default void schedule() { /** Cancels this command, if running on the default async scheduler. */ default void cancel() { - AsyncScheduler.getInstance().cancelAndWait(this, true); + AsyncScheduler.getInstance().cancel(this); } /** Checks if this command is currently scheduled to be running on the default async scheduler. */ @@ -135,65 +148,20 @@ default boolean isScheduled() { } default AsyncCommand withTimeout(Measure