Skip to content

Commit 2b34350

Browse files
committed
[UNVERIFIED] Initial Intake subsystem
1 parent de46fd2 commit 2b34350

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
package frc.robot.subsystems.intake;
6+
7+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
8+
9+
public class Intake extends SubsystemBase {
10+
11+
IntakeIO io;
12+
/** Creates a new Intake. */
13+
public Intake(IntakeIO io)
14+
{
15+
this.io = io;
16+
}
17+
18+
@Override
19+
public void periodic() {
20+
// This method will be called once per scheduler run
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package frc.robot.subsystems.intake;
2+
3+
public class IntakeConstants {
4+
5+
6+
public static final int SPINNER_CAN_ID = 20;
7+
public static final int INTAKE_EXTENDER_CAN_ID = 21;
8+
9+
public static final double extendedPosition = 1000;
10+
public static final double foldedPosition = 0;
11+
12+
public static final double MotorReduction = 4*4*5;
13+
public static final double BeltReduction = 2.0;
14+
15+
public static final double extenderPID_P = 0.5;
16+
public static final double extenderPID_I = 0.0;
17+
public static final double extenderPID_D = 0.0;
18+
public static final double extenderPID_MINIMUM = -1.0;
19+
public static final double extenderPID_MAXIMUM = 1.0;
20+
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package frc.robot.subsystems.intake;
2+
3+
import org.littletonrobotics.junction.AutoLog;
4+
5+
import com.revrobotics.spark.SparkBase.Faults;
6+
7+
import edu.wpi.first.math.geometry.Rotation2d;
8+
9+
public interface IntakeIO {
10+
@AutoLog
11+
public static class IntakeIOInputs
12+
{
13+
public Rotation2d intakePosition = new Rotation2d();
14+
public double intakeSpeed = 0.0;
15+
16+
17+
public double spinnerSpeed = 0.0;
18+
19+
// intake motors volts and ampers
20+
public double spinnerVoltage = 0.0;
21+
public double spinnerAmperage = 0.0;
22+
public double intakeVoltage = 0.0;
23+
public double intakeAmperage = 0.0;
24+
25+
//faults
26+
public Faults spinnerFaults = new Faults(0);
27+
public Faults extenderFaults = new Faults(0);
28+
29+
30+
}
31+
32+
public default void updateInputs(IntakeIOInputs inputs) {}
33+
34+
public default void setSpinnerSpeed(double speed) {}
35+
36+
public default void setIntakePosition(double setpoint) {}
37+
38+
public default void extendIntake() { this.setIntakePosition(IntakeConstants.extendedPosition);}
39+
40+
public default void foldIntake() { this.setIntakePosition(IntakeConstants.foldedPosition);}
41+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package frc.robot.subsystems.intake;
2+
3+
import com.revrobotics.AbsoluteEncoder;
4+
import com.revrobotics.PersistMode;
5+
import com.revrobotics.ResetMode;
6+
import com.revrobotics.spark.FeedbackSensor;
7+
import com.revrobotics.spark.SparkClosedLoopController;
8+
import com.revrobotics.spark.SparkMax;
9+
import com.revrobotics.spark.SparkBase.ControlType;
10+
import com.revrobotics.spark.SparkLowLevel.MotorType;
11+
import com.revrobotics.spark.config.SparkMaxConfig;
12+
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
13+
14+
import edu.wpi.first.math.geometry.Rotation2d;
15+
16+
public class IntakeIOSpark implements IntakeIO {
17+
18+
private SparkMax extenderMotor = new SparkMax(IntakeConstants.INTAKE_EXTENDER_CAN_ID, MotorType.kBrushless);
19+
private SparkMax spinnerMotor = new SparkMax(IntakeConstants.SPINNER_CAN_ID, MotorType.kBrushless);
20+
21+
private AbsoluteEncoder extenderEncoder;
22+
SparkClosedLoopController extenderController;
23+
24+
public IntakeIOSpark()
25+
{
26+
SparkMaxConfig extenderConfig = new SparkMaxConfig();
27+
28+
extenderConfig
29+
.openLoopRampRate(0.5)
30+
.closedLoopRampRate(0.5)
31+
.smartCurrentLimit(30)
32+
.idleMode(IdleMode.kBrake);
33+
34+
extenderConfig.closedLoop
35+
.p(IntakeConstants.extenderPID_P)
36+
.i(IntakeConstants.extenderPID_I)
37+
.d(IntakeConstants.extenderPID_D)
38+
.outputRange(IntakeConstants.extenderPID_MINIMUM,
39+
IntakeConstants.extenderPID_MAXIMUM)
40+
.feedbackSensor(FeedbackSensor.kAbsoluteEncoder);
41+
42+
extenderMotor.configure(extenderConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
43+
44+
extenderController = extenderMotor.getClosedLoopController();
45+
extenderEncoder = extenderMotor.getAbsoluteEncoder();
46+
47+
48+
SparkMaxConfig spinnerConfig = new SparkMaxConfig();
49+
spinnerConfig.inverted(true)
50+
.idleMode(IdleMode.kCoast)
51+
.smartCurrentLimit(30);
52+
53+
spinnerMotor.configure(spinnerConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
54+
}
55+
56+
@Override
57+
public void updateInputs(IntakeIOInputs inputs)
58+
{
59+
inputs.intakeAmperage = extenderMotor.getOutputCurrent();
60+
inputs.intakeVoltage = extenderMotor.getAppliedOutput() * extenderMotor.getBusVoltage();
61+
inputs.intakePosition = new Rotation2d(extenderEncoder.getPosition());
62+
inputs.intakeSpeed = extenderEncoder.getVelocity();
63+
64+
inputs.spinnerAmperage = spinnerMotor.getOutputCurrent();
65+
inputs.spinnerVoltage = spinnerMotor.getAppliedOutput() * spinnerMotor.getBusVoltage();
66+
inputs.spinnerSpeed = spinnerMotor.getEncoder().getVelocity();
67+
68+
inputs.spinnerFaults = spinnerMotor.getFaults();
69+
inputs.extenderFaults = extenderMotor.getFaults();
70+
}
71+
72+
@Override
73+
public void setSpinnerSpeed(double speed)
74+
{
75+
spinnerMotor.set(speed);
76+
}
77+
@Override
78+
public void setIntakePosition(double setpoint) {
79+
extenderController.setSetpoint(setpoint, ControlType.kPosition);
80+
}
81+
82+
}

0 commit comments

Comments
 (0)