# Injection System Speed Control

## Speed Profile During Injection Cycle

```mermaid
graph TD
    subgraph States
        IDLE[Idle State]
        ACCEL[Acceleration Phase]
        FULL[Full Speed Phase]
        DECEL[Deceleration Phase]
        POST[Post Flow Phase]
        STOP[Stop State]
    end

    IDLE -->|Start Command| ACCEL
    ACCEL -->|Reached Target Speed| FULL
    FULL -->|Position Threshold| DECEL
    DECEL -->|Low Speed Threshold| POST
    POST -->|Cycle Complete| STOP
    STOP -->|Reset| IDLE

```

## Speed vs Position Profile

```mermaid
xychart-beta
    title "Injection Speed Profile"
    x-axis ["0%", "25%", "50%", "75%", "100%"] ["Position"]
    y-axis "Speed (Hz)" 0 --> 60
    line [0, 50, 50, 20, 5]
    ```

## State Descriptions

- **Idle State**: System at rest, awaiting commands (0 Hz)
- **Acceleration Phase**: Ramps up to full injection speed (0-50 Hz)
- **Full Speed Phase**: Maintains maximum injection speed (50 Hz)
- **Deceleration Phase**: Controlled slowdown (50-20 Hz)
- **Post Flow Phase**: Very slow final movement (5-10 Hz)

## Code Implementation

The speed control is implemented in the App class through the following key methods:

- `plunge()`: Initiates forward movement
- `home()`: Initiates reverse movement
- `stop()`: Halts all movement
- `loopManual()`: Main control loop handling state transitions

### Key Parameters

```cpp
#define MIN_DT_AUTO 500 // Minimum time between auto operations
#define LOOP_DELAY 10 // Main loop delay
```

### Overload Protection

The system includes load monitoring through the MotorLoad class, which can trigger:
- Emergency stops on high load
- Speed adjustments based on load feedback
- Jam detection and recovery
