Skip to content

Commit b8aaf44

Browse files
committed
updated the intake subsystem
1 parent 6f70d1d commit b8aaf44

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import java.util.Optional;
1010

1111
import com.ctre.phoenix6.configs.CANcoderConfiguration;
12+
import com.ctre.phoenix6.configs.CANrangeConfiguration;
1213
import com.ctre.phoenix6.configs.TalonFXConfiguration;
1314
import com.ctre.phoenix6.signals.GravityTypeValue;
1415
import com.ctre.phoenix6.signals.InvertedValue;
1516
import com.ctre.phoenix6.signals.NeutralModeValue;
1617
import com.ctre.phoenix6.signals.SensorDirectionValue;
1718
import com.ctre.phoenix6.signals.StaticFeedforwardSignValue;
19+
import com.ctre.phoenix6.signals.UpdateModeValue;
1820
import com.frcteam3255.components.swerve.SN_SwerveConstants;
1921
import com.pathplanner.lib.config.ModuleConfig;
2022
import com.pathplanner.lib.config.PIDConstants;
@@ -221,6 +223,57 @@ public static class constIntake {
221223
// TODO: Replace with actual measurements
222224
public static final Current ALGAE_INTAKE_HAS_GP_CURRENT = Units.Amps.of(15);
223225
public static final AngularVelocity ALGAE_INTAKE_HAS_GP_VELOCITY = Units.RotationsPerSecond.of(2102 / 60);
226+
public static final TalonFXConfiguration INTAKE_PIVOT_CONFIG = new TalonFXConfiguration();
227+
public static final TalonFXConfiguration ALGAE_INTAKE_CONFIG = new TalonFXConfiguration();
228+
public static final TalonFXConfiguration CORAL_INTAKE_CONFIG = new TalonFXConfiguration();
229+
public static final CANrangeConfiguration CORAL_INTAKE_SENSOR_CONFIG = new CANrangeConfiguration();
230+
231+
static {
232+
// intake pivot motor
233+
INTAKE_PIVOT_CONFIG.MotorOutput.NeutralMode = NeutralModeValue.Brake;
234+
INTAKE_PIVOT_CONFIG.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
235+
236+
INTAKE_PIVOT_CONFIG.SoftwareLimitSwitch.ForwardSoftLimitEnable = true;
237+
INTAKE_PIVOT_CONFIG.SoftwareLimitSwitch.ForwardSoftLimitThreshold = Units.Rotations.of(57)
238+
.in(Units.Degrees);
239+
INTAKE_PIVOT_CONFIG.SoftwareLimitSwitch.ReverseSoftLimitEnable = true;
240+
INTAKE_PIVOT_CONFIG.SoftwareLimitSwitch.ReverseSoftLimitThreshold = Units.Rotations.of(-37)
241+
.in(Units.Degrees);
242+
243+
INTAKE_PIVOT_CONFIG.Feedback.SensorToMechanismRatio = 1000 / 27;// just like intake pivot, we still need
244+
// to get the ratio from fab
245+
INTAKE_PIVOT_CONFIG.Slot0.GravityType = GravityTypeValue.Arm_Cosine;
246+
INTAKE_PIVOT_CONFIG.Slot0.StaticFeedforwardSign = StaticFeedforwardSignValue.UseClosedLoopSign;
247+
248+
INTAKE_PIVOT_CONFIG.MotionMagic.MotionMagicCruiseVelocity = 9999;
249+
INTAKE_PIVOT_CONFIG.MotionMagic.MotionMagicAcceleration = 9999;
250+
251+
INTAKE_PIVOT_CONFIG.CurrentLimits.SupplyCurrentLimitEnable = true;
252+
INTAKE_PIVOT_CONFIG.CurrentLimits.SupplyCurrentLowerLimit = 30;
253+
INTAKE_PIVOT_CONFIG.CurrentLimits.SupplyCurrentLimit = 45;
254+
INTAKE_PIVOT_CONFIG.CurrentLimits.SupplyCurrentLowerTime = 0.5;
255+
256+
// algae intake motor config
257+
ALGAE_INTAKE_CONFIG.MotorOutput.NeutralMode = NeutralModeValue.Brake;
258+
ALGAE_INTAKE_CONFIG.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
259+
260+
ALGAE_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLimitEnable = true;
261+
ALGAE_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLowerLimit = 30;
262+
ALGAE_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLimit = 60;
263+
ALGAE_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLowerTime = 0.5;
264+
// coral intake motor config
265+
CORAL_INTAKE_CONFIG.MotorOutput.NeutralMode = NeutralModeValue.Brake;
266+
CORAL_INTAKE_CONFIG.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
267+
268+
CORAL_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLimitEnable = true;
269+
CORAL_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLowerLimit = 30;
270+
CORAL_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLimit = 60;
271+
CORAL_INTAKE_CONFIG.CurrentLimits.SupplyCurrentLowerTime = 0.5;
272+
// coral intake sensor config
273+
CORAL_INTAKE_SENSOR_CONFIG.ToFParams.UpdateMode = UpdateModeValue.ShortRange100Hz;
274+
CORAL_INTAKE_SENSOR_CONFIG.ProximityParams.ProximityThreshold = Units.Inches.of(3.95).in(Units.Meters);
275+
}
276+
224277
}
225278

