From 7a8cd5b6aa5866b4eb03db9af74cf7b10278fbcd Mon Sep 17 00:00:00 2001 From: tom131313 Date: Mon, 20 May 2024 14:21:17 -0400 Subject: [PATCH 01/10] Update Commands.java added looseSequence() --- .../wpi/first/wpilibj2/command/Commands.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 0d2178f6b57..86007644d29 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -223,6 +223,25 @@ public static Command sequence(Command... commands) { return new SequentialCommandGroup(commands); } + /** + * Runs a group of commands in series, one after the other. + * + *

Each command is run individually by proxy. The requirements + * of each command are only for the duration of that command and + * are not required for the entire group process. + + * @param commands the commands to include + * @return the command group + * @see SequentialCommandGroup + */ + public static Command looseSequence(Command... commands) { + SequentialCommandGroup sequence = new SequentialCommandGroup(); + for (Command command : commands) { + sequence.addCommands(command.asProxy()); + } + return sequence; + } + /** * Runs a group of commands in series, one after the other. Once the last command ends, the group * is restarted. From 8b36b83473488db5eee24d5e77dcace69f513d77 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Tue, 21 May 2024 09:02:52 -0400 Subject: [PATCH 02/10] Update Commands.java separatedSequence proxyAll --- .../java/edu/wpi/first/wpilibj2/command/Commands.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 86007644d29..02ab582dadf 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -229,17 +229,14 @@ public static Command sequence(Command... commands) { *

Each command is run individually by proxy. The requirements * of each command are only for the duration of that command and * are not required for the entire group process. - + * * @param commands the commands to include * @return the command group * @see SequentialCommandGroup */ - public static Command looseSequence(Command... commands) { - SequentialCommandGroup sequence = new SequentialCommandGroup(); - for (Command command : commands) { - sequence.addCommands(command.asProxy()); - } - return sequence; + public static Command separatedSequence(Command... commands) { + + return sequence(proxyAll(commands)); } /** From d5d39d3eea15565574ed0ec1b5fed6fa5610c004 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Tue, 21 May 2024 09:13:29 -0400 Subject: [PATCH 03/10] Update wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java Co-authored-by: Jade --- .../src/main/java/edu/wpi/first/wpilibj2/command/Commands.java | 1 - 1 file changed, 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 02ab582dadf..aafaa77e175 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -235,7 +235,6 @@ public static Command sequence(Command... commands) { * @see SequentialCommandGroup */ public static Command separatedSequence(Command... commands) { - return sequence(proxyAll(commands)); } From 0f28942b072b8040a7cb62f94f9ae26493effe72 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Tue, 21 May 2024 10:17:52 -0400 Subject: [PATCH 04/10] Update Commands.java documentation --- .../main/java/edu/wpi/first/wpilibj2/command/Commands.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index aafaa77e175..4fd80510c97 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -226,9 +226,9 @@ public static Command sequence(Command... commands) { /** * Runs a group of commands in series, one after the other. * - *

Each command is run individually by proxy. The requirements - * of each command are only for the duration of that command and - * are not required for the entire group process. + *

Each command is run individually by proxy. The requirements of + * each command are reserved only for the duration of that command and + * are not reserved for the entire group process. * * @param commands the commands to include * @return the command group From 5c858d3346b4d73f557420f246c4b355f3d596b4 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Wed, 22 May 2024 10:51:40 -0400 Subject: [PATCH 05/10] Update Commands.java new javadoc and new name for ungroupedSequence --- .../edu/wpi/first/wpilibj2/command/Commands.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 4fd80510c97..db31f1f4652 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -224,17 +224,18 @@ public static Command sequence(Command... commands) { } /** - * Runs a group of commands in series, one after the other. + * Runs individual commands in a series without grouped sequence behavior. * - *

Each command is run individually by proxy. The requirements of + *

Each command is run independently by proxy. The requirements of * each command are reserved only for the duration of that command and - * are not reserved for the entire group process. + * are not reserved for an entire group process as they are in a + * grouped sequence. * - * @param commands the commands to include - * @return the command group - * @see SequentialCommandGroup + * @param commands the commands to include in the series + * @return the command to run the series of commands + * @see #sequence() use sequence() to invoke group sequence behavior */ - public static Command separatedSequence(Command... commands) { + public static Command ungroupedSequence(Command... commands) { return sequence(proxyAll(commands)); } From 59e77bb97249ce76c3bd9dbf3612880a64ea5efe Mon Sep 17 00:00:00 2001 From: tom131313 Date: Wed, 22 May 2024 21:20:22 -0400 Subject: [PATCH 06/10] Update Commands.java disjointParallel --- .../wpi/first/wpilibj2/command/Commands.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index db31f1f4652..4b2b08d8c4d 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -224,7 +224,7 @@ public static Command sequence(Command... commands) { } /** - * Runs individual commands in a series without grouped sequence behavior. + * Runs individual commands in a series without grouped behavior. * *

Each command is run independently by proxy. The requirements of * each command are reserved only for the duration of that command and @@ -233,9 +233,9 @@ public static Command sequence(Command... commands) { * * @param commands the commands to include in the series * @return the command to run the series of commands - * @see #sequence() use sequence() to invoke group sequence behavior + * @see #sequence(Command...) use sequence() to invoke group sequence behavior */ - public static Command ungroupedSequence(Command... commands) { + public static Command disjointSequence(Command... commands) { return sequence(proxyAll(commands)); } @@ -262,6 +262,23 @@ public static Command repeatingSequence(Command... commands) { public static Command parallel(Command... commands) { return new ParallelCommandGroup(commands); } + + /** + * Runs individual commands at the same time without grouped behavior and ends once all commands finish. + * + *

Each command is run independently by proxy. The requirements of + * each command are reserved only for the duration of that command and + * are not reserved for an entire group process as they are in a + * grouped parallel. + * + * @param commands the commands to run in parallel + * @return the command to run the commands in parallel + * @see #parallel(Command...) use parallel() to invoke group parallel behavior + */ + public static Command disjointParallel(Command... commands) { + new ParallelCommandGroup(commands); + return parallel(proxyAll(commands)); + } /** * Runs a group of commands at the same time. Ends once any command in the group finishes, and From c1576a2c37763a875f3e02eccb64dcc827b67cee Mon Sep 17 00:00:00 2001 From: tom131313 Date: Thu, 23 May 2024 13:09:31 -0400 Subject: [PATCH 07/10] Update Commands.java disjoint commands --- .../wpi/first/wpilibj2/command/Commands.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 4b2b08d8c4d..2c14ed37088 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -252,6 +252,24 @@ public static Command repeatingSequence(Command... commands) { return sequence(commands).repeatedly(); } + /** + * Runs individual commands in a series without grouped behavior; once the last command ends, the series is restarted. + * + *

Each command is run independently by proxy. The requirements of + * each command are reserved only for the duration of that command and + * are not reserved for an entire group process as they are in a + * grouped sequence. + * + * @param commands the commands to include in the series + * @return the command to run the series of commands repeatedly + * @see #sequence(Command...) use sequenceRepeatedly() to invoke repeated group sequence behavior + * @see #disjointSequence(Command...) + * @see Command#repeatedly() + */ + public static Command repeatingDisjointSequence(Command... commands) { + return disjointSequence(commands).repeatedly(); + } + /** * Runs a group of commands at the same time. Ends once all commands in the group finish. * @@ -276,7 +294,7 @@ public static Command parallel(Command... commands) { * @see #parallel(Command...) use parallel() to invoke group parallel behavior */ public static Command disjointParallel(Command... commands) { - new ParallelCommandGroup(commands); + new ParallelCommandGroup(commands); // check parallel constraints return parallel(proxyAll(commands)); } @@ -306,6 +324,24 @@ public static Command deadline(Command deadline, Command... otherCommands) { return new ParallelDeadlineGroup(deadline, otherCommands); } + /** + * Runs individual commands at the same time without grouped behavior; when the deadline command ends the otherCommands are cancelled. + * + *

Each otherCommand is run independently by proxy. The requirements of + * each command are reserved only for the duration of that command and are + * not reserved for an entire group process as they are in a grouped deadline. + * + * @param deadline the deadline command + * @param otherCommands the other commands to include and will be cancelled when the deadline ends + * @return the command to run the deadline command and otherCommands + * @see #deadline(Command, Command...) use deadline() to invoke group parallel deadline behavior + * @throws IllegalArgumentException if the deadline command is also in the otherCommands argument + */ + public static Command disjointDeadline(Command deadline, Command... otherCommands) { + new ParallelDeadlineGroup(deadline, otherCommands); // check parallel deadline constraints + return deadline(deadline, proxyAll(otherCommands)); + } + private Commands() { throw new UnsupportedOperationException("This is a utility class"); } From 1fb1c9a82b3baa2b8550e4e3a883edb911002cfd Mon Sep 17 00:00:00 2001 From: tom131313 Date: Thu, 23 May 2024 19:57:51 -0400 Subject: [PATCH 08/10] Update Commands.java disjoints --- .../java/edu/wpi/first/wpilibj2/command/Commands.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 2c14ed37088..c7da2abc203 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -230,6 +230,8 @@ public static Command sequence(Command... commands) { * each command are reserved only for the duration of that command and * are not reserved for an entire group process as they are in a * grouped sequence. + * + *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. * * @param commands the commands to include in the series * @return the command to run the series of commands @@ -259,6 +261,8 @@ public static Command repeatingSequence(Command... commands) { * each command are reserved only for the duration of that command and * are not reserved for an entire group process as they are in a * grouped sequence. + * + *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. * * @param commands the commands to include in the series * @return the command to run the series of commands repeatedly @@ -288,6 +292,8 @@ public static Command parallel(Command... commands) { * each command are reserved only for the duration of that command and * are not reserved for an entire group process as they are in a * grouped parallel. + * + *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. * * @param commands the commands to run in parallel * @return the command to run the commands in parallel @@ -295,6 +301,7 @@ public static Command parallel(Command... commands) { */ public static Command disjointParallel(Command... commands) { new ParallelCommandGroup(commands); // check parallel constraints + for (Command cmd : commands) CommandScheduler.getInstance().removeComposedCommand(cmd); return parallel(proxyAll(commands)); } @@ -330,6 +337,8 @@ public static Command deadline(Command deadline, Command... otherCommands) { *

Each otherCommand is run independently by proxy. The requirements of * each command are reserved only for the duration of that command and are * not reserved for an entire group process as they are in a grouped deadline. + * + *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. * * @param deadline the deadline command * @param otherCommands the other commands to include and will be cancelled when the deadline ends @@ -339,6 +348,8 @@ public static Command deadline(Command deadline, Command... otherCommands) { */ public static Command disjointDeadline(Command deadline, Command... otherCommands) { new ParallelDeadlineGroup(deadline, otherCommands); // check parallel deadline constraints + CommandScheduler.getInstance().removeComposedCommand(deadline); + for (Command cmd : otherCommands) CommandScheduler.getInstance().removeComposedCommand(cmd); return deadline(deadline, proxyAll(otherCommands)); } From 0082985ded1e2de36696e213a176b477b6d4a7f3 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Thu, 30 May 2024 14:15:53 -0400 Subject: [PATCH 09/10] Update Commands.java added more disjoint methods updated javadocs --- .../wpi/first/wpilibj2/command/Commands.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index c7da2abc203..4e9cbb8c3ca 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -266,12 +266,12 @@ public static Command repeatingSequence(Command... commands) { * * @param commands the commands to include in the series * @return the command to run the series of commands repeatedly - * @see #sequence(Command...) use sequenceRepeatedly() to invoke repeated group sequence behavior - * @see #disjointSequence(Command...) - * @see Command#repeatedly() + * @see #repeatingSequence(Command...) use sequenceRepeatedly() to invoke repeated group sequence behavior + * @see #disjointSequence(Command...) use disjointSequence() for no repeating behavior */ public static Command repeatingDisjointSequence(Command... commands) { - return disjointSequence(commands).repeatedly(); + throw new IllegalArgumentException("Not Supported - RepeatCommand bug prevents correct use of Proxy"); + // return disjointSequence(commands).repeatedly(); } /** @@ -285,7 +285,7 @@ public static Command parallel(Command... commands) { return new ParallelCommandGroup(commands); } - /** +/** * Runs individual commands at the same time without grouped behavior and ends once all commands finish. * *

Each command is run independently by proxy. The requirements of @@ -317,6 +317,22 @@ public static Command race(Command... commands) { return new ParallelRaceGroup(commands); } + /** + * Runs a group of commands at the same time. Ends once any command in the group finishes, and + * cancels the others. + * + *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. + * + * @param commands the commands to include + * @return the command group + * @see ParallelRaceGroup + */ + public static Command disjointRace(Command... commands) { + new ParallelRaceGroup(commands); // check parallel constraints + for (Command cmd : commands) CommandScheduler.getInstance().removeComposedCommand(cmd); + return race(proxyAll(commands)); + } + /** * Runs a group of commands at the same time. Ends once a specific command finishes, and cancels * the others. @@ -337,7 +353,7 @@ public static Command deadline(Command deadline, Command... otherCommands) { *

Each otherCommand is run independently by proxy. The requirements of * each command are reserved only for the duration of that command and are * not reserved for an entire group process as they are in a grouped deadline. - * + * *

disjoint...() does not propagate to interior groups. Use additional disjoint...() as needed. * * @param deadline the deadline command @@ -349,8 +365,10 @@ public static Command deadline(Command deadline, Command... otherCommands) { public static Command disjointDeadline(Command deadline, Command... otherCommands) { new ParallelDeadlineGroup(deadline, otherCommands); // check parallel deadline constraints CommandScheduler.getInstance().removeComposedCommand(deadline); - for (Command cmd : otherCommands) CommandScheduler.getInstance().removeComposedCommand(cmd); - return deadline(deadline, proxyAll(otherCommands)); + for (Command cmd : otherCommands) { + CommandScheduler.getInstance().removeComposedCommand(cmd); + } + return deadline(deadline.asProxy(), proxyAll(otherCommands)); } private Commands() { From 42727747a5bab2225a1c514e7f512b614d771967 Mon Sep 17 00:00:00 2001 From: tom131313 Date: Fri, 31 May 2024 10:26:40 -0400 Subject: [PATCH 10/10] Update Commands.java add proxyAll() restricted to commands with requirements --- .../wpi/first/wpilibj2/command/Commands.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java index 4e9cbb8c3ca..af7ab4029c9 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Commands.java @@ -347,7 +347,7 @@ public static Command deadline(Command deadline, Command... otherCommands) { return new ParallelDeadlineGroup(deadline, otherCommands); } - /** + /** * Runs individual commands at the same time without grouped behavior; when the deadline command ends the otherCommands are cancelled. * *

Each otherCommand is run independently by proxy. The requirements of @@ -368,8 +368,34 @@ public static Command disjointDeadline(Command deadline, Command... otherCommand for (Command cmd : otherCommands) { CommandScheduler.getInstance().removeComposedCommand(cmd); } - return deadline(deadline.asProxy(), proxyAll(otherCommands)); + if ( ! deadline.getRequirements().isEmpty()) { + deadline = deadline.asProxy(); + } + return deadline(deadline, proxyAll(otherCommands)); + } + + /** + * Maps an array of commands by adding proxy to every element that has requirements using {@link Command#asProxy()}. + * + *

This is useful to ensure that default commands of subsystems within a command group are + * still triggered despite command groups requiring the union of their members' requirements + * + * @param commands an array of commands + * @return an array of commands to run by proxy if a command has requirements + */ + public static Command[] proxyAll(Command... commands) { + Command[] out = new Command[commands.length]; + for (int i = 0; i < commands.length; i++) { + if (commands[i].getRequirements().isEmpty()) { + out[i] = commands[i]; + } + else { + out[i] = commands[i].asProxy(); + } + } + return out; } +} private Commands() { throw new UnsupportedOperationException("This is a utility class");