77import com .ctre .phoenix6 .controls .PositionVoltage ;
88import com .ctre .phoenix6 .hardware .TalonFX ;
99import com .ctre .phoenix6 .signals .InvertedValue ;
10+ import com .spartronics4915 .frc2026 .subsystems .mechanisms .head .TurretSubsystem .TurretClamp ;
1011import com .spartronics4915 .frc2026 .util .ModeSwitchHandler ;
1112import 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
0 commit comments