> 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/add-a-button.md).

# Add a button

Buttons live in `opmodes/teleop/DriveTeleop.java`. Every button makes a **request**; it never runs a mechanism directly.

{% stepper %}
{% step %}

## Make sure there's a request for it

If the button asks the superstructure for something new, add the request first. See [Add a state](https://docs.raidrobotics.org/commands-v3-state-machine/how-to/add-a-state.md#add-a-request-if-someone-triggers-it).
{% endstep %}

{% step %}

## Bind it, with a comment for the driver

Add one binding, with a plain-words comment right above it:

{% code title="DriveTeleop.java" %}

```java
// Hold to shoot; the robot shoots as soon as it's aimed
controller.leftTrigger().whileTrue(superstructure.requestShoot());
```

{% endcode %}

RAIDSystems shows that comment as the button's description on its Controls page, for the drive team to approve. Write it for a driver, not a programmer.

Pick the binding that matches how the driver should use it:

| Binding        | The request is up...                                        |
| -------------- | ----------------------------------------------------------- |
| `whileTrue`    | while the button is held                                    |
| `toggleOnTrue` | from one press until the next                               |
| `onTrue`       | once, when pressed (for commands that finish by themselves) |
| {% endstep %}  |                                                             |

{% step %}

## Update the controls table

Update the table in `DriveTeleop`'s class comment, the README, and [Controls](https://docs.raidrobotics.org/commands-v3-state-machine/reference/controls.md).
{% endstep %}

{% step %}

## Map a simulator key

To test it on a keyboard, open the simulator, map a key to the new button in the keyboard joystick settings, and close the simulator so it saves `simgui-ds.json`. Commit that file.
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
Don't bind a mechanism command (`mechanism1.goTo(...)`) to a button. It would fight the state machine for the mechanism, and teleop would behave differently from auto. If you need a manual override, add it as a state with its own request.
{% 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/add-a-button.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.
