Skip to content

Commit 9adebfa

Browse files
Hopper and Spindexer Subsystems
1 parent 2c0a2ee commit 9adebfa

8 files changed

Lines changed: 194 additions & 3 deletions

File tree

.idea/compiler.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
package frc.robot.config;
22

3-
public class CANMappings {}
3+
public class CANMappings {
4+
public static final int SPINDEXER_MOTOR_ID = 0;
5+
6+
public static final int LEFT_HOPPER_MOTOR_ID = 0;
7+
public static final int RIGHT_HOPPER_MOTOR_ID = 0;
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package frc.robot.config;
2+
3+
public class HopperConfig {
4+
public static final double LEFT_HOPPER_SUPPLY_CURRENT_LIMIT = 70;
5+
public static final double LEFT_HOPPER_STATOR_CURRENT_LIMIT = 80;
6+
public static final double LEFT_HOPPER_GEAR_RATIO = 0;
7+
public static final double RIGHT_HOPPER_SUPPLY_CURRENT_LIMIT = 70;
8+
public static final double RIGHT_HOPPER_STATOR_CURRENT_LIMIT = 80;
9+
public static final double RIGHT_HOPPER_GEAR_RATIO = 0;
10+
11+
public static final double LEFT_HOPPER_MAX_CRUISE_VELOCITY = 3000;
12+
public static final double LEFT_HOPPER_TARGET_ACCELERATION = 500;
13+
public static final double LEFT_HOPPER_P = 0;
14+
public static final double LEFT_HOPPER_I = 0;
15+
public static final double LEFT_HOPPER_D = 0;
16+
17+
public static final double RIGHT_HOPPER_MAX_CRUISE_VELOCITY = 3000;
18+
public static final double RIGHT_HOPPER_TARGET_ACCELERATION = 500;
19+
public static final double RIGHT_HOPPER_P = 0;
20+
public static final double RIGHT_HOPPER_I = 0;
21+
public static final double RIGHT_HOPPER_D = 0;
22+
23+
public static final double HOPPER_TOLERANCE = 0.005;
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package frc.robot.config;
2+
3+
public class SpindexerConfig {
4+
public static final double SPINDEXER_SUPPLY_CURRENT_LIMIT = 70;
5+
public static final double SPINDEXER_STATOR_CURRENT_LIMIT = 80;
6+
public static final double SPINDEXER_GEAR_RATIO = 0;
7+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package frc.robot.subsystems;
2+
3+
import com.ctre.phoenix6.configs.TalonFXConfiguration;
4+
import com.ctre.phoenix6.controls.DutyCycleOut;
5+
import com.ctre.phoenix6.controls.MotionMagicVoltage;
6+
import com.ctre.phoenix6.hardware.TalonFX;
7+
import com.ctre.phoenix6.signals.NeutralModeValue;
8+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
9+
import frc.robot.config.CANMappings;
10+
import frc.robot.config.HopperConfig;
11+
12+
public class Hopper extends SubsystemBase {
13+
private TalonFX leftHopper;
14+
private TalonFX rightHopper;
15+
16+
public Hopper() {
17+
18+
leftHopper = new TalonFX(CANMappings.LEFT_HOPPER_MOTOR_ID);
19+
rightHopper = new TalonFX(CANMappings.RIGHT_HOPPER_MOTOR_ID);
20+
21+
TalonFXConfiguration leftHopperConfig = new TalonFXConfiguration();
22+
TalonFXConfiguration rightHopperConfig = new TalonFXConfiguration();
23+
24+
leftHopperConfig.CurrentLimits.SupplyCurrentLimitEnable = true;
25+
leftHopperConfig.CurrentLimits.StatorCurrentLimitEnable = true;
26+
leftHopperConfig.CurrentLimits.StatorCurrentLimit =
27+
HopperConfig.LEFT_HOPPER_STATOR_CURRENT_LIMIT;
28+
leftHopperConfig.CurrentLimits.SupplyCurrentLimit =
29+
HopperConfig.LEFT_HOPPER_SUPPLY_CURRENT_LIMIT;
30+
;
31+
32+
rightHopperConfig.CurrentLimits.SupplyCurrentLimitEnable = true;
33+
rightHopperConfig.CurrentLimits.StatorCurrentLimitEnable = true;
34+
rightHopperConfig.CurrentLimits.StatorCurrentLimit =
35+
HopperConfig.RIGHT_HOPPER_STATOR_CURRENT_LIMIT;
36+
;
37+
rightHopperConfig.CurrentLimits.SupplyCurrentLimit =
38+
HopperConfig.RIGHT_HOPPER_SUPPLY_CURRENT_LIMIT;
39+
;
40+
41+
leftHopperConfig.MotionMagic.MotionMagicCruiseVelocity =
42+
HopperConfig.LEFT_HOPPER_MAX_CRUISE_VELOCITY;
43+
rightHopperConfig.MotionMagic.MotionMagicCruiseVelocity =
44+
HopperConfig.RIGHT_HOPPER_MAX_CRUISE_VELOCITY;
45+
leftHopperConfig.MotionMagic.MotionMagicAcceleration =
46+
HopperConfig.LEFT_HOPPER_TARGET_ACCELERATION;
47+
rightHopperConfig.MotionMagic.MotionMagicAcceleration =
48+
HopperConfig.RIGHT_HOPPER_TARGET_ACCELERATION;
49+
50+
leftHopperConfig.Slot0.kP = HopperConfig.LEFT_HOPPER_P;
51+
leftHopperConfig.Slot0.kI = HopperConfig.LEFT_HOPPER_I;
52+
leftHopperConfig.Slot0.kD = HopperConfig.LEFT_HOPPER_D;
53+
54+
rightHopperConfig.Slot0.kP = HopperConfig.RIGHT_HOPPER_P;
55+
rightHopperConfig.Slot0.kI = HopperConfig.RIGHT_HOPPER_I;
56+
rightHopperConfig.Slot0.kD = HopperConfig.RIGHT_HOPPER_D;
57+
58+
leftHopperConfig.Feedback.SensorToMechanismRatio =
59+
HopperConfig.LEFT_HOPPER_GEAR_RATIO; // gear ratio
60+
rightHopperConfig.Feedback.SensorToMechanismRatio = HopperConfig.RIGHT_HOPPER_GEAR_RATIO;
61+
62+
leftHopperConfig.MotorOutput.NeutralMode = NeutralModeValue.Coast;
63+
rightHopperConfig.MotorOutput.NeutralMode = NeutralModeValue.Coast;
64+
65+
leftHopper.getConfigurator().apply(leftHopperConfig);
66+
rightHopper.getConfigurator().apply(rightHopperConfig);
67+
68+
// follower = new Follower(CANMappings.K_Hopper_LEFT_ID, false);
69+
}
70+
71+
public void extend(double rotation) {
72+
leftHopper.setControl(new MotionMagicVoltage(rotation));
73+
rightHopper.setControl(new MotionMagicVoltage(rotation));
74+
}
75+
76+
public void retract(double rotation) {
77+
leftHopper.setControl(new MotionMagicVoltage(rotation));
78+
rightHopper.setControl(new MotionMagicVoltage(rotation));
79+
}
80+
81+
public void directionalExtend(double speed) {
82+
leftHopper.setControl(new DutyCycleOut(speed));
83+
rightHopper.setControl(new DutyCycleOut(speed));
84+
}
85+
86+
public void directionalRetract(double speed) {
87+
leftHopper.setControl(new DutyCycleOut(speed));
88+
rightHopper.setControl(new DutyCycleOut(speed));
89+
}
90+
91+
public void stop() {
92+
leftHopper.stopMotor();
93+
rightHopper.stopMotor();
94+
}
95+
96+
public void zero() {
97+
leftHopper.setPosition(0.0);
98+
rightHopper.setPosition(0.0);
99+
}
100+
101+
public boolean atPosition() {
102+
return (Math.abs(leftHopper.getClosedLoopError().getValueAsDouble())
103+
<= HopperConfig.HOPPER_TOLERANCE)
104+
&& (Math.abs(rightHopper.getClosedLoopError().getValueAsDouble())
105+
<= HopperConfig.HOPPER_TOLERANCE);
106+
}
107+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package frc.robot.subsystems;
2+
3+
import com.ctre.phoenix6.configs.TalonFXConfiguration;
4+
import com.ctre.phoenix6.controls.DutyCycleOut;
5+
import com.ctre.phoenix6.hardware.TalonFX;
6+
import com.ctre.phoenix6.signals.NeutralModeValue;
7+
import edu.wpi.first.wpilibj2.command.SubsystemBase;
8+
import frc.robot.config.CANMappings;
9+
import frc.robot.config.SpindexerConfig;
10+
11+
public class Spindexer extends SubsystemBase {
12+
protected TalonFX spindexerMotor;
13+
14+
public Spindexer() {
15+
spindexerMotor = new TalonFX(CANMappings.SPINDEXER_MOTOR_ID);
16+
TalonFXConfiguration spindexerMotorConfig = new TalonFXConfiguration();
17+
18+
spindexerMotorConfig.CurrentLimits.SupplyCurrentLimitEnable = true;
19+
spindexerMotorConfig.CurrentLimits.StatorCurrentLimitEnable = true;
20+
21+
spindexerMotorConfig.CurrentLimits.SupplyCurrentLimit =
22+
SpindexerConfig.SPINDEXER_SUPPLY_CURRENT_LIMIT;
23+
spindexerMotorConfig.CurrentLimits.StatorCurrentLimit =
24+
SpindexerConfig.SPINDEXER_STATOR_CURRENT_LIMIT;
25+
26+
spindexerMotorConfig.Feedback.SensorToMechanismRatio = SpindexerConfig.SPINDEXER_GEAR_RATIO;
27+
spindexerMotorConfig.MotorOutput.NeutralMode = NeutralModeValue.Coast;
28+
29+
spindexerMotor.getConfigurator().apply(spindexerMotorConfig);
30+
}
31+
32+
public void index(double velocity) {
33+
spindexerMotor.setControl(new DutyCycleOut(velocity));
34+
}
35+
36+
public void stop() {
37+
spindexerMotor.stopMotor();
38+
}
39+
}

0 commit comments

Comments
 (0)