> For the complete documentation index, see [llms.txt](https://docs.raidrobotics.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.raidrobotics.org/commands-v3-state-machine/how-to/write-an-auto.md).

# Write an auto

Every auto is its own file in `opmodes/auto/`. No other file needs to know about it.

{% stepper %}
{% step %}

## Copy the example

Copy `opmodes/auto/ExampleAuto.java`, rename the class, and change the name in `@Autonomous(name = "...")`. That name is what the drive team sees on the Driver Station, so make it say what the auto does.
{% endstep %}

{% step %}

## Set the poses

Write every pose for the **blue** alliance. `AutoDrive` mirrors them on red.

```java
private static final Pose2d START = new Pose2d(2.0, 4.0, Rotation2d.ZERO);
private static final Pose2d GAME_PIECE = new Pose2d(4.0, 4.5, Rotation2d.ZERO);
```

To find a pose, drive the robot there and read `Drive/Pose`, or take it from the field drawings.
{% endstep %}

{% step %}

## Write the steps

The routine reads top to bottom. Start with `resetPose`, then drive and make requests:

```java
coroutine.await(drive.resetPose(START));
coroutine.await(superstructure.scoreUntilDone().withTimeout(Seconds.of(3)));
coroutine.awaitAll(
    drive.driveTo("ToGamePiece", GAME_PIECE).withTimeout(Seconds.of(4)),
    superstructure.intakeUntilHolding().withTimeout(Seconds.of(5))
);
```

* `await` runs one command and waits for it.
* `awaitAll` runs several together and waits for all of them.
* Use ordinary `if`s to react: `if (!superstructure.hasGamePiece()) { ... }`.
* Log each step with `RobotLog.event("Auto: step 3, fetch a game piece")`, so the log shows how far it got.
  {% endstep %}

{% step %}

## Put a timeout on every step

Every step that waits on the real world (driving, intaking, scoring) needs `.withTimeout(...)`. A missed game piece should cost a second, not the rest of the auto.
{% endstep %}

{% step %}

## Keep the three bindings

Keep the lines that run the state machine and the routine for the whole autonomous period, and the one that ignores vision:

```java
RobotModeTriggers.autonomous().whileTrue(superstructure.createStateMachine());
RobotModeTriggers.autonomous().whileTrue(routine);
RobotModeTriggers.autonomous().whileTrue(robot.vision.ignore());
```

Delete the vision line only if this auto needs the cameras.
{% endstep %}

{% step %}

## Run it in the simulator

Run `./gradlew run`, pick **Autonomous** and your auto, and enable. Watch **Drive › Field** and **Superstructure › Drawing**. Try it as both alliances (set the alliance in the simulator's **FMS** panel) to check the mirroring.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Autos can only make the same requests teleop makes. If an auto needs the robot to do something new, add it to the superstructure as a state and a request, and teleop gets it too.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.raidrobotics.org/commands-v3-state-machine/how-to/write-an-auto.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
