# SPARK MAX vs SPARK Flex

Generally, the feature sets of the software for SPARK MAX and SPARK Flex are very similar, yet they are still very different devices and should be treated that way in code. Because of this, there are two separate device classes in REVLib: `SparkMax` and `SparkFlex`. Separating them enables better management of feature differences that currently exist or may exist later down the road.

{% hint style="warning" %}
It is important to ensure that the correct class is used for the device you are programming. Using the incorrect class for a SPARK motor controller will result in a warning in the driver station, and some functionalities may not work as intended.&#x20;
{% endhint %}

## Major Differences

### Alternate vs External Encoder

The SPARK MAX supports using an "alternate" encoder while the SPARK Flex supports using an "external" encoder. Though these are largely similar concepts, both providing the ability to measure position and velocity external to the motor's primary encoder, the alternate encoder is limited by its inability to handle high RPM loads. Due to this caveat, separate classes exist: `SparkMaxAlternateEncoder` and `SparkFlexExternalEncoder`.

Additionally, an alternate encoder cannot be used with an absolute encoder and/or limit switches. Attempting to configure or use an alternate encoder alongside an absolute encoder/and or limit switches will throw an exception.

The external encoder on SPARK Flex does not have these limitations. More information about the alternate encoder can be found [here](https://docs.revrobotics.com/brushless/spark-max/encoders/alternate-encoder).

## Migrating between MAX and Flex in REVLib

Since the majority of methods and interfaces in the two classes are largely similar, migrating between MAX and Flex can typically be done with a simple find-and-replace of class names. However, major differences listed above will need to be addressed on a case-by-case basis.

Below is a list of class names that can be interchanged between MAX and Flex:

| SPARK MAX                   | SPARK Flex                  |
| --------------------------- | --------------------------- |
| SparkMax                    | SparkFlex                   |
| SparkMaxConfig              | SparkFlexConfig             |
| SparkMaxConfigAccessor      | SparkFlexConfigAccessor     |
| SparkMaxAlternateEncoder    | SparkFlexExternalEncoder    |
| SparkMaxSim                 | SparkFlexSim                |
| SparkMaxAlternateEncoderSim | SparkFlexExternalEncoderSim |

Below is an example of how you would migrate how a SPARK object is constructed:

{% tabs %}
{% tab title="Java" %}

### SPARK MAX

```java
SparkMax spark = new SparkMax(1, MotorType.kBrushless);
```

### SPARK Flex

```java
SparkFlex spark = new SparkFlex(1, MotorType.kBrushless);
```

{% endtab %}

{% tab title="C++" %}

### SPARK MAX

```cpp
using namespace rev::spark;

SparkMax m_spark{1, SparkMax::MotorType::kBrushless};
```

### SPARK Flex

```cpp
using namespace rev::spark;

SparkFlex m_spark{1, SparkFlex::MotorType::kBrushless};
```

{% endtab %}
{% endtabs %}


---

# 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/revlib/spark/max-vs-flex.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.
