2026-02-19 17:51:31 -05:00
|
|
|
package frc.robot.subsystems;
|
|
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
|
|
|
|
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.Command;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
|
|
|
|
import edu.wpi.first.wpilibj2.command.WaitCommand;
|
|
|
|
|
import frc.robot.Constants;
|
|
|
|
|
|
|
|
|
|
import com.revrobotics.spark.ClosedLoopSlot;
|
|
|
|
|
import com.revrobotics.spark.SparkBase.PersistMode;
|
|
|
|
|
import com.revrobotics.spark.SparkBase.ResetMode;
|
|
|
|
|
import com.revrobotics.spark.SparkClosedLoopController;
|
|
|
|
|
import com.revrobotics.spark.SparkFlex;
|
|
|
|
|
import com.revrobotics.spark.SparkLowLevel.MotorType;
|
|
|
|
|
import com.revrobotics.spark.config.SparkFlexConfig;
|
|
|
|
|
import com.revrobotics.RelativeEncoder;
|
|
|
|
|
import com.revrobotics.spark.SparkBase.ControlType;
|
|
|
|
|
|
|
|
|
|
public class IntakeSubsystem extends SubsystemBase {
|
|
|
|
|
|
2026-02-19 18:01:14 -05:00
|
|
|
private static SparkFlex intakeWheelsMotor = new SparkFlex(Constants.IntakeConstants.INTAKE_WHEELS_MOTOR_ID,
|
2026-02-19 17:51:31 -05:00
|
|
|
MotorType.kBrushless);
|
|
|
|
|
|
|
|
|
|
private static SparkFlex intakeRotatorMotor = new SparkFlex(Constants.IntakeConstants.INTAKE_ROTATOR_MOTOR_ID,
|
|
|
|
|
MotorType.kBrushless);
|
|
|
|
|
private static SparkClosedLoopController intakeRotatorPIDController;
|
|
|
|
|
public static SparkFlexConfig intakeRotatorConfig = new SparkFlexConfig();
|
|
|
|
|
|
2026-02-19 18:01:14 -05:00
|
|
|
private static SparkClosedLoopController intakeWheelsMotorPIDController;
|
|
|
|
|
public static SparkFlexConfig intakeWheelsMotorConfig = new SparkFlexConfig();
|
|
|
|
|
|
2026-02-19 17:51:31 -05:00
|
|
|
public IntakeSubsystem() {
|
|
|
|
|
intakeRotatorConfig.closedLoop.pid(Constants.IntakeConstants.IntakeRotatorPID.INTAKE_ROTATOR_P,
|
|
|
|
|
Constants.IntakeConstants.IntakeRotatorPID.INTAKE_ROTATOR_I,
|
|
|
|
|
Constants.IntakeConstants.IntakeRotatorPID.INTAKE_ROTATOR_D);
|
|
|
|
|
intakeRotatorMotor.configure(intakeRotatorConfig, com.revrobotics.ResetMode.kNoResetSafeParameters,
|
|
|
|
|
com.revrobotics.PersistMode.kNoPersistParameters);
|
|
|
|
|
intakeRotatorPIDController = intakeRotatorMotor.getClosedLoopController();
|
2026-02-19 18:01:14 -05:00
|
|
|
|
|
|
|
|
intakeWheelsMotorConfig.closedLoop.pid(Constants.ShooterConstants.SHOOTER_MOTOR_P,
|
|
|
|
|
Constants.ShooterConstants.SHOOTER_MOTOR_I,
|
|
|
|
|
Constants.ShooterConstants.SHOOTER_MOTOR_D);
|
|
|
|
|
intakeWheelsMotor.configure(intakeWheelsMotorConfig, com.revrobotics.ResetMode.kNoResetSafeParameters,
|
|
|
|
|
com.revrobotics.PersistMode.kNoPersistParameters);
|
|
|
|
|
intakeWheelsMotorPIDController = intakeWheelsMotor.getClosedLoopController();
|
2026-02-19 17:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startIntakeMotor() {
|
2026-02-19 18:01:14 -05:00
|
|
|
intakeWheelsMotorPIDController.setSetpoint(Constants.IntakeConstants.INTAKE_WHEELS_MOTOR_RPM, ControlType.kVelocity);
|
2026-02-19 17:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void reverseIntakeMotor() {
|
2026-02-19 18:01:14 -05:00
|
|
|
intakeWheelsMotorPIDController.setSetpoint(Constants.IntakeConstants.INTAKE_WHEELS_MOTOR_RPM * -1, ControlType.kVelocity);
|
2026-02-19 17:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopIntakeMotor() {
|
2026-02-20 17:09:46 -05:00
|
|
|
intakeWheelsMotorPIDController.setSetpoint(Constants.IntakeConstants.INTAKE_WHEELS_MOTOR_RPM * -1, ControlType.kVelocity);
|
2026-02-19 17:51:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command startIntakeMotorCommand() {
|
|
|
|
|
return runOnce(() -> startIntakeMotor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command reverseIntakeMotorCommand() {
|
|
|
|
|
return runOnce(() -> reverseIntakeMotor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command stopIntakeMotorCommand() {
|
|
|
|
|
return runOnce(() -> stopIntakeMotor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deployIntake() {
|
|
|
|
|
intakeRotatorPIDController.setSetpoint(Constants.IntakeConstants.INTAKE_COLLECT_ENCODER_VALUE,
|
|
|
|
|
ControlType.kPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command deployintakeCommand() {
|
|
|
|
|
return runOnce(() -> deployIntake());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void retractIntake() {
|
|
|
|
|
intakeRotatorPIDController.setSetpoint(0, ControlType.kPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command retractIntakeCommand() {
|
|
|
|
|
return runOnce(() -> retractIntake());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void assistFuelIntake() {
|
|
|
|
|
intakeRotatorPIDController.setSetpoint(Constants.IntakeConstants.INTAKE_MIDDLE_ENCODER_VALUE,
|
|
|
|
|
ControlType.kPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command assistFuelIntakeCommand() {
|
|
|
|
|
return runOnce(() -> assistFuelIntake()).andThen(new WaitCommand(2)).andThen(deployintakeCommand())
|
|
|
|
|
.andThen(new WaitCommand(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void periodic() {
|
|
|
|
|
SmartDashboard.putNumber("Intake Rotator Motor PID", intakeRotatorMotor.getEncoder().getPosition());
|
|
|
|
|
}
|
|
|
|
|
}
|