# Programming MAXSwerve

## MAXSwerve Code Templates

Below are two GitHub Repositories for template projects that will control an FRC swerve drivetrain built with REV MAXSwerve Modules.

Note that this is meant to be used with a drivetrain composed of four MAXSwerve Modules, each configured with two SPARK MAXs, a NEO as the driving motor, a NEO 550 as the steering motor, and a REV Through Bore Encoder as the absolute turning encoder.

### [Java Template](https://github.com/REVrobotics/MAXSwerve-Java-Template)

### [C++ Template](https://github.com/REVrobotics/MAXSwerve-Cpp-Template)

## Adjusting Slew Rate Parameters

Within the **Constants** file for both the Java and C++ MAXSwerve Templates, there are three variables that your team can tune for your robot's Slew Rate needs.  To determine the default values we loaded a test MAXSwerve Drivetrain to approximately 140lbs (Including bumpers and battery) and tuned the parameters until we found values that made the MAXSwerve Wheels last the longest amount of time.&#x20;

### DirectionSlewRate

DirectionSlewRate is the most important parameter for reducing MAXSwerve Wheel failures. Lower values limit the rate of change of the direction of the robot. This avoids high-speed J turns that put destructive side loads on the wheels. Note that direction changes faster than the slew rate are allowed at lower speeds. The value here is the slew rate at 100% linear speed.&#x20;

### MagnitudeSlewRate

The MagnitudeSlewRate, or acceleration, in the linear direction. Generally, adjustments to the direction slew rate should be applied here as well (i.e. both should be increased or both should be reduced).&#x20;

### RotationalSlewRate

RotationalSlewRate is not a major contributor to wheel wear but may help smooth other motions out. If the robot has to do a lot of spinning due to defense or a particular style of mechanism, reducing this could help reduce tread wear.

{% tabs %}
{% tab title="Java Slew Rate Limiting Code Segment" %}

<pre><code>// Driving Parameters - Note that these are not the maximum capable speeds of
// the robot, rather the allowed maximum speeds

<strong>public static final double kMaxSpeedMetersPerSecond = 4.8;
</strong>public static final double kMaxAngularSpeed = 2 * Math.PI; // radians per second

public static final double kDirectionSlewRate = 1.2; // radians per second
public static final double kMagnitudeSlewRate = 1.8; // percent per second (1 = 100%)
public static final double kRotationalSlewRate = 2.0; // percent per second (1 = 100%)

</code></pre>

{% endtab %}

{% tab title="C++ Slew Rate Limiting Code Segment" %}

```clike
// Driving Parameters - Note that these are not the maximum capable speeds of
// the robot, rather the allowed maximum speeds

constexpr units::meters_per_second_t kMaxSpeed = 4.8_mps;
constexpr units::radians_per_second_t kMaxAngularSpeed{2 * std::numbers::pi};

constexpr double kDirectionSlewRate = 1.2;   // radians per second
constexpr double kMagnitudeSlewRate = 1.8;   // percent per second (1 = 100%)
constexpr double kRotationalSlewRate = 2.0;  // percent per second (1 = 100%)

```

{% endtab %}
{% endtabs %}

## MAXSwerve Template Changelog:

#### V2023.1

* Added a configurable rate limiting system to prevent excessive loads from causing premature wheel failure.


---

# 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.revrobotics.com/ion-build/motion/maxswerve/programming-maxswerve.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.
