Skip to content

Commit 0009ab4

Browse files
committed
Soft limits & Homing Command
1 parent 6f947c8 commit 0009ab4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/frc/robot/subsystems/intake/IntakeConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package frc.robot.subsystems.intake;
22

33
import com.ctre.phoenix6.configs.Slot0Configs;
4+
import com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs;
45

56
public class IntakeConstants {
67

@@ -29,6 +30,8 @@ public static Slot0Configs createRollerMotorSlot0Configs() {
2930

3031
// Extension Motor
3132
public static final double ALLOWABLE_EXTENSION_ERROR = 0.1;
33+
public static final double INTAKE_FORWARD_LIMIT = 100;
34+
public static final double INTAKE_REVERSE_LIMIT = 0;
3235
public static final double EXTENSION_KS = 0;
3336
public static final double EXTENSION_KP = 0;
3437
public static final double EXTENSION_KD = 0;
@@ -40,4 +43,16 @@ public static Slot0Configs createExtensionMotorSlot0Configs() {
4043
slot.kD = EXTENSION_KD;
4144
return slot;
4245
}
46+
47+
public static SoftwareLimitSwitchConfigs createExtensionSoftwareLimitSwitchConfigs() {
48+
SoftwareLimitSwitchConfigs configs = new SoftwareLimitSwitchConfigs();
49+
configs.ForwardSoftLimitEnable = false;
50+
configs.ReverseSoftLimitEnable = false;
51+
configs.ForwardSoftLimitThreshold = INTAKE_FORWARD_LIMIT;
52+
configs.ReverseSoftLimitThreshold = INTAKE_REVERSE_LIMIT;
53+
return configs;
54+
}
55+
56+
public static final double SAFE_HOMING_EFFORT = -0.2;
57+
public static final double SAFE_STATOR_LIMIT = 0.8;
4358
}

src/main/java/frc/robot/subsystems/intake/IntakeSubsystem.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ public IntakeSubsystem() {
3131
rollerControl = new VelocityVoltage(0);
3232

3333
extensionMotor.getConfigurator().apply(IntakeConstants.createExtensionMotorSlot0Configs());
34+
extensionMotor
35+
.getConfigurator()
36+
.apply(IntakeConstants.createExtensionSoftwareLimitSwitchConfigs());
3437
extensionMotor.setPosition(0);
3538
extensionTarget = Rotations.of(0);
3639
extensionControl = new PositionTorqueCurrentFOC(0);
40+
41+
homeIntake();
3742
}
3843

3944
@Override
@@ -77,4 +82,23 @@ public Command stowCommand() {
7782
.andThen(setIntakeExtensionCommand(Rotations.of(0)))
7883
.withName("Stow Intake");
7984
}
85+
86+
private void homeIntake() {
87+
while (extensionMotor.getStatorCurrent().getValueAsDouble()
88+
> IntakeConstants.SAFE_STATOR_LIMIT) {
89+
extensionMotor.set(IntakeConstants.SAFE_HOMING_EFFORT);
90+
}
91+
extensionMotor.setPosition(0);
92+
}
93+
94+
public Command homeIntakeCommand() {
95+
return runEnd(
96+
() -> extensionMotor.set(IntakeConstants.SAFE_HOMING_EFFORT),
97+
() -> extensionMotor.setPosition(0))
98+
.until(
99+
() -> {
100+
return extensionMotor.getStatorCurrent().getValueAsDouble()
101+
> IntakeConstants.SAFE_STATOR_LIMIT;
102+
});
103+
}
80104
}

0 commit comments

Comments
 (0)