66import edu .wpi .first .math .controller .PIDController ;
77import edu .wpi .first .math .geometry .Pose3d ;
88import edu .wpi .first .math .geometry .Rotation3d ;
9+ import edu .wpi .first .util .struct .Struct ;
10+ import edu .wpi .first .util .struct .StructGenerator ;
11+ import edu .wpi .first .util .struct .StructSerializable ;
912import edu .wpi .first .wpilibj2 .command .Command ;
1013import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
1114import edu .wpi .first .wpilibj2 .command .button .Trigger ;
1215import java .util .function .BooleanSupplier ;
1316import java .util .function .Supplier ;
14- import org .curtinfrc .frc2025 .subsystems .elevator .ElevatorConstants .ElevatorSetpoints ;
1517import org .littletonrobotics .junction .AutoLogOutput ;
1618import org .littletonrobotics .junction .Logger ;
1719
1820public class Elevator extends SubsystemBase {
1921 private static final double TOLERANCE = 0.01 ;
22+ public static double CLIMB_KP = 45 ;
23+ public static double CLIMB_KD = 0 ;
24+
25+ public static enum ElevatorSetpoints implements StructSerializable {
26+ L1 (0 ),
27+ L2 (0.221 ),
28+ AlgaePopLow (0 ),
29+ L3 (0.611 ),
30+ AlgaePopHigh (0.38 ),
31+ BASE (0.01 ),
32+ climbPrep (0.3 ),
33+ climbAttempt (0.5 ),
34+ climbed (0.01 );
35+
36+ public final double setpointMetres ;
37+
38+ ElevatorSetpoints (double setpointMetres ) {
39+ this .setpointMetres = setpointMetres ;
40+ }
41+
42+ public static ElevatorSetpoints getPopPoint (ElevatorSetpoints point ) {
43+ switch (point ) {
44+ case L2 :
45+ return AlgaePopLow ;
46+ case L3 :
47+ return AlgaePopHigh ;
48+ default :
49+ return BASE ;
50+ }
51+ }
52+
53+ public static final Struct <ElevatorSetpoints > struct =
54+ StructGenerator .genEnum (ElevatorSetpoints .class );
55+ }
2056
2157 private final ElevatorIO io ;
2258 private final ElevatorIOInputsAutoLogged inputs = new ElevatorIOInputsAutoLogged ();
23- private final PIDController climbPID = new PIDController (climbkP , climbkI , climbkD );
59+ private final PIDController climbPID = new PIDController (CLIMB_KP , 0 , CLIMB_KD );
2460 private ElevatorSetpoints setpoint = ElevatorSetpoints .BASE ;
2561
2662 public final Trigger isNotAtCollect = new Trigger (() -> setpoint != ElevatorSetpoints .BASE );
@@ -29,12 +65,12 @@ public class Elevator extends SubsystemBase {
2965
3066 public Elevator (ElevatorIO io ) {
3167 this .io = io ;
32- climbPID .setTolerance (tolerance );
68+ climbPID .setTolerance (TOLERANCE );
3369
3470 atSetpoint =
3571 new Trigger (
3672 () -> {
37- var error = Math .abs (inputs .positionMetres - setpoint .setpoint );
73+ var error = Math .abs (inputs .positionMetres - setpoint .setpointMetres );
3874 var velocity = Math .abs (inputs .velocityMetresPerSecond );
3975 return error < TOLERANCE && velocity < 0.1 ;
4076 })
@@ -62,7 +98,7 @@ public Command goToSetpoint(Supplier<ElevatorSetpoints> point, BooleanSupplier s
6298 return run (() -> {
6399 setpoint = point .get ();
64100 if (safe .getAsBoolean ()) {
65- goToTarget (point .get ().setpoint );
101+ goToTarget (point .get ().setpointMetres );
66102 }
67103 })
68104 .withName ("GoToDynamicSetpoint" );
@@ -72,7 +108,7 @@ public Command goToSetpoint(ElevatorSetpoints point, BooleanSupplier safe) {
72108 return run (() -> {
73109 setpoint = point ;
74110 if (safe .getAsBoolean ()) {
75- goToTarget (point .setpoint );
111+ goToTarget (point .setpointMetres );
76112 }
77113 })
78114 .withName ("GoToStaticSetpoint" );
@@ -82,7 +118,7 @@ public Command goToClimberSetpoint(ElevatorSetpoints point, BooleanSupplier safe
82118 return run (
83119 () -> {
84120 if (safe .getAsBoolean ()) {
85- var out = climbPID .calculate (inputs .positionMetres , point .setpoint );
121+ var out = climbPID .calculate (inputs .positionMetres , point .setpointMetres );
86122 io .setVoltage (MathUtil .clamp (out , -4 , 4 ));
87123 }
88124 });
0 commit comments