# Using a DetachedEncoder as a SPARK's feedback sensor

A DetachedEncoder, such as the MAXSpline Encoder, may be used as a `FeedbackSensor` for Closed Loop Control in SPARK MAX and SPARK Flex motor controllers.

This is configured in the `ClosedLoopConfig` class using the `feedbackSensor(FeedbackSensor, int)` or `feedbackSensor(FeedbackSensor, DetachedEncoder)` methods as follows:

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

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

SparkFlexConfig sparkConfig = new SparkFlexConfig();
sparkConfig.closedLoop
feedbackSensor(FeedbackSensor.kDetachedAbsoluteEncoder, spline);
  
// Continue with other configuration
```

{% endtab %}

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

```cpp
using namespace rev::detached;
using namespace rev::spark;

SplineEncoder m_spline{12};
SparkFlex m_spark{1, SparkFlex::MotorType::kBrushless};

SparkFlexConfig sparkConfig;
sparkConfig.closedLoop
  .SetFeedbackSensor(FeedbackSensor::kDetachedAbsoluteEncoder, spline);

// Continue with other configuration
```

{% endtab %}
{% endtabs %}

&#x20;


---

# 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/smart-sensors/using-a-detachedencoder-as-a-sparks-feedback-sensor.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.
