Skip to content

Commit fa2fea5

Browse files
committed
what autoscoring would look like with the limit switch CTRE "hack" and a fictitious canrange
1 parent e283edc commit fa2fea5

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/main/java/frc/robot/subsystems/drive/DriveSubsystem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import frc.robot.generated.TunerConstants;
2323
import frc.robot.subsystems.vision.VisionFieldPoseEstimate;
2424
import frc.robot.util.RobotTime;
25-
2625
import frc.robot.util.simulations.MapleSimSwerveDrivetrain;
2726
import java.util.function.Supplier;
2827
import org.littletonrobotics.junction.AutoLogOutput;

src/main/java/frc/robot/subsystems/end_effector/Claw.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.wpi.first.wpilibj2.command.Command;
44
import edu.wpi.first.wpilibj2.command.Commands;
5+
import edu.wpi.first.wpilibj2.command.InstantCommand;
56
import edu.wpi.first.wpilibj2.command.SubsystemBase;
67
import edu.wpi.first.wpilibj2.command.button.Trigger;
78
import frc.robot.Constants.EndEffectorConstants;
@@ -39,6 +40,7 @@ public class Claw extends SubsystemBase {
3940
private ClawState currentState = ClawState.NONE;
4041
private boolean firstSensorTriggered;
4142
private boolean secondSensorTriggered;
43+
private boolean autoScoring = false;
4244

4345
public Claw(ClawIO io) {
4446
this.io = io;
@@ -83,6 +85,13 @@ public boolean isClawScoring() {
8385
|| currentState == ClawState.SCORING_ALGAE;
8486
}
8587

88+
public Command autoScoreWhenPoleSensed() {
89+
return new InstantCommand(() -> io.setRollerPosition(0), this)
90+
.alongWith(new InstantCommand(() -> io.setRollerTargetPosition(0)))
91+
.until(
92+
() -> CoralStateTracker.getCurrentPosition() == CoralStateTracker.CoralPosition.NONE);
93+
}
94+
8695
public boolean isCoralInClaw() {
8796
// Use CoralStateTracker instead of individual sensor readings
8897
CoralStateTracker.CoralPosition position = CoralStateTracker.getCurrentPosition();

src/main/java/frc/robot/subsystems/end_effector/ClawIO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ClawIOInputs {
99
public EE_RollerData rollerData = new EE_RollerData(false, 0, 0, 0, 0, 0);
1010
public EE_CANRangeData firstCANRangeData = new EE_CANRangeData(false, false);
1111
public EE_CANRangeData secondCANRangeData = new EE_CANRangeData(false, false);
12+
public EE_CANRangeData scoringCANRangeData = new EE_CANRangeData(false, false);
1213
}
1314

1415
record EE_RollerData(
@@ -29,6 +30,10 @@ default void setTorqueCurrent(double amps) {}
2930

3031
default void setRollerVelocity(double velocity) {}
3132

33+
default void setRollerPosition(double position) {}
34+
35+
default void setRollerTargetPosition(double position) {}
36+
3237
default boolean checkRollerStalled() {
3338
return false;
3439
}

src/main/java/frc/robot/subsystems/end_effector/ClawIOReal.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.ctre.phoenix6.BaseStatusSignal;
44
import com.ctre.phoenix6.StatusSignal;
5+
import com.ctre.phoenix6.configs.HardwareLimitSwitchConfigs;
6+
import com.ctre.phoenix6.configs.Slot0Configs;
7+
import com.ctre.phoenix6.controls.PositionVoltage;
58
import com.ctre.phoenix6.controls.TorqueCurrentFOC;
69
import com.ctre.phoenix6.controls.VoltageOut;
710
import com.ctre.phoenix6.hardware.CANrange;
@@ -22,6 +25,7 @@ public class ClawIOReal implements ClawIO {
2225
protected TalonFX rollerTalonFX;
2326
private CANrange firstCoralCANRange;
2427
private CANrange secondCoralCANRange;
28+
private CANrange scoringCANRange;
2529

2630
private TorqueCurrentFOC roller_c_request =
2731
new TorqueCurrentFOC(EndEffectorConstants.CLAW_HOLD_ALGAE_AMPS);
@@ -46,12 +50,26 @@ public ClawIOReal() {
4650
new CANrange(EndEffectorConstants.FIRST_CORAL_CANRANGE_ID, Constants.MISC_CANIVORE);
4751
secondCoralCANRange =
4852
new CANrange(EndEffectorConstants.SECOND_CORAL_CANRANGE_ID, Constants.MISC_CANIVORE);
53+
scoringCANRange = new CANrange(34, Constants.MISC_CANIVORE);
4954
PhoenixUtil.tryUntilOk(
5055
5, () -> firstCoralCANRange.getConfigurator().apply(EndEffectorConstants.CANRANGE_CONFIG));
5156
PhoenixUtil.tryUntilOk(
5257
5, () -> secondCoralCANRange.getConfigurator().apply(EndEffectorConstants.CANRANGE_CONFIG));
5358
PhoenixUtil.tryUntilOk(
54-
5, () -> rollerTalonFX.getConfigurator().apply(EndEffectorConstants.ROLLER_TALON_CONFIG));
59+
5, () -> scoringCANRange.getConfigurator().apply(EndEffectorConstants.CANRANGE_CONFIG));
60+
PhoenixUtil.tryUntilOk(
61+
5,
62+
() ->
63+
rollerTalonFX
64+
.getConfigurator()
65+
.apply(
66+
EndEffectorConstants.ROLLER_TALON_CONFIG
67+
.withHardwareLimitSwitch(
68+
new HardwareLimitSwitchConfigs()
69+
.withReverseLimitAutosetPositionEnable(true)
70+
.withReverseLimitAutosetPositionValue(-100)
71+
.withReverseLimitRemoteCANrange(scoringCANRange))
72+
.withSlot0(new Slot0Configs().withKP(100))));
5573

5674
rollerVelocityRPS = rollerTalonFX.getRotorVelocity();
5775
rollerAppliedVolts = rollerTalonFX.getMotorVoltage();
@@ -120,6 +138,16 @@ public void setRollerVoltage(double voltage) {
120138
rollerTalonFX.setControl(roller_m_request.withOutput(voltage));
121139
}
122140

141+
@Override
142+
public void setRollerPosition(double position) {
143+
rollerTalonFX.setPosition(0);
144+
}
145+
146+
@Override
147+
public void setRollerTargetPosition(double position) {
148+
rollerTalonFX.setControl(new PositionVoltage(position));
149+
}
150+
123151
@Override
124152
public boolean checkRollerStalled() {
125153
return debouncerAlgae.calculate(

0 commit comments

Comments
 (0)