Skip to content

Commit 885e048

Browse files
committed
Add clamping to hood and turret in place of state control
1 parent 2c03062 commit 885e048

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

src/main/java/com/spartronics4915/frc2026/subsystems/mechanisms/ClimberSubsystem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public ClimberSubsystem() {
4545
motorConfig.apply(motorOutputConfigs);
4646

4747
setMechanismPosition(0);
48-
4948
ModeSwitchHandler.EnableModeSwitchHandler(this);
5049
}
5150

src/main/java/com/spartronics4915/frc2026/subsystems/mechanisms/head/HoodSubsystem.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.ctre.phoenix6.controls.PositionVoltage;
88
import com.ctre.phoenix6.hardware.TalonFX;
99
import com.ctre.phoenix6.signals.InvertedValue;
10+
import com.spartronics4915.frc2026.subsystems.mechanisms.head.TurretSubsystem.TurretClamp;
1011
import com.spartronics4915.frc2026.util.ModeSwitchHandler;
1112
import com.spartronics4915.frc2026.util.ModeSwitchHandler.ModeSwitchInterface;
1213

@@ -28,13 +29,17 @@ public class HoodSubsystem extends SubsystemBase implements ModeSwitchInterface
2829

2930
TalonFX motor = new TalonFX(MOTOR_ID);
3031

