Skip to content

Commit b2daa96

Browse files
committed
Homing
1 parent 9995d6c commit b2daa96

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

src/main/java/frc/robot/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public static class Drive {
3232
}
3333

3434
public static class LiftHardware {
35+
public static final Frequency TALON_UPDATE_RATE = Hertz.of(50);
3536
public static final TalonFX.ID ELEVATOR_MOTOR_ID = new TalonFX.ID("LiftHardware/Elevator", PhoenixCANBus.CANIVORE, 4);
3637
public static final TalonFX.ID PIVOT_MOTOR_ID = new TalonFX.ID("LiftHardware/Pivot", PhoenixCANBus.CANIVORE, 5);
37-
public static final Frequency TALON_UPDATE_RATE = Hertz.of(50);
3838
public static final Distance SPROCKET_PITCH_RADIUS = Inches.of((1.751)/(2.0));
3939
public static final LimitSwitch.ID ELEVATOR_HOMING_BEAM_BREAK_PORT = new LimitSwitch.ID("LiftHardware/HomingSwitch", 0);
4040
}

src/main/java/frc/robot/subsystems/lift/LiftSubsystem.java

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static edu.wpi.first.units.Units.Meters;
66
import static edu.wpi.first.units.Units.Radians;
77
import static edu.wpi.first.units.Units.Rotations;
8+
import static edu.wpi.first.units.Units.Millimeters;
89

910
import org.lasarobotics.fsm.StateMachine;
1011
import org.lasarobotics.fsm.SystemState;
@@ -13,6 +14,7 @@
1314
import org.lasarobotics.hardware.generic.LimitSwitch.SwitchPolarity;
1415

1516
import com.ctre.phoenix6.configs.TalonFXConfiguration;
17+
import com.ctre.phoenix6.controls.DutyCycleOut;
1618
import com.ctre.phoenix6.controls.MotionMagicVoltage;
1719
import com.ctre.phoenix6.signals.FeedbackSensorSourceValue;
1820
import 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

Comments
 (0)