A state machine representing a complete action to be performed by the robot. Commands are run by the CommandScheduler, and can be composed into CommandGroups to allow users to build complicated multi-step actions without the need to roll the state machine logic themselves. Commands are
| 21 | * @author Jackson |
| 22 | */ |
| 23 | @SuppressWarnings("PMD.TooManyMethods") |
| 24 | public interface Command { |
| 25 | |
| 26 | /** |
| 27 | * The initial subroutine of a command. Called once when the command is initially scheduled. |
| 28 | */ |
| 29 | default void initialize() { |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * The main body of a command. Called repeatedly while the command is scheduled. |
| 34 | */ |
| 35 | default void execute() { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * The action to take when the command ends. Called when either the command finishes normally, |
| 40 | * or when it interrupted/canceled. |
| 41 | * |
| 42 | * @param interrupted whether the command was interrupted/canceled |
| 43 | */ |
| 44 | default void end(boolean interrupted) { |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Whether the command has finished. Once a command finishes, the scheduler will call its |
| 49 | * end() method and un-schedule it. |
| 50 | * |
| 51 | * @return whether the command has finished. |
| 52 | */ |
| 53 | default boolean isFinished() { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Specifies the set of subsystems used by this command. Two commands cannot use the same |
| 59 | * subsystem at the same time. If the command is scheduled as interruptible and another |
| 60 | * command is scheduled that shares a requirement, the command will be interrupted. Else, |
| 61 | * the command will not be scheduled. If no subsystems are required, return an empty set. |
| 62 | * |
| 63 | * <p>Note: it is recommended that user implementations contain the requirements as a field, |
| 64 | * and return that field here, rather than allocating a new set every time this is called. |
| 65 | * |
| 66 | * @return the set of subsystems that are required |
| 67 | */ |
| 68 | Set<Subsystem> getRequirements(); |
| 69 | |
| 70 | /** |
| 71 | * Decorates this command with a timeout. If the specified timeout is exceeded before the command |
| 72 | * finishes normally, the command will be interrupted and un-scheduled. Note that the |
| 73 | * timeout only applies to the command returned by this method; the calling command is |
| 74 | * not itself changed. |
| 75 | * |
| 76 | * <p>Note: This decorator works by composing this command within a CommandGroup. The command |
| 77 | * cannot be used independently after being decorated, or be re-decorated with a different |
| 78 | * decorator, unless it is manually cleared from the list of grouped commands with |
| 79 | * {@link CommandGroupBase#clearGroupedCommand(Command)}. The decorated command can, however, be |
| 80 | * further decorated without issue. |
no outgoing calls
no test coverage detected