226279
public static class constField {

src/main/java/frc/robot/subsystems/Intake.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import com.ctre.phoenix6.hardware.CANrange;
88
import com.ctre.phoenix6.hardware.TalonFX;
9+
import com.ctre.phoenix6.signals.NeutralModeValue;
910

11+
import static edu.wpi.first.units.Units.Degrees;
12+
import edu.wpi.first.units.measure.Angle;
1013
import edu.wpi.first.units.measure.AngularVelocity;
1114
import edu.wpi.first.units.measure.Current;
1215
import edu.wpi.first.wpilibj2.command.SubsystemBase;
@@ -20,15 +23,21 @@ public class Intake extends SubsystemBase {
2023
CANrange coralSensor;
2124
public boolean hasCoral = false;
2225
public boolean hasAlgae = false;
26+
private Angle lastDesiredAngle = Degrees.zero();
2327

2428
/** Creates a new Intake. */
2529
public Intake() {
2630
intakePivotMotor = new TalonFX(mapIntake.INTAKE_PIVOT_CAN); // Intake pivot motor
2731
coralIntakeMotor = new TalonFX(mapIntake.CORAL_INTAKE_CAN); // Coral left intake motor
2832
algaeIntakeMotor = new TalonFX(mapIntake.INTAKE_ALGAE_CAN); // Algae intake motor
33+
coralSensor = new CANrange(mapIntake.CORAL_INTAKE_SENSOR); // Coral intake sensor
2934

3035
// Set default motor configurations if needed
3136
// e.g., intakePivotMotor.configFactoryDefault();
37+
intakePivotMotor.getConfigurator().apply(constIntake.INTAKE_PIVOT_CONFIG);
38+
coralIntakeMotor.getConfigurator().apply(constIntake.CORAL_INTAKE_CONFIG);
39+
algaeIntakeMotor.getConfigurator().apply(constIntake.ALGAE_INTAKE_CONFIG);
40+
coralSensor.getConfigurator().apply(constIntake.CORAL_INTAKE_SENSOR_CONFIG);
3241
}
3342

3443
public boolean hasCoral() {
@@ -53,6 +62,32 @@ public boolean hasAlgae() {
5362
}
5463
}
5564

65+
public void getIntakePivtoMotorAngle() {
66+
double angle = intakePivotMotor.getPosition().getValueAsDouble();
67+
68+
}
69+
70+
public Angle getLastDesiredPivotAngle() {
71+
return lastDesiredAngle;
72+
}
73+
74+
public void setIntakePivotMotor(double Angle) {
75+
intakePivotMotor.setVoltage(Angle);
76+
}
77+
78+
public void setCoralIntakeMotor(double speed) {
79+
coralIntakeMotor.setVoltage(speed);
80+
}
81+
82+
public void setAlgaeIntakeMotor(double speed) {
83+
algaeIntakeMotor.setVoltage(speed);
84+
}
85+
86+
public void setIntakeMotorNeutralMode(NeutralModeValue mode) {
87+
intakePivotMotor.setNeutralMode(mode);
88+
algaeIntakeMotor.setNeutralMode(mode);
89+
}
90+
5691
@Override
5792
public void periodic() {
5893
// This method will be called once per scheduler run

0 commit comments

Comments
 (0)