# Simulation

## How it works?

YAGSL Simulates the entire robot using the same simulation modules provided by vendors to varying degrees of support. There is an entirely simulated SwerveModule named `SwerveModuleSimulation` and `SwerveIMUSimulation` which provide necessary data.

## How do I enable it?

{% hint style="warning" %}
Cosine compensation and heading correction should be disabled when running simulation or else the simulation may be uncontrollable!
{% endhint %}

For simulation to work properly all you have to do is ensure that heading compensation and cosine compensation are disabled like in the example below.

<pre class="language-java"><code class="lang-java"> /**
   * Initialize {@link SwerveDrive} with the directory provided.
   *
   * @param directory Directory of swerve drive config files.
   */
  public SwerveSubsystem(File directory)
  {
    // Configure the Telemetry before creating the SwerveDrive to avoid unnecessary objects being created.
    SwerveDriveTelemetry.verbosity = TelemetryVerbosity.HIGH;
    swerveDrive = new SwerveParser(directory).createSwerveDrive(Constants.MAX_SPEED);
<strong>    swerveDrive.setHeadingCorrection(false); // Heading correction should only be used while controlling the robot via angle.
</strong><strong>    swerveDrive.setCosineCompensator(false); // Disables cosine compensation for simulations since it causes discrepancies not seen in real life.
</strong>  }
</code></pre>

Then run simulation like you normally would in wpilib.

For more information checkout WPILib documentaiton on simulation!

{% embed url="<https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/robot-simulation/introduction.html>" %}


---

# 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.yagsl.com/overview/our-features/simulation.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.
