# State-Based Roller Subsystems

### What is a Roller Subsystem?

A **roller subsystem** controls motors that intake, outtake, or hold game pieces using spinning rollers. These subsystems vary from simple single-motor controllers to more complex ones managing multiple motors working together.

There are two main patterns in our codebase for roller subsystems:

* **Basic Single-Motor Roller Subsystems**
* **Composite Multi-Motor Roller Subsystems**

***

{% hint style="danger" %}
We no longer use these patterns, will update when I have time (Although it is fairly similar). See RobotController.java‘s endEffectorRollers for Basic roller subsystem replacement. See IntakeRollers.java for a composite Subsytsem replacement.
{% endhint %}

### 1. Basic Roller Subsystems

#### Example: `EndEffectorRollers`

The `EndEffectorRollers` class is a simple roller subsystem controlling one motor. It extends the base class:

```java
class EndEffectorRollers extends BasicStateBasedRollerSubsystem<EndEffectorRollers.State>
```

* Each state in `EndEffectorRollers.State` represents a voltage to apply to the motor.
* The control mode is usually `VOLTAGE`, directly controlling motor output.

```java
enum State implements BasicRollerState {
    IDLE(0.0),
    HOLD(-2.0),
    CORAL_INTAKE(-4.0),
    // other states...
}
```

**When to use:**\
This pattern is ideal for simple rollers with straightforward control requirements, like a single flywheel or a roller that only needs on/off/hold states.

***

### 2. Composite Roller Subsystems

#### Example: `IntakeRollers`

`IntakeRollers` is an example of a **multi-motor roller subsystem** that controls several motors as one logical unit:

```java
class IntakeRollers extends StateBasedRollerSubsystem<IntakeRollers.State>
```

* Controls **three motors**: intake roller, indexer bottom, and indexer sides.
* Each state provides an array of voltages for all three motors.

```java
enum State implements RollerState {
    IDLE(0,0,0),
    INTAKING(10.0, 2.5, 8),
    EXHAUST(-6, -6, -6),
    // other states...
}
```

* Each motor can have its own voltage, but they are managed **together** as a single subsystem.

**Benefits:**

* Centralizes control logic for related motors.
* Simplifies coordination and reduces complexity in the superstructure.
* Ensures all intake and indexing rollers work in sync.

***

### 3. Control Modes

Our roller subsystems primarily use three common control modes:

* **`ControlState.VOLTAGE`**\
  Directly controls motor output voltage. Most common for rollers because it’s simple and effective for on/off or variable speed control.
* **`ControlState.VELOCITY`**\
  Uses closed-loop velocity control with feedback (e.g., encoders) to maintain a target roller speed. Useful for precise speed regulation during intaking or shooting.
* **`ControlState.OPEN_LOOP`**\
  Sends raw motor power commands without feedback or PID control. Good for very simple or manual control scenarios.
