Skip to content

Commit b6772a5

Browse files
committed
add shooter subsystem
1 parent 2b34350 commit b6772a5

File tree

8 files changed

+177
-99
lines changed

8 files changed

+177
-99
lines changed

src/main/java/frc/robot/subsystems/intake/Intake.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ public class Intake extends SubsystemBase {
1010

1111
IntakeIO io;
1212
/** Creates a new Intake. */
13-
public Intake(IntakeIO io)
14-
{
13+
public Intake(IntakeIO io) {
1514
this.io = io;
1615
}
1716

src/main/java/frc/robot/subsystems/intake/IntakeConstants.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
public class IntakeConstants {
44

5+
public static final int canSpinnerMotorId = 20;
6+
public static final int canIntakeExtenderMotorId = 21;
57

6-
public static final int SPINNER_CAN_ID = 20;
7-
public static final int INTAKE_EXTENDER_CAN_ID = 21;
8+
public static final double extendedPosition = 1000;
9+
public static final double foldedPosition = 0;
810

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;
11+
public static final double motorReduction = 4 * 4 * 5;
12+
public static final double beltReduction = 2.0;
2013

14+
public static final double extenderClosedLoopControllerP = 0.5;
15+
public static final double extenderClosedLoopControllerI = 0.0;
16+
public static final double extenderClosedLoopControllerD = 0.0;
17+
public static final double extenderClosedLoopControllerMinimumOutput = -1.0;
18+
public static final double extenderClosedLoopControllerMaximumOutput = 1.0;
2119
}
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
package frc.robot.subsystems.intake;
22

3-
import org.littletonrobotics.junction.AutoLog;
4-
53
import com.revrobotics.spark.SparkBase.Faults;
6-
74
import edu.wpi.first.math.geometry.Rotation2d;
5+
import org.littletonrobotics.junction.AutoLog;
86

97
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;
8+
@AutoLog
9+
public static class IntakeIOInputs {
10+
public Rotation2d intakePosition = new Rotation2d();
11+
public double intakeSpeed = 0.0;
2412

25-
//faults
26-
public Faults spinnerFaults = new Faults(0);
27-
public Faults extenderFaults = new Faults(0);
13+
public double spinnerSpeed = 0.0;
2814

15+
// intake motors volts and ampers
16+
public double spinnerVoltage = 0.0;
17+
public double spinnerAmperage = 0.0;
18+
public double intakeVoltage = 0.0;
19+
public double intakeAmperage = 0.0;
2920

30-
}
21+
// faults
22+
public Faults spinnerFaults = new Faults(0);
23+
public Faults extenderFaults = new Faults(0);
24+
}
3125

32-
public default void updateInputs(IntakeIOInputs inputs) {}
26+
public default void updateInputs(IntakeIOInputs inputs) {}
3327

34-
public default void setSpinnerSpeed(double speed) {}
28+
public default void setSpinnerSpeed(double speed) {}
3529

36-
public default void setIntakePosition(double setpoint) {}
30+
public default void setIntakePosition(double setpoint) {}
3731

38-
public default void extendIntake() { this.setIntakePosition(IntakeConstants.extendedPosition);}
32+
public default void extendIntake() {
33+
this.setIntakePosition(IntakeConstants.extendedPosition);
34+
}
3935

40-
public default void foldIntake() { this.setIntakePosition(IntakeConstants.foldedPosition);}
36+
public default void foldIntake() {
37+
this.setIntakePosition(IntakeConstants.foldedPosition);
38+
}
4139
}

src/main/java/frc/robot/subsystems/intake/IntakeIOSpark.java

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,78 @@
44
import com.revrobotics.PersistMode;
55
import com.revrobotics.ResetMode;
66
import com.revrobotics.spark.FeedbackSensor;
7-
import com.revrobotics.spark.SparkClosedLoopController;
8-
import com.revrobotics.spark.SparkMax;
97
import com.revrobotics.spark.SparkBase.ControlType;
8+
import com.revrobotics.spark.SparkClosedLoopController;
109
import com.revrobotics.spark.SparkLowLevel.MotorType;
11-
import com.revrobotics.spark.config.SparkMaxConfig;
10+
import com.revrobotics.spark.SparkMax;
1211
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
13-
12+
import com.revrobotics.spark.config.SparkMaxConfig;
1413
import edu.wpi.first.math.geometry.Rotation2d;
1514

1615
public class IntakeIOSpark implements IntakeIO {
1716

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);
17+
private SparkMax extenderMotor =
18+
new SparkMax(IntakeConstants.canIntakeExtenderMotorId, MotorType.kBrushless);
19+
private SparkMax spinnerMotor =
20+
new SparkMax(IntakeConstants.canSpinnerMotorId, MotorType.kBrushless);
2021

