Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intake Subsystem #17

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2025.1.1"
id "edu.wpi.first.GradleRIO" version "2025.3.1"
}

java {
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -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();
}

Expand All @@ -41,9 +43,10 @@ public RobotContainer() {
* joysticks}.
*/
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
}

/**
* Use this to pass the autonomous command to the main {@link Robot} class.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
24 changes: 24 additions & 0 deletions src/main/java/frc/robot/constants/Intake/IntakeConfigs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package frc.robot.constants.Intake;

import com.ctre.phoenix6.configs.MotorOutputConfigs;

import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.signals.InvertedValue;




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);


public static TalonFXConfiguration intakeMotorConfig = new TalonFXConfiguration()
.withMotorOutput(motorOutputConfigs);

}
50 changes: 50 additions & 0 deletions src/main/java/frc/robot/constants/Intake/IntakeSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package frc.robot.constants.Intake;


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;
import static frc.robot.constants.Intake.IntakeConfigs.*;


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 boolean getBeamBreak(){
return !beamBreak.get();
}

public void runIntake(double speed){
intakeMotor.setControl(new VoltageOut(speed));
}

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();
}
}
}