From c53a4159a8007ebe921c3932d0eb1b9579c012c9 Mon Sep 17 00:00:00 2001 From: adarsh-cms Date: Thu, 13 Feb 2025 20:20:41 -0500 Subject: [PATCH 1/5] Finished the roller bars for the intake. Final adjustments may be needed. --- build.gradle | 2 +- .../java/frc/robot/constants/Constants.java | 2 ++ .../robot/constants/Intake/IntakeConfigs.java | 30 ++++++++++++++++ .../constants/Intake/IntakeSubsystem.java | 34 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/frc/robot/constants/Intake/IntakeConfigs.java create mode 100644 src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java diff --git a/build.gradle b/build.gradle index 11d95e6..b9f0e50 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2025.1.1" + id "edu.wpi.first.GradleRIO" version "2025.2.1" } java { diff --git a/src/main/java/frc/robot/constants/Constants.java b/src/main/java/frc/robot/constants/Constants.java index 1e552e6..629964c 100755 --- a/src/main/java/frc/robot/constants/Constants.java +++ b/src/main/java/frc/robot/constants/Constants.java @@ -15,4 +15,6 @@ */ public final class Constants { public static final int XBOX_CONTROLLER_PORT = 0; + public static final String CANIVORE_BUS = "canivoreBus"; + public static final String RIO_BUS = "rio"; } diff --git a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java new file mode 100644 index 0000000..3209555 --- /dev/null +++ b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java @@ -0,0 +1,30 @@ +package frc.robot.constants.Intake; + +import com.ctre.phoenix6.configs.MotorOutputConfigs; +import com.ctre.phoenix6.configs.Slot0Configs; +import com.ctre.phoenix6.configs.TalonFXConfiguration; +import com.ctre.phoenix6.signals.InvertedValue; + +import java.lang.module.Configuration; + + +public class IntakeConfigs { + + public static final int INTAKE_MOTOR_ID = 8; + public static final int VOLTAGE_OUTPUT = 12; + + public static Slot0Configs slot0Configs = new Slot0Configs() + .withKP(0) + .withKI(0) + .withKD(0) + .withKS(0); + + public static MotorOutputConfigs motorOutputConfigs = new MotorOutputConfigs() + .withInverted(InvertedValue.Clockwise_Positive); + + + public static TalonFXConfiguration intakeMotorConfig = new TalonFXConfiguration() + .withSlot0(slot0Configs) + .withMotorOutput(motorOutputConfigs); + +} diff --git a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java new file mode 100644 index 0000000..a0102a2 --- /dev/null +++ b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java @@ -0,0 +1,34 @@ +package frc.robot.constants.Intake; + +import com.ctre.phoenix6.controls.MotionMagicVelocityTorqueCurrentFOC; +import com.ctre.phoenix6.controls.MotionMagicVelocityVoltage; +import com.ctre.phoenix6.controls.VoltageOut; +import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.wpilibj2.command.SubsystemBase; +import static frc.robot.constants.Constants.CANIVORE_BUS; +import static frc.robot.constants.Intake.IntakeConfigs.*; + + +public class IntakeSubsystem extends SubsystemBase { + private final TalonFX intakeMotor = new TalonFX(INTAKE_MOTOR_ID, CANIVORE_BUS); + public VoltageOut voltageOut = new VoltageOut(0); + + + + public IntakeSubsystem(){ + intakeMotor.getConfigurator().apply(intakeMotorConfig); + } + + public void stopIntake(){ + intakeMotor.stopMotor(); + } + + public void runIntakeOut(){ + intakeMotor.setControl(voltageOut.withOutput(VOLTAGE_OUTPUT)); + } + public void runIntakeIn(){ + intakeMotor.setControl(voltageOut.withOutput(-VOLTAGE_OUTPUT)); + } + +} + From cd4580d24c7623a170c48e93770c471aba90d136 Mon Sep 17 00:00:00 2001 From: adarsh-cms Date: Sat, 15 Feb 2025 13:17:57 -0500 Subject: [PATCH 2/5] Finished the roller bars for the intake. Configured bindings for the flywheel (For now, just for testing). Final adjustments may be needed. --- build.gradle | 2 +- src/main/java/frc/robot/RobotContainer.java | 9 ++++++--- .../frc/robot/constants/Intake/IntakeConfigs.java | 4 ++-- .../robot/constants/Intake/IntakeSubsystem.java | 14 +++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index b9f0e50..90f24da 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "java" - id "edu.wpi.first.GradleRIO" version "2025.2.1" + id "edu.wpi.first.GradleRIO" version "2025.3.1" } java { diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index a65ad18..8235840 100755 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -5,11 +5,12 @@ package frc.robot; -import edu.wpi.first.wpilibj.XboxController; + import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.Trigger; import frc.robot.constants.Constants; +import frc.robot.constants.Intake.IntakeSubsystem; /** @@ -20,13 +21,14 @@ */ public class RobotContainer { - XboxController xboxController; + CommandXboxController xboxController; + private final IntakeSubsystem intakeSubsystem = new IntakeSubsystem(); /** * The container for the robot. Contains subsystems, OI devices, and commands. */ public RobotContainer() { - xboxController = new XboxController(Constants.XBOX_CONTROLLER_PORT); + xboxController = new CommandXboxController(Constants.XBOX_CONTROLLER_PORT); configureBindings(); } @@ -41,6 +43,7 @@ public RobotContainer() { * joysticks}. */ private void configureBindings() { + xboxController.a().whileTrue(intakeSubsystem.spinIntake()); } diff --git a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java index 3209555..00de886 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java @@ -5,13 +5,13 @@ import com.ctre.phoenix6.configs.TalonFXConfiguration; import com.ctre.phoenix6.signals.InvertedValue; -import java.lang.module.Configuration; + public class IntakeConfigs { public static final int INTAKE_MOTOR_ID = 8; - public static final int VOLTAGE_OUTPUT = 12; + public static Slot0Configs slot0Configs = new Slot0Configs() .withKP(0) diff --git a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java index a0102a2..40e5664 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java @@ -1,9 +1,9 @@ package frc.robot.constants.Intake; -import com.ctre.phoenix6.controls.MotionMagicVelocityTorqueCurrentFOC; -import com.ctre.phoenix6.controls.MotionMagicVelocityVoltage; + import com.ctre.phoenix6.controls.VoltageOut; import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import static frc.robot.constants.Constants.CANIVORE_BUS; import static frc.robot.constants.Intake.IntakeConfigs.*; @@ -11,7 +11,7 @@ public class IntakeSubsystem extends SubsystemBase { private final TalonFX intakeMotor = new TalonFX(INTAKE_MOTOR_ID, CANIVORE_BUS); - public VoltageOut voltageOut = new VoltageOut(0); + @@ -23,11 +23,11 @@ public void stopIntake(){ intakeMotor.stopMotor(); } - public void runIntakeOut(){ - intakeMotor.setControl(voltageOut.withOutput(VOLTAGE_OUTPUT)); + public void runIntakeOut(double speed){ + intakeMotor.setControl(new VoltageOut(speed)); } - public void runIntakeIn(){ - intakeMotor.setControl(voltageOut.withOutput(-VOLTAGE_OUTPUT)); + public Command spinIntake(){ + return startEnd(()-> runIntakeOut(2), this::stopIntake).withTimeout(1); } } From 35995a44d3f699ac73db80777978ab4ae11e92ff Mon Sep 17 00:00:00 2001 From: adarsh-cms Date: Sat, 15 Feb 2025 15:05:15 -0500 Subject: [PATCH 3/5] Added an eject command that reverses intake. --- src/main/java/frc/robot/RobotContainer.java | 3 +-- .../java/frc/robot/constants/Intake/IntakeSubsystem.java | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 8235840..568a207 100755 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -43,8 +43,7 @@ public RobotContainer() { * joysticks}. */ private void configureBindings() { - xboxController.a().whileTrue(intakeSubsystem.spinIntake()); - + xboxController.a().onTrue(intakeSubsystem.spinIntake()); } /** diff --git a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java index 40e5664..84eb33c 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java @@ -17,6 +17,7 @@ public class IntakeSubsystem extends SubsystemBase { public IntakeSubsystem(){ intakeMotor.getConfigurator().apply(intakeMotorConfig); + } public void stopIntake(){ @@ -27,7 +28,10 @@ public void runIntakeOut(double speed){ intakeMotor.setControl(new VoltageOut(speed)); } public Command spinIntake(){ - return startEnd(()-> runIntakeOut(2), this::stopIntake).withTimeout(1); + return startEnd(()-> runIntakeOut(5), this::stopIntake).withTimeout(.5); + } + public Command spinIntakeOut(){ + return startEnd(()-> runIntakeOut(-5), this::stopIntake).withTimeout(1); } } From 6360e4a1450f292ddf6a8edf7b007fbdcd5ebb50 Mon Sep 17 00:00:00 2001 From: adarsh-cms Date: Thu, 20 Feb 2025 20:26:17 -0500 Subject: [PATCH 4/5] added a boolean variable to the intake roller bars to reduce code. Removed unnecessary configs. --- src/main/java/frc/robot/RobotContainer.java | 4 ++-- .../java/frc/robot/constants/Intake/IntakeConfigs.java | 10 +--------- .../frc/robot/constants/Intake/IntakeSubsystem.java | 8 +++----- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 568a207..92b4621 100755 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -43,9 +43,9 @@ public RobotContainer() { * joysticks}. */ private void configureBindings() { - xboxController.a().onTrue(intakeSubsystem.spinIntake()); + xboxController.a().onTrue(intakeSubsystem.spinIntake(true)); + // if true, intakes note, if false spits the note out } - /** * Use this to pass the autonomous command to the main {@link Robot} class. * diff --git a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java index 00de886..ed6eab9 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java @@ -1,7 +1,7 @@ package frc.robot.constants.Intake; import com.ctre.phoenix6.configs.MotorOutputConfigs; -import com.ctre.phoenix6.configs.Slot0Configs; + import com.ctre.phoenix6.configs.TalonFXConfiguration; import com.ctre.phoenix6.signals.InvertedValue; @@ -12,19 +12,11 @@ public class IntakeConfigs { public static final int INTAKE_MOTOR_ID = 8; - - public static Slot0Configs slot0Configs = new Slot0Configs() - .withKP(0) - .withKI(0) - .withKD(0) - .withKS(0); - public static MotorOutputConfigs motorOutputConfigs = new MotorOutputConfigs() .withInverted(InvertedValue.Clockwise_Positive); public static TalonFXConfiguration intakeMotorConfig = new TalonFXConfiguration() - .withSlot0(slot0Configs) .withMotorOutput(motorOutputConfigs); } diff --git a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java index 84eb33c..eb0f77e 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java @@ -27,12 +27,10 @@ public void stopIntake(){ public void runIntakeOut(double speed){ intakeMotor.setControl(new VoltageOut(speed)); } - public Command spinIntake(){ - return startEnd(()-> runIntakeOut(5), this::stopIntake).withTimeout(.5); - } - public Command spinIntakeOut(){ - return startEnd(()-> runIntakeOut(-5), this::stopIntake).withTimeout(1); + public Command spinIntake(boolean reversed){ + return startEnd(()-> runIntakeOut(5 * (reversed ? 1 : -1)), this::stopIntake).withTimeout(2); } + } From 89e5d005586134e7e67feefe4642160fbf81cfda Mon Sep 17 00:00:00 2001 From: adarsh-cms Date: Thu, 20 Feb 2025 21:21:00 -0500 Subject: [PATCH 5/5] Added beam break code that runs the intake in or out depending on the argument passes: true = intake in until beam break returns true; false = intake out for 3 seconds. --- src/main/java/frc/robot/RobotContainer.java | 1 + .../robot/constants/Intake/IntakeConfigs.java | 2 ++ .../constants/Intake/IntakeSubsystem.java | 28 ++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 92b4621..367b8b9 100755 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -44,6 +44,7 @@ public RobotContainer() { */ private void configureBindings() { xboxController.a().onTrue(intakeSubsystem.spinIntake(true)); + xboxController.b().onTrue(intakeSubsystem.spinIntake(false)); // if true, intakes note, if false spits the note out } /** diff --git a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java index ed6eab9..0118123 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeConfigs.java @@ -11,6 +11,8 @@ public class IntakeConfigs { public static final int INTAKE_MOTOR_ID = 8; + public static final int BEAMBREAK_ID = 2; + public static final int ROLLER_SPEED = 5; public static MotorOutputConfigs motorOutputConfigs = new MotorOutputConfigs() .withInverted(InvertedValue.Clockwise_Positive); diff --git a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java index eb0f77e..5ec4027 100644 --- a/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java +++ b/src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java @@ -3,6 +3,7 @@ import com.ctre.phoenix6.controls.VoltageOut; import com.ctre.phoenix6.hardware.TalonFX; +import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import static frc.robot.constants.Constants.CANIVORE_BUS; @@ -11,26 +12,39 @@ public class IntakeSubsystem extends SubsystemBase { private final TalonFX intakeMotor = new TalonFX(INTAKE_MOTOR_ID, CANIVORE_BUS); - - - + private final DigitalInput beamBreak = new DigitalInput(BEAMBREAK_ID); public IntakeSubsystem(){ intakeMotor.getConfigurator().apply(intakeMotorConfig); - } public void stopIntake(){ intakeMotor.stopMotor(); } - public void runIntakeOut(double speed){ + public boolean getBeamBreak(){ + return !beamBreak.get(); + } + + public void runIntake(double speed){ intakeMotor.setControl(new VoltageOut(speed)); } - public Command spinIntake(boolean reversed){ - return startEnd(()-> runIntakeOut(5 * (reversed ? 1 : -1)), this::stopIntake).withTimeout(2); + + public Command in(){ + return startEnd(()-> runIntake(ROLLER_SPEED), this::stopIntake).until(this::getBeamBreak); } + public Command out(){ + return startEnd(()-> runIntake(-ROLLER_SPEED), this::stopIntake).withTimeout(3); + } + public Command spinIntake(boolean reversed){ + if (reversed == true){ + return in(); + } + else{ + return out(); + } + } }