21-
private AbsoluteEncoder extenderEncoder;
22-
SparkClosedLoopController extenderController;
22+
private AbsoluteEncoder extenderEncoder;
23+
SparkClosedLoopController extenderController;
2324

24-
public IntakeIOSpark()
25-
{
26-
SparkMaxConfig extenderConfig = new SparkMaxConfig();
25+
public IntakeIOSpark() {
26+
SparkMaxConfig extenderConfig = new SparkMaxConfig();
2727

28-
extenderConfig
28+
extenderConfig
2929
.openLoopRampRate(0.5)
3030
.closedLoopRampRate(0.5)
3131
.smartCurrentLimit(30)
3232
.idleMode(IdleMode.kBrake);
3333

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)
34+
extenderConfig
35+
.closedLoop
36+
.p(IntakeConstants.extenderClosedLoopControllerP)
37+
.i(IntakeConstants.extenderClosedLoopControllerI)
38+
.d(IntakeConstants.extenderClosedLoopControllerD)
39+
.outputRange(
40+
IntakeConstants.extenderClosedLoopControllerMinimumOutput,
41+
IntakeConstants.extenderClosedLoopControllerMaximumOutput)
4042
.feedbackSensor(FeedbackSensor.kAbsoluteEncoder);
4143

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-
44+
extenderMotor.configure(
45+
extenderConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
46+
47+
extenderController = extenderMotor.getClosedLoopController();
48+
extenderEncoder = extenderMotor.getAbsoluteEncoder();
49+
50+
SparkMaxConfig spinnerConfig = new SparkMaxConfig();
51+
spinnerConfig.inverted(true).idleMode(IdleMode.kCoast).smartCurrentLimit(30);
52+
53+
spinnerMotor.configure(
54+
spinnerConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
55+
}
56+
57+
@Override
58+
public void updateInputs(IntakeIOInputs inputs) {
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+
spinnerMotor.set(speed);
75+
}
76+
77+
@Override
78+
public void setIntakePosition(double setpoint) {
79+
extenderController.setSetpoint(setpoint, ControlType.kPosition);
80+
}
8281
}
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.shooter;
6+
7+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
8+
9+
public class Shooter extends SubsystemBase {
10+
11+
private final ShooterIO io;
12+
13+
/** Creates a new Shootoer. */
14+
public Shooter(ShooterIO io) {
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package frc.robot.subsystems.shooter;
2+
3+
public class ShooterConstants {
4+
public static int canShooterMotorId = 25;
5+
6+
public static boolean shooterMotorInverted = false;
7+
8+
public static double shooterStallCurrentLimit = 40;
9+
public static double shooterFreeCurrentLimit = 40;
10+
11+
public static double shooterTargetVelocity = 100.0;
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package frc.robot.subsystems.shooter;
2+
3+
import com.revrobotics.spark.SparkBase.Faults;
4+
import org.littletonrobotics.junction.AutoLog;
5+
6+
public interface ShooterIO {
7+
8+
@AutoLog
9+
public static class ShooterIOInputs {
10+
public double shooterAmperage = 0.0;
11+
public double shooterVoltage = 0.0;
12+
13+
public Faults shooterFaults = new Faults(0);
14+
public double shooterVelocity = 0.0;
15+
16+
public boolean shooterTargetVelocityReached = false;
17+
}
18+
19+
public default void updateInputs(ShooterIOInputs inputs) {}
20+
21+
public default void startShooter() {}
22+
23+
public default void setShooterTargetVelocity(double velocity) {}
24+
25+
public default void stopShooter() {}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package frc.robot.subsystems.shooter;
2+
3+
import com.revrobotics.RelativeEncoder;
4+
import com.revrobotics.spark.SparkClosedLoopController;
5+
import com.revrobotics.spark.SparkLowLevel.MotorType;
6+
import com.revrobotics.spark.SparkMax;
7+
import com.revrobotics.spark.config.SparkBaseConfig.IdleMode;
8+
import com.revrobotics.spark.config.SparkMaxConfig;
9+
10+
// import com.ctre.phoenix6.sim.TalonFXSimState.MotorType;
11+
12+
public class ShooterIOSpark implements ShooterIO {
13+
14+
SparkMax shooterMotor = new SparkMax(0, MotorType.kBrushless);
15+
16+
SparkClosedLoopController shooterController;
17+
RelativeEncoder shooterEncoder;
18+
19+
public ShooterIOSpark() {
20+
SparkMaxConfig config = new SparkMaxConfig();
21+
22+
config.idleMode(IdleMode.kCoast).smartCurrentLimit(40, 40).inverted(false);
23+
}
24+
}

0 commit comments

Comments
 (0)