31-
TrapezoidProfile trapProfile = new TrapezoidProfile(
32+
TrapezoidProfile trapezoidProfile = new TrapezoidProfile(
3233
new Constraints(MAX_VELOCITY, MAX_ACCELERATION)
3334
);
3435

3536
private Rotation2d currentSetpoint = Rotation2d.fromDegrees(0);
3637
private State currentState = new State();
3738

39+
private HoodClamp currentClamp;
40+
private Rotation2d minAngle;
41+
private Rotation2d maxAngle;
42+
3843
private final DoublePublisher appliedOutPublisher = NetworkTableInstance.getDefault().getTable("hood").getDoubleTopic("applied out").publish();
3944
private final StructPublisher<Rotation2d> positionPublisher = NetworkTableInstance.getDefault().getTable("hood").getStructTopic("position", Rotation2d.struct).publish();
4045
private final StructPublisher<Rotation2d> desiredStatePublisher = NetworkTableInstance.getDefault().getTable("hood").getStructTopic("desiredState", Rotation2d.struct).publish();
@@ -50,13 +55,12 @@ public HoodSubsystem() {
5055
motorOutputConfigs.Inverted = InvertedValue.Clockwise_Positive;
5156
motorConfig.apply(motorOutputConfigs);
5257

53-
setMechanismAngle(Rotation2d.fromDegrees(0));
58+
currentClamp = HoodClamp.RESTRICTED;
59+
minAngle = currentClamp.minAngle;
60+
maxAngle = currentClamp.maxAngle;
5461

62+
setMechanismAngle(Rotation2d.fromDegrees(0));
5563
ModeSwitchHandler.EnableModeSwitchHandler(this);
56-
57-
SmartDashboard.putData("Hood Up", setStateCommand(HoodState.UP));
58-
SmartDashboard.putData("Hood Middle", setStateCommand(HoodState.MIDDLE));
59-
SmartDashboard.putData("Hood Down", setStateCommand(HoodState.DOWN));
6064
}
6165

6266
//#region Main Functionality
@@ -66,12 +70,12 @@ public void periodic(){
6670
currentSetpoint = Rotation2d.fromRotations(
6771
MathUtil.clamp(
6872
currentSetpoint.getRotations(),
69-
MIN_ANGLE.getRotations(),
70-
MAX_ANGLE.getRotations()
73+
minAngle.getRotations(),
74+
maxAngle.getRotations()
7175
)
7276
);
7377

74-
currentState = trapProfile.calculate(
78+
currentState = trapezoidProfile.calculate(
7579
DELTA_TIME,
7680
currentState,
7781
new State(currentSetpoint.getRotations(), 0.0)
@@ -95,8 +99,10 @@ public void setSetpoint(Rotation2d setpoint){
9599
currentSetpoint = setpoint;
96100
}
97101

98-
public void setState(HoodState state){
99-
currentSetpoint = state.angle;
102+
public void setClamp(HoodClamp clamp){
103+
currentClamp = clamp;
104+
minAngle = currentClamp.minAngle;
105+
maxAngle = currentClamp.maxAngle;
100106
}
101107

102108
private void setMechanismAngle(Rotation2d angle){
@@ -120,20 +126,17 @@ public void resetMechanism(Rotation2d angle){
120126
public Command setSetpointCommand(Rotation2d newSetpoint){
121127
return this.runOnce(() -> setSetpoint(newSetpoint));
122128
}
123-
124-
public Command setStateCommand(HoodState state){
125-
return setSetpointCommand(state.angle);
126-
}
127129

128-
public enum HoodState {
129-
DOWN(Rotation2d.fromDegrees(0)),
130-
UP(Rotation2d.fromDegrees(30)),
131-
MIDDLE(Rotation2d.fromDegrees(15));
130+
public enum HoodClamp {
131+
RESTRICTED(Rotation2d.fromDegrees(0), Rotation2d.fromDegrees(0)),
132+
UNRESTRICTED(Rotation2d.fromDegrees(0), Rotation2d.fromDegrees(0));
132133

133-
Rotation2d angle;
134+
Rotation2d minAngle;
135+
Rotation2d maxAngle;
134136

135-
private HoodState(Rotation2d angle) {
136-
this.angle = angle;
137+
private HoodClamp(Rotation2d minAngle, Rotation2d maxAngle) {
138+
this.minAngle = minAngle;
139+
this.maxAngle = maxAngle;
137140
}
138141
}
139142

src/main/java/com/spartronics4915/frc2026/subsystems/mechanisms/head/TurretSubsystem.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class TurretSubsystem extends SubsystemBase implements ModeSwitchInterfac
3333
private Rotation2d currentSetpoint = Rotation2d.fromDegrees(0);
3434
private State currentState = new State();
3535

36-
private TurretState currentTurretState;
36+
private TurretClamp currentClamp;
3737
private Rotation2d minAngle;
3838
private Rotation2d maxAngle;
3939

@@ -48,9 +48,9 @@ public TurretSubsystem(){
4848
configurator.apply(CURRENT_LIMITS_CONFIG);
4949
configurator.apply(FEEDBACK_CONFIG);
5050

51-
currentTurretState = TurretState.RESTRICTED;
52-
minAngle = currentTurretState.minAngle;
53-
maxAngle = currentTurretState.maxAngle;
51+
currentClamp = TurretClamp.RESTRICTED;
52+
minAngle = currentClamp.minAngle;
53+
maxAngle = currentClamp.maxAngle;
5454

5555
setMechanismAngle(Rotation2d.fromDegrees(0));
5656
ModeSwitchHandler.EnableModeSwitchHandler(this);
@@ -92,10 +92,10 @@ public void setSetpoint(Rotation2d setpoint){
9292
currentSetpoint = setpoint;
9393
}
9494

95-
public void setTurretState(TurretState state){
96-
currentTurretState = state;
97-
minAngle = currentTurretState.minAngle;
98-
maxAngle = currentTurretState.maxAngle;
95+
public void setClamp(TurretClamp clamp){
96+
currentClamp = clamp;
97+
minAngle = currentClamp.minAngle;
98+
maxAngle = currentClamp.maxAngle;
9999
}
100100

101101
private void setMechanismAngle(Rotation2d angle){
@@ -122,14 +122,14 @@ public Command setSetpointCommand(Rotation2d newSetpoint){
122122

123123
//#endregion
124124

125-
public enum TurretState {
125+
public enum TurretClamp {
126126
RESTRICTED(Rotation2d.fromDegrees(0), Rotation2d.fromDegrees(0)),
127127
UNRESTRICTED(Rotation2d.fromDegrees(0), Rotation2d.fromDegrees(0));
128128

129129
Rotation2d minAngle;
130130
Rotation2d maxAngle;
131131

132-
private TurretState(Rotation2d minAngle, Rotation2d maxAngle) {
132+
private TurretClamp(Rotation2d minAngle, Rotation2d maxAngle) {
133133
this.minAngle = minAngle;
134134
this.maxAngle = maxAngle;
135135
}

src/main/java/com/spartronics4915/frc2026/subsystems/mechanisms/pipeline/ShooterSubsystem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public ShooterSubsystem() {
5555
followerMotor.setControl(new Follower(FOLLOWER_MOTOR_ID, MotorAlignmentValue.Aligned));
5656

5757
leadMotor.set(0);
58-
5958
ModeSwitchHandler.EnableModeSwitchHandler(this);
6059

6160
SmartDashboard.putData("Shooter On", setStateCommand(ShooterState.ON));

0 commit comments

Comments
 (0)