Skip to content
learnFRC.org
programmingexample

Pivoting Slapdown Intake Subsystem

Production pivoting ground intake coordinating an articulated wrist pivot with high-torque intake rollers and current-spike piece detection.

Modern competitive FRC robots frequently use an articulated slapdown intake: a mechanism that pivots outside the bumper perimeter to collect game pieces, then retracts inside the frame to protect the rollers from defense hits.

This production subsystem coordinates two actuators in a single encapsulated mechanism:

  1. Pivot Wrist: High-reduction rotary joint driven by a Talon FX with an absolute CANcoder and cosine-scaled gravity feedforward.
  2. Intake Rollers: High-speed polyurethane rollers driven by a Talon FX with stator current-spike game-piece detection.

package frc.robot.subsystems;
import com.ctre.phoenix6.configs.CANcoderConfiguration;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.MotionMagicVoltage;
import com.ctre.phoenix6.controls.VoltageOut;
import com.ctre.phoenix6.hardware.CANcoder;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.GravityTypeValue;
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.units.measure.Voltage;
import static edu.wpi.first.units.Units.*;
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;
public class PivotingIntakeSubsystem extends SubsystemBase {
// Hardware handles
private final TalonFX m_pivotMotor = new TalonFX(20, "rio");
private final CANcoder m_pivotEncoder = new CANcoder(21, "rio");
private final TalonFX m_rollerMotor = new TalonFX(22, "rio");
// Kinematics: 50:1 planetary gearbox reduction between pivot motor and intake arm
private static final double PIVOT_GEAR_RATIO = 50.0;
// Presets
public static final Angle STOW_ANGLE = Degrees.of(90.0); // Vertical inside robot
public static final Angle DEPLOY_ANGLE = Degrees.of(-10.0); // Down onto carpet
public static final Angle HANDOFF_ANGLE = Degrees.of(45.0); // Feeding into indexer
// Reusable control requests
private final MotionMagicVoltage m_pivotMotionMagic = new MotionMagicVoltage(0).withSlot(0);
private final VoltageOut m_rollerVoltage = new VoltageOut(0);
// Current spike detection for game-piece capture
private static final double CURRENT_SPIKE_AMPS = 28.0;
private int m_spikeDebounce = 0;
public PivotingIntakeSubsystem() {
configureHardware();
setDefaultCommand(holdStowedCommand());
}
private void configureHardware() {
// 1. Pivot CANcoder configuration
CANcoderConfiguration coderCfg = new CANcoderConfiguration();
coderCfg.MagnetSensor.MagnetOffset = 0.235; // Calibrated offset in rotations
m_pivotEncoder.getConfigurator().apply(coderCfg);
// 2. Pivot Motor configuration
TalonFXConfiguration pivotCfg = new TalonFXConfiguration();
pivotCfg.MotorOutput.NeutralMode = NeutralModeValue.Brake;
pivotCfg.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
// Current limits on pivot to prevent motor burnout when jammed against carpet
pivotCfg.CurrentLimits.StatorCurrentLimitEnable = true;
pivotCfg.CurrentLimits.StatorCurrentLimit = 40.0;
// Soft limits: prevent arm from hyperextending beyond mechanical hardstops
pivotCfg.SoftwareLimitSwitch.ReverseSoftLimitEnable = true;
pivotCfg.SoftwareLimitSwitch.ReverseSoftLimitThreshold = (-18.0 / 360.0) * PIVOT_GEAR_RATIO;
pivotCfg.SoftwareLimitSwitch.ForwardSoftLimitEnable = true;
pivotCfg.SoftwareLimitSwitch.ForwardSoftLimitThreshold = (95.0 / 360.0) * PIVOT_GEAR_RATIO;
// Slot 0 Gains with Cosine Gravity Feedforward
pivotCfg.Slot0.GravityType = GravityTypeValue.Arm_Cosine;
pivotCfg.Slot0.kG = 0.48; // 0.48V to hold intake horizontal (0°)
pivotCfg.Slot0.kS = 0.20;
pivotCfg.Slot0.kV = 0.12;
pivotCfg.Slot0.kP = 5.50;
pivotCfg.Slot0.kD = 0.22;
// Motion Magic kinematic constraints
pivotCfg.MotionMagic.MotionMagicCruiseVelocity = 0.8 * PIVOT_GEAR_RATIO; // 0.8 rot/s = 288 deg/s
pivotCfg.MotionMagic.MotionMagicAcceleration = 2.0 * PIVOT_GEAR_RATIO;
pivotCfg.MotionMagic.MotionMagicJerk = 20.0 * PIVOT_GEAR_RATIO;
m_pivotMotor.getConfigurator().apply(pivotCfg);
// Seed motor position from absolute CANcoder
double initialAngleRotations = m_pivotEncoder.getAbsolutePosition().getValueAsDouble();
m_pivotMotor.setPosition(initialAngleRotations * PIVOT_GEAR_RATIO);
// 3. Roller Motor configuration
TalonFXConfiguration rollerCfg = new TalonFXConfiguration();
rollerCfg.MotorOutput.NeutralMode = NeutralModeValue.Brake;
rollerCfg.CurrentLimits.StatorCurrentLimitEnable = true;
rollerCfg.CurrentLimits.StatorCurrentLimit = 35.0; // 35A max roller current
m_rollerMotor.getConfigurator().apply(rollerCfg);
}
@Override
public void periodic() {
double currentAngleDeg = (m_pivotMotor.getPosition().getValueAsDouble() / PIVOT_GEAR_RATIO) * 360.0;
double rollerStatorCurrent = m_rollerMotor.getStatorCurrent().getValueAsDouble();
SmartDashboard.putNumber("Intake/PivotAngle_deg", currentAngleDeg);
SmartDashboard.putNumber("Intake/RollerCurrent_A", rollerStatorCurrent);
SmartDashboard.putBoolean("Intake/HasPiece", hasGamePiece());
// Debounce current spike (must exceed threshold for 3 cycles = 60ms)
if (rollerStatorCurrent > CURRENT_SPIKE_AMPS) {
m_spikeDebounce++;
} else {
m_spikeDebounce = 0;
}
}
public boolean hasGamePiece() {
return m_spikeDebounce >= 3;
}
public boolean isPivotAtAngle(Angle targetAngle) {
double currentAngleDeg = (m_pivotMotor.getPosition().getValueAsDouble() / PIVOT_GEAR_RATIO) * 360.0;
return Math.abs(currentAngleDeg - targetAngle.in(Degrees)) < 2.5;
}
/**
* Move pivot to angle using Motion Magic.
*/
public Command setPivotAngleCommand(Angle targetAngle) {
double targetRot = (targetAngle.in(Degrees) / 360.0) * PIVOT_GEAR_RATIO;
return run(() -> m_pivotMotor.setControl(m_pivotMotionMagic.withPosition(targetRot)))
.until(() -> isPivotAtAngle(targetAngle))
.withName("SetPivotAngle");
}
/**
* Run rollers at specified voltage.
*/
public Command runRollersCommand(Voltage voltage) {
return run(() -> m_rollerMotor.setControl(m_rollerVoltage.withOutput(voltage.in(Volts))))
.withName("RunRollers");
}
public Command stopRollersCommand() {
return runOnce(() -> m_rollerMotor.setControl(m_rollerVoltage.withOutput(0)))
.withName("StopRollers");
}
/**
* Complete Automated Intake Routine:
* 1. Deploy pivot to carpet and spin rollers.
* 2. Automatically stop rollers and retract pivot when game piece current spike is detected.
*/
public Command autoIntakeAndRetractCommand() {
return Commands.sequence(
// Deploy and spin until game piece acquired
Commands.parallel(
setPivotAngleCommand(DEPLOY_ANGLE),
runRollersCommand(Volts.of(10.0))
).until(this::hasGamePiece),
// Immediately stop rollers and stow arm inside robot
stopRollersCommand(),
setPivotAngleCommand(STOW_ANGLE)
).withName("AutoIntakeAndRetract");
}
public Command holdStowedCommand() {
double stowRot = (STOW_ANGLE.in(Degrees) / 360.0) * PIVOT_GEAR_RATIO;
return run(() -> {
m_pivotMotor.setControl(m_pivotMotionMagic.withPosition(stowRot));
m_rollerMotor.setControl(m_rollerVoltage.withOutput(0));
}).withName("HoldStowed");
}
}

Notice line 75: m_pivotMotor.setPosition(initialAngleRotations * PIVOT_GEAR_RATIO). Because the CANcoder is mounted directly on the final output shaft (1:1 ratio), its reading represents the true absolute orientation of the intake relative to the horizon. Seeding the motor’s internal encoder on boot allows the motor controller to run 1 kHz onboard closed loops using the motor’s high-resolution rotor sensor without losing absolute calibration.

When the intake is deployed outside the robot, opposing robots can ram into it. Stator current limits (40A) allow the pivot to be pushed without stripping gears or overheating the Kraken/Falcon windings.