# Intake Subsystem Documentation
 
## Overview
The `Intake` subsystem controls the intake mechanism of the robot, which is responsible for collecting game pieces. The subsystem uses a single brushless motor, an encoder for feedback, and two beam break sensors to detect the presence of objects.
 
### Features:
- Single motor control for intake speed
- Beam break sensors for object detection
- Encoder feedback for motor velocity monitoring
- SmartDashboard integration for telemetry and tuning
 
---
 
## Code Overview
 
### Motor Initialization
The subsystem initializes a `CANSparkMax` motor to control the intake mechanism:
 
```java
intakeNeo1 = new CANSparkMax(id, MotorType.kBrushless);
intakeNeo1.setInverted(false);
intakeNeo1.setIdleMode(IdleMode.kBrake);
  • Motor (intakeNeo1): Brushless motor that drives the intake mechanism.
  • Inverted: The motor is not inverted, meaning it operates in its normal direction.
  • Idle Mode: The motor is set to brake mode to stop when power is cut.

Encoder Initialization

A relative encoder is attached to the motor to monitor its velocity:

intakeEncoder = intakeNeo1.getEncoder();
SmartDashboard.putNumber("ProcessVariable", intakeEncoder.getVelocity());

This allows the motor’s speed to be monitored and adjusted if needed.


Object Detection

Beam Break Sensors

Two DigitalInput beam break sensors are used to detect objects in the intake:

private DigitalInput beamBreakOvershoot = new DigitalInput(1);
private DigitalInput beamBreakNote = new DigitalInput(2);
  • Beam Break 1 (Overshoot): Detects whether an object has fully passed through the intake.
  • Beam Break 2 (Note): Detects whether an object is currently being intaken.

These sensors are used to control the logic of whether an object is being collected or has passed through the intake.

Object Detection Logic

  • getOvershootBeam(): Returns the state of the overshoot sensor, which indicates whether the object has been fully collected.
  • getNoteBeam(): Returns the state of the note sensor, which indicates whether the object is currently in the process of being intaken.

Object State Methods

  • getRing(): Returns whether the intake has an object (hasRing flag).
  • ringTrue(): Sets the hasRing flag to true, indicating the presence of an object.
  • ringFalse(): Sets the hasRing flag to false, indicating no object is present.

Movement Control

move(double speed)

Sets the intake motor speed, allowing for manual control of the intake mechanism:

public void move(double speed) {
    intakeNeo1.set(speed);
}

stopIntake()

Stops the intake motor by setting its speed to zero:

public void stopIntake() {
    intakeNeo1.set(0);
}

These methods provide simple control for the intake mechanism, enabling the intake motor to run at a specific speed or stop completely.


Telemetry

The subsystem uses the SmartDashboard to display telemetry data for debugging and tuning:

SmartDashboard.putBoolean("intake//Beam Break Overshoot", beamBreakOvershoot.get());
SmartDashboard.putBoolean("intake//Beam Break Overshoot has Ring", hasRing);
SmartDashboard.putBoolean("intake//Beam Break Intaking", beamBreakNote.get());
  • Beam Break Overshoot: Displays whether the overshoot beam is triggered.
  • Has Ring: Displays whether the system has detected an object.
  • Beam Break Intaking: Displays whether the intake is currently intaking an object.

Periodic Functions

periodic()

This method runs every scheduler cycle and updates the state of the sensors and SmartDashboard telemetry:

@Override
public void periodic() {
    if (beamBreakOvershoot.get() == false) {
        ringTrue();
    } else { 
        ringFalse();
    }
 
    if (beamBreakNote.get() == false) {
        intakingRing = true;
    } else {
        intakingRing = false;
    }
 
    SmartDashboard.putBoolean("intake//Beam Break Overshoot", beamBreakOvershoot.get());
    SmartDashboard.putBoolean("intake//Beam Break Overshoot has Ring", hasRing);
    SmartDashboard.putBoolean("intake//Beam Break Intaking", beamBreakNote.get());
}

The periodic() method continually checks the state of the beam break sensors and updates the status of whether an object is detected or being intaken.

simulationPeriodic()

This method is used when running simulations.

@Override
public void simulationPeriodic() {
    // This method will be called once per scheduler run during simulation
}

Future Enhancements

  • Integrate additional logic for controlling the intake speed based on object detection.
  • Use encoder feedback to implement speed control for more consistent intake performance.
  • Further enhance the SmartDashboard telemetry with additional intake status information.

This documentation provides a clear explanation of the Intake subsystem, including its movement control, object detection via beam break sensors, and telemetry integration. It also suggests future enhancements for improving performance and control.