> 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/api-reference/java-reference/swerve/swerve-module.md). Agents can also search and read this documentation through its [MCP server](https://yams.yassrobotics.com/~gitbook/mcp).

# SwerveModule

**Package:** `yams.core.mechanisms.swerve`\
**Javadoc:** [`SwerveModule`](https://javadocs.yassrobotics.com/yams/yams/core/mechanisms/swerve/SwerveModule.html)

Represents one swerve module: a drive motor and an azimuth (steering) motor. You construct one `SwerveModule` per corner and pass them to the [`SwerveDriveConfig`](https://yams.yassrobotics.com/api-reference/java-reference/swerve/swerve-drive-config.md); `SwerveDrive` then manages them. The same class is used with Commands v2 and Commands v3.

## Constructor

```java
SwerveModule(SwerveModuleConfig config)
```

| Parameter | Type                 | Description                                                                |
| --------- | -------------------- | -------------------------------------------------------------------------- |
| `config`  | `SwerveModuleConfig` | Module-level configuration including motors, encoder offset, and location. |

***

## State

| Method                         | Returns                           | Description                                                                                                                                  |
| ------------------------------ | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `getState()`                   | `SwerveModuleVelocityWithAzimuth` | Current drive velocity and azimuth angle, plus how fast the azimuth is turning (`azimuthVelocity`). Extends WPILib's `SwerveModuleVelocity`. |
| `getPosition()`                | `SwerveModulePosition`            | Integrated drive distance and azimuth angle.                                                                                                 |
| `getName()`                    | `String`                          | Module name as set in config.                                                                                                                |
| `getConfig()`                  | `SwerveModuleConfig`              | The configuration this module was constructed with.                                                                                          |
| `getRawAbsoluteEncoderAngle()` | `Angle`                           | Absolute encoder angle with no offset applied.                                                                                               |
| `getDriveMotorController()`    | `SmartMotorController`            | The drive motor.                                                                                                                             |
| `getAzimuthMotorController()`  | `SmartMotorController`            | The azimuth motor.                                                                                                                           |

***

## Control

| Method                                                                     | Returns                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------------------------------------------------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `setSwerveModuleState(SwerveModuleVelocity state)`                         | `SwerveModuleVelocity` | Commands a drive speed and azimuth angle. Returns the optimized state actually sent.                                                                                                                                                                                                                                                                                                                                                               |
| `setSwerveModuleState(SwerveModuleVelocity state, Force feedforwardForce)` | `SwerveModuleVelocity` | Same, plus a drive-wheel feedforward `Force` applied on top (e.g. from a PathPlanner setpoint generator). The force is reversed when optimization turns the wheel around and scaled by cosine compensation when enabled.                                                                                                                                                                                                                           |
| `setAzimuthAngle(Rotation2d angle)`                                        | `SwerveModuleVelocity` | Turns the wheel to `angle` without driving it, as for locking the drive in place or tuning the azimuth motor. Unlike `setSwerveModuleState`, the velocity deadband does not hold the wheel where it is (see [`SwerveModuleConfig.getLockedState(...)`](https://yams.yassrobotics.com/api-reference/java-reference/swerve/swerve-module-config.md#state-helpers)). Used by `SwerveDrive.lockPose()` and `SwerveDrive.setAzimuthAngles(Rotation2d)`. |
| `getCouplingVelocity()`                                                    | `LinearVelocity`       | The wheel velocity the drive encoder reads because the azimuth is turning, which a drive held still must be commanded to.                                                                                                                                                                                                                                                                                                                          |
| `seedAzimuthEncoder()`                                                     | `void`                 | Reads the absolute encoder and seeds the relative encoder to match. Call on robot enable.                                                                                                                                                                                                                                                                                                                                                          |

***

## Lifecycle

| Method              | Returns | Description                                                                                       |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------- |
| `updateTelemetry()` | `void`  | Publishes module state and encoder readings to NetworkTables, and updates both motors' telemetry. |
| `simIterate()`      | `void`  | Advances module simulation by one loop iteration.                                                 |

***

## Telemetry and DataLog

`setupTelemetry(String mechName)` wires up this module's telemetry under `Mechanisms/<mechName>/modules/<moduleName>`; `SwerveDrive` calls it automatically for every module during its own construction, so you don't normally call it yourself. `updateTelemetry()` then publishes this module's `SwerveModuleVelocity` and absolute encoder angle to NetworkTables at the verbosity from `SwerveModuleConfig.getTelemetryVerbosity()`, or from an explicit `SwerveModuleTelemetryConfig` passed via `SwerveModuleConfig.withTelemetry(name, SwerveModuleTelemetryConfig)`; see [SwerveModuleConfig](https://yams.yassrobotics.com/api-reference/java-reference/swerve/swerve-module-config.md#datalog-telemetry) for how to additionally record fields to a WPILib DataLog. For field-level control (or a DataLog name) on the drive/azimuth motors themselves, configure each motor's own `SmartMotorControllerConfig.withTelemetry(name, SmartMotorControllerTelemetryConfig)`.

{% hint style="warning" %}
`SwerveModuleConfig` has no `withDataLogName(String)` method: `setupTelemetry(...)` only consults the `SwerveModuleTelemetryConfig`'s own, separate DataLog name. Use `SwerveModuleConfig.withTelemetry(name, new SwerveModuleTelemetryConfig().withDataLogName(...))` instead; see [SwerveModuleConfig](https://yams.yassrobotics.com/api-reference/java-reference/swerve/swerve-module-config.md#datalog-telemetry).
{% endhint %}

***

## See also

* [SwerveModuleConfig](https://yams.yassrobotics.com/api-reference/java-reference/swerve/swerve-module-config.md)
* [C++ SwerveModule](https://yams.yassrobotics.com/api-reference/c++-reference/swerve/swerve-module.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/api-reference/java-reference/swerve/swerve-module.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.
