diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java index a53d792d0e4..ed934b39c3e 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/Command.java @@ -398,6 +398,28 @@ public ProxyCommand asProxy() { return new ProxyCommand(this); } + /** + * Decorates this command to run "forked" by wrapping it in a {@link ScheduleCommand}. Use this + * for "forking off" from command compositions when the user does not wish to extend the command's + * requirements to the entire command composition. Note that if run from a composition, the + * composition will not know about the status of the scheduled commands, and will treat this + * command as finishing instantly. Commands can be added to this and will be scheduled in order + * with this command scheduled first. + * + * @param other other commands to schedule along with this one. This command is scheduled first. + * @return the decorated command + * @see ScheduleCommand + * @see WPILib + * docs + */ + public ScheduleCommand fork(Command... other) { + Command[] commands = new Command[1 + other.length]; + commands[0] = this; + System.arraycopy(other, 0, commands, 1, other.length); + return new ScheduleCommand(commands); + } + /** * Decorates this command to only run if this condition is not met. If the command is already * running and the condition changes to true, the command will not stop running. The requirements diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp index 298cc2e50ca..4d48c5706b9 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/CommandPtr.cpp @@ -18,6 +18,7 @@ #include "frc2/command/ParallelRaceGroup.h" #include "frc2/command/ProxyCommand.h" #include "frc2/command/RepeatCommand.h" +#include "frc2/command/ScheduleCommand.h" #include "frc2/command/SequentialCommandGroup.h" #include "frc2/command/WaitCommand.h" #include "frc2/command/WaitUntilCommand.h"