Skip to content
learnFRC.org
programmingexample

Beam-Break Indexer & Feeder Subsystem

Staged game-piece indexing and flywheel feeding subsystem with photoelectric beam-break sensors, anti-jamming, and ready-to-fire synchronization.

Between the ground intake and the flywheel shooter sits the Indexer and Feeder Subsystem. Its job is critical:

  1. Accept game pieces from the intake and advance them to a precise staging position.
  2. Hold the game piece securely without rubbing against spinning flywheel wheels.
  3. Rapidly feed the game piece into the flywheels only after the shooter has achieved target RPM.

package frc.robot.subsystems;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.units.measure.Voltage;
import static edu.wpi.first.units.Units.*;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import java.util.function.BooleanSupplier;
public class FeederIndexerSubsystem extends SubsystemBase {
private final TalonFX m_feederMotor = new TalonFX(19, "rio");
// Photoelectric Digital Beam-Break Sensors (DIO 0 and 1)
// Most industrial photoelectric sensors are normally-closed (NC): true = beam clear, false = beam broken
private final DigitalInput m_entryBeamBreak = new DigitalInput(0);
private final DigitalInput m_stagingBeamBreak = new DigitalInput(1);
private final VoltageOut m_voltage = new VoltageOut(0);
public FeederIndexerSubsystem() {
configureHardware();
setDefaultCommand(stopCommand());
}
private void configureHardware() {
TalonFXConfiguration cfg = new TalonFXConfiguration();
cfg.MotorOutput.NeutralMode = NeutralModeValue.Brake;
// Current limits
cfg.CurrentLimits.StatorCurrentLimitEnable = true;
cfg.CurrentLimits.StatorCurrentLimit = 35.0; // 35A stator limit
cfg.CurrentLimits.SupplyCurrentLimitEnable = true;
cfg.CurrentLimits.SupplyCurrentLimit = 30.0;
m_feederMotor.getConfigurator().apply(cfg);
}
@Override
public void periodic() {
SmartDashboard.putBoolean("Feeder/EntryClear", isEntryClear());
SmartDashboard.putBoolean("Feeder/StagingBroken", isStagingBroken());
SmartDashboard.putNumber("Feeder/Current_A", m_feederMotor.getStatorCurrent().getValueAsDouble());
}
/**
* Returns true if entry sensor detects a game piece arriving.
*/
public boolean isEntryBroken() {
return !m_entryBeamBreak.get(); // Inverted because sensor is NC
}
public boolean isEntryClear() {
return m_entryBeamBreak.get();
}
/**
* Returns true if the game piece has reached the staging position just before the flywheels.
*/
public boolean isStagingBroken() {
return !m_stagingBeamBreak.get();
}
public boolean isStagingClear() {
return m_stagingBeamBreak.get();
}
public boolean hasPieceStaged() {
return isStagingBroken();
}
/**
* Automatically pulls the game piece forward until it breaks the staging sensor, then halts.
*/
public Command stagePieceCommand() {
return run(() -> m_feederMotor.setControl(m_voltage.withOutput(7.0)))
.until(this::isStagingBroken)
.andThen(stopCommand())
.withName("StagePiece");
}
/**
* Feeds the piece forward into the flywheels.
* Guaranteed to wait until the shooter flywheel reports isAtSpeed()!
*/
public Command feedToShooterCommand(BooleanSupplier shooterAtSpeedSupplier) {
return Commands.sequence(
// Wait until shooter is spun up to target speed
Commands.waitUntil(shooterAtSpeedSupplier),
// Launch feeder forward at full speed for 0.75 seconds to launch note
run(() -> m_feederMotor.setControl(m_voltage.withOutput(11.0)))
.withTimeout(Seconds.of(0.75)),
stopCommand()
).withName("FeedToShooter");
}
/**
* Un-jam command: reverses the feeder wheels briefly.
*/
public Command reverseCommand() {
return run(() -> m_feederMotor.setControl(m_voltage.withOutput(-8.0)))
.withName("ReverseFeeder");
}
public Command stopCommand() {
return runOnce(() -> m_feederMotor.setControl(m_voltage.withOutput(0)))
.withName("StopFeeder");
}
}

Industrial photoelectric beam-break sensors (such as the Banner QS18 series) connect to the roboRIO DIO ports:

  • Red: +5V DC
  • Black: Ground (0V)
  • Signal (White/Black): roboRIO DIO Signal pin

Most sensors pull the signal line to Ground when the infrared light beam is unobstructed (Normally Closed / NC). When a game piece breaks the optical path, the internal transistor opens, and the roboRIO’s internal 10k pull-up resistor pulls the pin to 5V. In code, !m_sensor.get() therefore indicates a blocked sensor.

Never Feed Flywheels Before Full Speed

Feeding a game piece into flywheels that are only running at 70% speed causes two catastrophic issues:

  1. The shot will land several feet short into the low goal or bounce off the rim.
  2. The game piece will drag the flywheel down further, causing motor current spikes. Notice feedToShooterCommand() strictly requires Commands.waitUntil(shooterAtSpeedSupplier) before energizing the feeder motor.