> For the complete documentation index, see [llms.txt](https://yams.yassrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yams.yassrobotics.com/documentation/tutorials/elevator/simulate.md). Agents can also search and read this documentation through its [MCP server](https://yams.yassrobotics.com/~gitbook/mcp).

# Step 4: Simulate it

Run the elevator in simulation and drive it with a controller.

The code from the first three steps runs on your computer exactly as it will on the robot. YAMS simulates the motor, the gearing, the carriage and gravity, so the closed loop, the limits and the commands all behave the way they will on the real elevator.

{% stepper %}
{% step %}

### Start the simulation

{% tabs %}
{% tab title="Java, Commands v2" %}
Open the command palette with <kbd>Ctrl+Shift+P</kbd> and run **WPILib: Simulate Robot Code**. If you are asked which extensions to run, tick **Sim GUI**.
{% endtab %}

{% tab title="Java, Commands v3" %}
Open the command palette with <kbd>Ctrl+Shift+P</kbd> and run **WPILib: Simulate Robot Code**. If you are asked which extensions to run, tick **Sim GUI**.

The buttons are bound in the `ExampleTeleop` op mode, so that is the op mode to run when you enable.

If the simulated mechanism never moves, check that `Robot.java` has a `simulationInit()` that calls `startSimulation(...)` for the mechanism.
{% endtab %}

{% tab title="C++" %}
Open the command palette with <kbd>Ctrl+Shift+P</kbd> and run **WPILib: Simulate Robot Code**. If you are asked which extensions to run, tick **Sim GUI**.

The first C++ build compiles the whole project, so it takes a few minutes. Later builds are much faster.
{% endtab %}
{% endtabs %}

<figure><img src="https://1354553280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZM0CFmYiQzcrY4zDcTtZ%2Fuploads%2F04lmc9ZfMo9DPRuEp9gh%2Fimage.png?alt=media&amp;token=de5c8905-4617-4c86-bfd9-2c4acdccac09" alt="The Sim GUI, the window that opens with the simulation, with the Robot State, System Joysticks, Joysticks and NetworkTables panels"><figcaption><p>The Sim GUI.</p></figcaption></figure>
{% endstep %}

{% step %}

### Drive it

1. Connect a controller to your computer, then drag it from **System Joysticks** to **Joystick\[0]**. Commands v3: drag it to **Joystick\[1]** instead, because the Command v3 template's controller is on port 1 (`DriverConstants.DRIVER_CONTROLLER_PORT`).
2. Open the simulated mechanism with **NetworkTables -> Mechanisms -> Elevator -> mechanism**. It is named after the `withTelemetry("Elevator", ...)` on the `ElevatorConfig`. It shows the carriage as a bar that grows upward as the carriage rises, with short marks beside it for the soft limits and the hard stops.

<figure><img src="https://1354553280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZM0CFmYiQzcrY4zDcTtZ%2Fuploads%2FLFZWXPofThkqLoUsplTR%2FRobot%20Simulation%208_30_2025%207_06_08%20PM.png?alt=media&amp;token=18b8bec7-865d-451e-a12b-d9adcf088f0e" alt="The Sim GUI with the elevator&#x27;s Mechanism2d window open: a vertical bar for the carriage height, next to marks for the limits"><figcaption></figcaption></figure>

3. Resize **Elevator/mechanism** to your liking.
4. Commands v3: pick the `ExampleTeleop` op mode first. Then press **Teleoperated** in **Robot State**. The controller now drives the simulated elevator just as it would the real one.

No controller? The Sim GUI can use the keyboard as a joystick: drag **Keyboard 0** to **Joystick\[0]** (**Joystick\[1]** for Commands v3).

<figure><img src="https://1354553280-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZM0CFmYiQzcrY4zDcTtZ%2Fuploads%2FZdaaTFAtUEcoLKsw3qzY%2FRobot%20Simulation%202025-08-30%2018-37-59.gif?alt=media&amp;token=0b4e3353-320f-4983-9309-d452471b7311" alt="The simulated elevator in its Mechanism2d window, the carriage bar rising and falling between heights as buttons are pressed"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

## What you should see

* Before you enable, the carriage is drawn at 0 m, its starting position, at the bottom.
* When you enable, the default command holds it at 0 m, so it stays at the bottom.
* Holding **A** raises it toward 0.5 m, and holding **B** toward 1 m. Let go, and it goes back down to 0 m. It moves no faster than 0.5 m/s, the limit from the motion profile.
* Holding **X** drives it up, and **Y** drives it down, until the soft limits stop it at 0 m and 2 m.
* It settles below each setpoint, roughly 15 cm with the placeholder gains. That is gravity: `kG` is 0, so only `kP` holds the carriage up, and `kP` only pushes once the carriage has dropped below the setpoint. The next step fixes it.

## If it did not work

* **The elevator is not in the NetworkTables menu.** Look under **Mechanisms**, not **SmartDashboard**.
* **The elevator does not move.** Check the robot is enabled in **Teleoperated** and the controller is on **Joystick\[0]** (**Joystick\[1]** for Commands v3). Commands v3: check you picked `ExampleTeleop`, and that `Robot.simulationInit()` starts the elevator's simulation with `startSimulation(...)`.
* **The code stops with an error when the simulation starts.** Read the first error. YAMS names the setting that is missing, such as soft limits in meters set before `withDrumRadius`.

More problems and fixes: [Troubleshooting](https://yams.yassrobotics.com/documentation/tutorials/troubleshooting.md).


---

# 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://yams.yassrobotics.com/documentation/tutorials/elevator/simulate.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.
