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

# DifferentialMechanismConfig

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

`DifferentialMechanismConfig` configures a two-motor differential mechanism. Unlike the other config classes, it holds the two motor controllers. Supply them in the constructor, or with `withSmartMotorControllers(...)` once; they cannot be replaced after they are set.

All builder methods return the `DifferentialMechanismConfig` instance for chaining.

See also: [DifferentialMechanism](https://yams.yassrobotics.com/api-reference/java-reference/mechanisms/differential-mechanism.md)

***

## Constructor

```java
DifferentialMechanismConfig(SmartMotorController left, SmartMotorController right)
DifferentialMechanismConfig()  // call withSmartMotorControllers(...) before use
DifferentialMechanismConfig clone()  // Copy
```

| Parameter | Type                   | Description                                                                        |
| --------- | ---------------------- | ---------------------------------------------------------------------------------- |
| `left`    | `SmartMotorController` | The "left" motor. Its output mixes with the right motor to produce tilt and twist. |
| `right`   | `SmartMotorController` | The "right" motor.                                                                 |

Both motor controllers, a starting tilt and twist, and a length are **required** before the config is used by a `DifferentialMechanism`; it throws `DifferentialMechanismConfigurationException` otherwise. The default movement plane is XY.

***

## Builder methods

| Method                                                                             | Parameters                                             | Description                                                                                                                                                                                                                 |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `withSmartMotorControllers(SmartMotorController left, SmartMotorController right)` | `left`, `right`: motor controllers                     | Sets the motor controllers when the no-argument constructor was used. Throws `DifferentialMechanismConfigurationException` if they are already set.                                                                         |
| `withStartingPosition(Angle tilt, Angle twist)`                                    | `tilt`, `twist`: starting angles                       | **Required** (or set both individually below). Seeds both encoders with an initial tilt and twist.                                                                                                                          |
| `withTiltStartingPosition(Angle startingPosition)`                                 | `startingPosition`: starting tilt angle                | Seeds the tilt encoder with an initial position. A tilt starting position is required.                                                                                                                                      |
| `withTwistStartingPosition(Angle startingPosition)`                                | `startingPosition`: starting twist angle               | Seeds the twist encoder with an initial position. A twist starting position is required.                                                                                                                                    |
| `withAngleSuppliers(Supplier<Angle> twistSupplier, Supplier<Angle> tiltSupplier)`  | absolute angle suppliers                               | Supplies absolute encoder readings for twist and tilt. Optional.                                                                                                                                                            |
| `withGearing(MechanismGearing gearing)`                                            | `gearing`: bevel gearing                               | Twist gearing when the bevel gears are not 1:1, separate from the motor gearing. Optional.                                                                                                                                  |
| `withLength(Distance length)`                                                      | `length`: arm length                                   | **Required.** Sets the mechanism arm length, used to compute the end position (also set by `withMOI(Distance, Mass)`).                                                                                                      |
| `withMOI(Distance length, Mass weight)`                                            | `length`: arm length, `weight`: arm mass               | Sets the length and estimates the moment of inertia for simulation.                                                                                                                                                         |
| `withMOI(MomentOfInertia MOI)`                                                     | `MOI`: moment of inertia                               | Sets the moment of inertia for simulation directly. An MOI is required in simulation.                                                                                                                                       |
| `withTelemetry(String name, TelemetryVerbosity verbosity)`                         | `name`: NT key prefix, `verbosity`: `LOW`/`MID`/`HIGH` | Enables NetworkTables telemetry for this mechanism. Optional.                                                                                                                                                               |
| `withSimColor(Color8Bit color)`                                                    | `color`: RGB color                                     | Sets the Mechanism2d visualization color. Optional.                                                                                                                                                                         |
| `withMechanismPositionConfig(MechanismPositionConfig config)`                      | `config`: position config                              | Where the mechanism is on the robot, for `getPose3d()`, and the plane it moves in. See [MechanismPositionConfig](https://yams.yassrobotics.com/api-reference/java-reference/config/mechanism-position-config.md). Optional. |

Other methods: `applyConfig()` reapplies both motor controller configs, and the getters `getLeftMotorController()`, `getRightMotorController()`, `getMOI()`, `getLength()`, `getTwistGearing()`, `getStartingTiltAngle()`, `getStartingTwistAngle()`, `getTiltAngleSupplier()`, `getTwistAngleSupplier()`, `getTelemetryName()`, `getTelemetryVerbosity()`, `getSimColor()` and `getMechanismPositionConfig()`. `getTiltAngle(Angle left, Angle right)`, `getTwistAngle(Angle left, Angle right)`, `getLeftMechanismPosition(Angle tilt, Angle twist)` and `getRightMechanismPosition(Angle tilt, Angle twist)` convert between motor and tilt/twist positions.

***

## Example

```java
SmartMotorController leftSMC = new SparkWrapper(
    new SparkMax(CANPort.CAN_S0, 1, MotorType.kBrushless),
    DCMotor.getNEO(1),
    leftConfig
);
SmartMotorController rightSMC = new SparkWrapper(
    new SparkMax(CANPort.CAN_S0, 2, MotorType.kBrushless),
    DCMotor.getNEO(1),
    rightConfig
);

DifferentialMechanismConfig config = new DifferentialMechanismConfig(leftSMC, rightSMC)
    .withStartingPosition(Degrees.of(90), Degrees.of(0))
    .withMOI(Inches.of(12), Pounds.of(4))
    .withTelemetry("Wrist", TelemetryVerbosity.HIGH);
```

{% @github-files/github-code-block url="<https://github.com/Yet-Another-Software-Suite/YAMS/blob/master/examples/commands2/simple_robot-2027/src/main/java/first/robot/subsystems/DiffyMechSubsystem.java#L64-L68>" %}


---

# 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/config/differential-mechanism-config.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.
