# Lesson 2.?: Command Groups

Accompanying code lesson: TODO

Commands can be grouped together in 4 ways: sequential, parallel, race, and deadline. This allows multiple commands to run together and act as one command, though each group type changes how the command group ends.

* Sequential
  * Starts the next command in the sequence when the previous command is done
  * Ends when the final command in the sequence is done
* Parallel
  * Runs all commands in the group at once
  * Ends when all the commands in the group are done
* Race
  * Runs all commands in the group at once
  * Ends when just one of the commands in the group is done
  * Cancels all other commands in the group when ending
* Deadline
  * The first command in the group is considered the "deadline"
  * Ends when the deadline command is done
  * Cancels any unfinished commands in the group when ending

<figure><img src="/files/8VPlNaJdUiJLOzR79NJM" alt=""><figcaption><p>How each command group behaves.</p></figcaption></figure>

Command groups are not available from the `Subsystem` class, they are only available from the `Commands` static import.

Sequential group syntax example:

```java
sequence(
  command1(),
  command2(),
  // ...
  commandN())
```

Parallel group syntax example:

```java
parallel(
    command1(),
    command2(),
    // ...
    commandN())
```

Race group syntax example:

```java
race(
    command1(),
    command2(),
    // ...
    commandN())
```

Deadline group syntax example:

```java
deadline(
    deadlineCommand(),
    command1(),
    command2(),
    // ...
    commandN())
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iowacityrobotics.org/programming/frc-programming/section-2-commands/lesson-2.-command-groups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
