11package org .curtinfrc .frc2025 .subsystems .elevator ;
22
3- import static org .curtinfrc .frc2025 .subsystems .elevator .ElevatorConstants .*;
4-
53import edu .wpi .first .math .MathUtil ;
64import edu .wpi .first .math .controller .PIDController ;
75import edu .wpi .first .math .geometry .Pose3d ;
86import edu .wpi .first .math .geometry .Rotation3d ;
7+ import edu .wpi .first .util .struct .Struct ;
8+ import edu .wpi .first .util .struct .StructGenerator ;
9+ import edu .wpi .first .util .struct .StructSerializable ;
910import edu .wpi .first .wpilibj2 .command .Command ;
1011import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
1112import edu .wpi .first .wpilibj2 .command .button .Trigger ;
1213import java .util .function .BooleanSupplier ;
1314import java .util .function .Supplier ;
14- import org .curtinfrc .frc2025 .subsystems .elevator .ElevatorConstants .ElevatorSetpoints ;
1515import org .littletonrobotics .junction .AutoLogOutput ;
1616import org .littletonrobotics .junction .Logger ;
1717
1818public class Elevator extends SubsystemBase {
19- private static final double TOLERANCE = 0.01 ;
19+ private static final double TOLERANCE = 0.005 ;
20+ public static double CLIMB_KP = 45 ;
21+ public static double CLIMB_KD = 0 ;
22+
23+ public static enum ElevatorSetpoints implements StructSerializable {
24+ L1 (0 ),
25+ L2 (0.221 ),
26+ AlgaePopLow (0 ),
27+ L3 (0.611 ),
28+ AlgaePopHigh (0.38 ),
29+ BASE (0.01 ),
30+ climbPrep (0.3 ),
31+ climbAttempt (0.5 ),
32+ climbed (0.01 );
33+
34+ public final double setpointMetres ;
35+
36+ ElevatorSetpoints (double setpointMetres ) {
37+ this .setpointMetres = setpointMetres ;
38+ }
39+
40+ public static ElevatorSetpoints getPopPoint (ElevatorSetpoints point ) {
41+ switch (point ) {
42+ case L2 :
43+ return AlgaePopLow ;
44+ case L3 :
45+ return AlgaePopHigh ;
46+ default :
47+ return BASE ;
48+ }
49+ }
50+
51+ public static final Struct <ElevatorSetpoints > struct =
52+ StructGenerator .genEnum (ElevatorSetpoints .class );
53+ }
2054
2155 private final ElevatorIO io ;
2256 private final ElevatorIOInputsAutoLogged inputs = new ElevatorIOInputsAutoLogged ();
23- private final PIDController climbPID = new PIDController (climbkP , climbkI , climbkD );
57+ private final PIDController climbPID = new PIDController (CLIMB_KP , 0 , CLIMB_KD );
2458 private ElevatorSetpoints setpoint = ElevatorSetpoints .BASE ;
2559
2660 public final Trigger isNotAtCollect = new Trigger (() -> setpoint != ElevatorSetpoints .BASE );
@@ -29,12 +63,12 @@ public class Elevator extends SubsystemBase {
2963
3064 public Elevator (ElevatorIO io ) {
3165 this .io = io ;
32- climbPID .setTolerance (tolerance );
66+ climbPID .setTolerance (TOLERANCE );
3367
3468 atSetpoint =
3569 new Trigger (
3670 () -> {
37- var error = Math .abs (inputs .positionMetres - setpoint .setpoint );
71+ var error = Math .abs (inputs .positionMetres - setpoint .setpointMetres );
3872 var velocity = Math .abs (inputs .velocityMetresPerSecond );
3973 return error < TOLERANCE && velocity < 0.1 ;
4074 })
@@ -62,7 +96,7 @@ public Command goToSetpoint(Supplier<ElevatorSetpoints> point, BooleanSupplier s
6296 return run (() -> {
6397 setpoint = point .get ();
6498 if (safe .getAsBoolean ()) {
65- goToTarget (point .get ().setpoint );
99+ goToTarget (point .get ().setpointMetres );
66100 }
67101 })
68102 .withName ("GoToDynamicSetpoint" );
@@ -72,7 +106,7 @@ public Command goToSetpoint(ElevatorSetpoints point, BooleanSupplier safe) {
72106 return run (() -> {
73107 setpoint = point ;
74108 if (safe .getAsBoolean ()) {
75- goToTarget (point .setpoint );
109+ goToTarget (point .setpointMetres );
76110 }
77111 })
78112 .withName ("GoToStaticSetpoint" );
@@ -82,7 +116,7 @@ public Command goToClimberSetpoint(ElevatorSetpoints point, BooleanSupplier safe
82116 return run (
83117 () -> {
84118 if (safe .getAsBoolean ()) {
85- var out = climbPID .calculate (inputs .positionMetres , point .setpoint );
119+ var out = climbPID .calculate (inputs .positionMetres , point .setpointMetres );
86120 io .setVoltage (MathUtil .clamp (out , -4 , 4 ));
87121 }
88122 });
0 commit comments