55import static edu .wpi .first .units .Units .Meters ;
66import static edu .wpi .first .units .Units .Radians ;
77import static edu .wpi .first .units .Units .Rotations ;
8+ import static edu .wpi .first .units .Units .Millimeters ;
89
910import org .lasarobotics .fsm .StateMachine ;
1011import org .lasarobotics .fsm .SystemState ;
1314import org .lasarobotics .hardware .generic .LimitSwitch .SwitchPolarity ;
1415
1516import com .ctre .phoenix6 .configs .TalonFXConfiguration ;
17+ import com .ctre .phoenix6 .controls .DutyCycleOut ;
1618import com .ctre .phoenix6 .controls .MotionMagicVoltage ;
1719import com .ctre .phoenix6 .signals .FeedbackSensorSourceValue ;
1820import com .ctre .phoenix6 .signals .GravityTypeValue ;
@@ -38,36 +40,55 @@ public static enum USER_INPUT {
3840 L4
3941 }
4042
41- public static final Angle SCORING_L1_ANGLE = Degrees .of (0 );
42- public static final Angle SCORING_L2_ANGLE = Degrees .of (0 );
43- public static final Angle SCORING_L3_ANGLE = Degrees .of (0 );
44- public static final Angle SCORING_L4_ANGLE = Degrees .of (0 );
43+ static final DutyCycleOut HOMING_SPEED = new DutyCycleOut (-0.05 );
44+ static final Distance HOMING_EPSILON = Millimeters .of (5 );
4545
46- public static final Angle SAFE_REEF_ANGLE_BOTTOM = Degrees .of (0 );
47- public static final Angle SAFE_REEF_ANGLE_TOP = Degrees .of (0 );
48- public static final Angle SAFE_INTAKE_ANGLE = Degrees .of (0 );
46+ static final Angle SCORING_L1_ANGLE = Degrees .of (0 );
47+ static final Angle SCORING_L2_ANGLE = Degrees .of (0 );
48+ static final Angle SCORING_L3_ANGLE = Degrees .of (0 );
49+ static final Angle SCORING_L4_ANGLE = Degrees .of (0 );
4950
50- public static final Angle STOW_ANGLE = Degrees .of (0 );
51- public static final Distance STOW_HEIGHT = Inches .of (0 );
51+ static final Angle SAFE_REEF_ANGLE_BOTTOM = Degrees .of (0 );
52+ static final Angle SAFE_REEF_ANGLE_TOP = Degrees .of (0 );
53+ static final Angle SAFE_INTAKE_ANGLE = Degrees .of (0 );
5254
53- public static final Distance L1_HEIGHT = Inches .of (0 );
54- public static final Distance L2_HEIGHT = Inches .of (0 );
55- public static final Distance CLEAR_HEIGHT = Inches .of (0 );
56- public static final Distance L3_HEIGHT = Inches .of (0 );
57- public static final Distance L4_HEIGHT = Inches .of (0 );
55+ static final Angle STOW_ANGLE = Degrees .of (0 );
56+ static final Distance STOW_HEIGHT = Inches .of (0 );
57+
58+ static final Distance L1_HEIGHT = Inches .of (0 );
59+ static final Distance L2_HEIGHT = Inches .of (0 );
60+ static final Distance CLEAR_HEIGHT = Inches .of (0 );
61+ static final Distance L3_HEIGHT = Inches .of (0 );
62+ static final Distance L4_HEIGHT = Inches .of (0 );
5863
5964 /* TODO: Actually get user input */
6065 private static USER_INPUT getUserInput () { return USER_INPUT .STOW ; }
6166
6267 public enum LiftStates implements SystemState {
6368 IDLE {
69+ @ Override
70+ public LiftStates nextState () {
71+ return this ;
72+ }
73+ },
74+ HOME {
6475 @ Override
6576 public void initialize () {
77+ s_liftinstance .startHomingElevator ();
78+ }
6679
80+ @ Override
81+ public void execute () {
82+ if (s_liftinstance .elevatorAtHome ()) {
83+ s_liftinstance .resetElevatorEncoder ();
84+ s_liftinstance .stopElevator ();
85+ }
6786 }
6887
6988 @ Override
7089 public LiftStates nextState () {
90+ if (s_liftinstance .elevatorAtHome () && s_liftinstance .getElevatorHeight ().isNear (Meters .zero (), HOMING_EPSILON ))
91+ return IDLE ;
7192 return this ;
7293 }
7394 },
@@ -607,7 +628,7 @@ public static Hardware initializeHardware() {
607628 Hardware liftHardware = new Hardware (
608629 new TalonFX (Constants .LiftHardware .ELEVATOR_MOTOR_ID , Constants .LiftHardware .TALON_UPDATE_RATE ),
609630 new TalonFX (Constants .LiftHardware .PIVOT_MOTOR_ID , Constants .LiftHardware .TALON_UPDATE_RATE ),
610- new LimitSwitch (Constants .LiftHardware .ELEVATOR_HOMING_BEAM_BREAK_PORT , SwitchPolarity .NORMALLY_CLOSED )
631+ new LimitSwitch (Constants .LiftHardware .ELEVATOR_HOMING_BEAM_BREAK_PORT , SwitchPolarity .NORMALLY_OPEN )
611632 );
612633
613634 return liftHardware ;
@@ -650,11 +671,25 @@ private Distance getElevatorHeight() {
650671 return height ;
651672 }
652673
674+ /**
675+ * Slowly run the elevator motor
676+ */
677+ private void startHomingElevator () {
678+ m_elevatorMotor .setControl (HOMING_SPEED );
679+ }
680+
653681 /**
654682 * Zero the elevator encoder
655683 */
656- private void homeElevator () {
657- m_elevatorMotor .setPosition (Degrees .of (0 ));
684+ private void resetElevatorEncoder () {
685+ m_elevatorMotor .setPosition (Degrees .of (0.0 ));
686+ }
687+
688+ /**
689+ * Stop the elevator motor
690+ */
691+ private void stopElevator () {
692+ m_elevatorMotor .stopMotor ();
658693 }
659694
660695 /**
0 commit comments