From 8e51663dd58c57c38f1ebefc1b2e8a0b1c5fec99 Mon Sep 17 00:00:00 2001 From: Xiaohan Date: Tue, 30 Jan 2024 17:11:54 -0600 Subject: [PATCH 1/3] Fixed indexer and shooter, :3 --- .../java/frc/robot/commands/IndexCommand.java | 6 +- .../java/frc/robot/settings/Constants.java | 11 ++-- .../robot/subsystems/IndexerSubsystem.java | 62 ++++++------------- .../robot/subsystems/ShooterSubsystem.java | 30 ++++----- 4 files changed, 42 insertions(+), 67 deletions(-) diff --git a/src/main/java/frc/robot/commands/IndexCommand.java b/src/main/java/frc/robot/commands/IndexCommand.java index 5989de8d..36a21d12 100644 --- a/src/main/java/frc/robot/commands/IndexCommand.java +++ b/src/main/java/frc/robot/commands/IndexCommand.java @@ -42,15 +42,15 @@ public void initialize() { public void execute() { if (m_Indexer.getInchesFromSensor()>8) { intake.intakeYes(1); - m_Indexer.holderRetrieve(0.5); + m_Indexer.on(); shooter.turnOff(); } else { intake.intakeOff(); - m_Indexer.holderOff(); + m_Indexer.off(); shooter.shootThing(1); } if (shootButtonSupplier.getAsBoolean()) { - m_Indexer.feederFeed(0.5); + m_Indexer.on(); } } diff --git a/src/main/java/frc/robot/settings/Constants.java b/src/main/java/frc/robot/settings/Constants.java index 3c9cff4e..73189cf7 100644 --- a/src/main/java/frc/robot/settings/Constants.java +++ b/src/main/java/frc/robot/settings/Constants.java @@ -256,8 +256,8 @@ private DriveConstants() { public static final double k_PICKUP_NOTE_tx_D = 0; } public static final class ShooterConstants{ - public static final int SHOOTER_1_MOTORID = 2491; - public static final int SHOOTER_2_MOTORID = 2491; + public static final int SHOOTER_R_MOTORID = 2491; + public static final int SHOOTER_L_MOTORID = 2491; public static final int PITCH_MOTOR_ID = 2491; public static final double SHOOTER_MOTOR_POWER = 1; public static final double SHOOTING_SPEED_MPS = 10; @@ -306,11 +306,8 @@ public static final class ClimberConstants{ public static final double CLIMBER_RPM = 0.1; } public static final class IndexerConstants{ - public static final int FEEDER_1_MOTOR = 2491; - public static final int FEEDER_2_MOTOR = 2491; - public static final int HOLDER_1_MOTOR = 2491; - public static final int HOLDER_2_MOTOR = 2491; - public static final double INDEXER_SPEED = 0.75; + public static final int INDEXER_MOTOR = 2491; + public static final double INDEXER_SPEED = 2491; } public static final class IntakeConstants{ public static final int INTAKE_1_MOTOR = 2491; diff --git a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java index 716324f9..4532c8f3 100644 --- a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java @@ -1,56 +1,32 @@ package frc.robot.subsystems; - + import com.revrobotics.CANSparkMax; - import com.revrobotics.RelativeEncoder; -import com.revrobotics.SparkPIDController; - import com.revrobotics.SparkRelativeEncoder; - import com.revrobotics.CANSparkBase.ControlType; - import com.revrobotics.CANSparkBase.IdleMode; - import com.revrobotics.CANSparkLowLevel.MotorType; - import edu.wpi.first.wpilibj2.command.SubsystemBase; -import frc.robot.settings.Constants; +import com.revrobotics.CANSparkLowLevel.MotorType; +import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.settings.Constants.IndexerConstants; -public class IndexerSubsystem extends SubsystemBase{ - CANSparkMax holder1; - CANSparkMax holder2; - CANSparkMax feeder1; - CANSparkMax feeder2; - boolean isHolding; - public IndexerSubsystem(){ - CANSparkMax holder1 = new CANSparkMax(IndexerConstants.HOLDER_1_MOTOR, MotorType.kBrushless); - CANSparkMax holder2 = new CANSparkMax(IndexerConstants.HOLDER_2_MOTOR, MotorType.kBrushless); - CANSparkMax feeder1 = new CANSparkMax(IndexerConstants.FEEDER_1_MOTOR, MotorType.kBrushless); - CANSparkMax feeder2 = new CANSparkMax(IndexerConstants.FEEDER_2_MOTOR, MotorType.kBrushless); - //sensor sensorThingy = new ???; - boolean isHolding = false; - feeder2.follow(feeder1); - feeder2.setInverted(true); - holder2.follow(holder1); - holder2.setInverted(true); - holder1.setIdleMode(IdleMode.kBrake); - holder2.setIdleMode(IdleMode.kBrake); - feeder1.setIdleMode(IdleMode.kBrake); - feeder2.setIdleMode(IdleMode.kBrake); +public class IndexerSubsystem extends SubsystemBase { + CANSparkMax m_IndexerMotor; + boolean Indexer; + + public IndexerSubsystem() { + CANSparkMax indexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR, MotorType.kBrushless); + indexerMotor = m_IndexerMotor; } public double getInchesFromSensor() { return 0; } - public void feederFeed(double generalSpeed){ - feeder1.set(generalSpeed); - } - public void feederOff(){ - feeder1.set(0); - } - public void holderRetrieve(double generalSpeed){ - holder1.set(generalSpeed); + + public void on() { + m_IndexerMotor.set(IndexerConstants.INDEXER_SPEED); } - public void holderOff(){ - holder1.set(0); + + public void off() { + m_IndexerMotor.set(0); } - public void allOff(){ - feeder1.set(0); - holder1.set(0); + + public void reverse() { + m_IndexerMotor.set(-IndexerConstants.INDEXER_SPEED); } } diff --git a/src/main/java/frc/robot/subsystems/ShooterSubsystem.java b/src/main/java/frc/robot/subsystems/ShooterSubsystem.java index 6e95e10d..b8dacc2e 100644 --- a/src/main/java/frc/robot/subsystems/ShooterSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ShooterSubsystem.java @@ -33,8 +33,8 @@ import java.util.function.BooleanSupplier; public class ShooterSubsystem extends SubsystemBase { - CANSparkMax shooter1; - CANSparkMax shooter2; + CANSparkMax shooterR; + CANSparkMax shooterL; CANSparkMax pitchMotor; double runSpeed; @@ -81,19 +81,19 @@ public class ShooterSubsystem extends SubsystemBase { public ShooterSubsystem(double runSpeed, BooleanSupplier aimAtAmp) { SparkPIDController shooterPID; this.aimAtAmp = aimAtAmp; - shooter1 = new CANSparkMax(ShooterConstants.SHOOTER_1_MOTORID, MotorType.kBrushless); - shooter2 = new CANSparkMax(ShooterConstants.SHOOTER_2_MOTORID, MotorType.kBrushless); + shooterR = new CANSparkMax(ShooterConstants.SHOOTER_R_MOTORID, MotorType.kBrushless); + shooterL = new CANSparkMax(ShooterConstants.SHOOTER_L_MOTORID, MotorType.kBrushless); pitchMotor = new CANSparkMax(ShooterConstants.PITCH_MOTOR_ID, MotorType.kBrushless); - shooter1.restoreFactoryDefaults(); - shooter2.follow(shooter1); - shooter2.setInverted(true); - shooter1.setIdleMode(IdleMode.kCoast); - shooter2.setIdleMode(IdleMode.kCoast); + shooterR.restoreFactoryDefaults(); + shooterL.follow(shooterR); + shooterL.setInverted(true); + shooterR.setIdleMode(IdleMode.kCoast); + shooterL.setIdleMode(IdleMode.kCoast); - encoder1 = shooter1.getEncoder(SparkRelativeEncoder.Type.kQuadrature, 4096); + encoder1 = shooterR.getEncoder(SparkRelativeEncoder.Type.kQuadrature, 4096); - shooterPID = shooter1.getPIDController(); + shooterPID = shooterR.getPIDController(); pitchPID = pitchMotor.getPIDController(); pitchPID.setFF(pitchFeedForward); @@ -146,11 +146,13 @@ public ShooterSubsystem(double runSpeed, BooleanSupplier aimAtAmp) { public void shootThing(double runSpeed) { - shooter1.set(runSpeed); + shooterR.set(runSpeed); + shooterL.set(runSpeed); } public void turnOff(){ - shooter1.set(0); - } + shooterR.set(0); + shooterL.set(0); + } public void pitchShooter(double pitchSpeed){ pitchMotor.set(pitchSpeed); } From b52ab535278dd65f4a5bb32d8181026276dc0767 Mon Sep 17 00:00:00 2001 From: Xiaohan Date: Tue, 30 Jan 2024 17:15:25 -0600 Subject: [PATCH 2/3] round 2, changged robot container --- src/main/java/frc/robot/RobotContainer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 30730083..bb061148 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -282,8 +282,8 @@ private void configureDriveTrain() { private void registerNamedCommands() { NamedCommands.registerCommand("stopDrivetrain", new InstantCommand(driveTrain::stop, driveTrain)); if(shooterExists) {NamedCommands.registerCommand("shooterOn", new InstantCommand(()->shooter.shootThing(1), shooter)); - NamedCommands.registerCommand("stopFeedingShooter", new InstantCommand(indexer::feederOff, indexer));} - if(indexerExists) {NamedCommands.registerCommand("feedShooter", new InstantCommand(()->indexer.feederFeed(0.5), indexer));} + NamedCommands.registerCommand("stopFeedingShooter", new InstantCommand(indexer::off, indexer));} + if(indexerExists) {NamedCommands.registerCommand("feedShooter", new InstantCommand(()->indexer.on(), indexer));} if(intakeExists) {NamedCommands.registerCommand("autoPickup", new CollectNote(driveTrain, intake)); NamedCommands.registerCommand("intakeOn", new InstantCommand(()-> intake.intakeYes(1)));} } From 9bfdaf0b684a4df93c8aa5a8e729c14c8d6029d3 Mon Sep 17 00:00:00 2001 From: Xiaohan Date: Tue, 30 Jan 2024 17:27:26 -0600 Subject: [PATCH 3/3] round 3: made indexer actually work --- src/main/java/frc/robot/subsystems/IndexerSubsystem.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java index 4532c8f3..639e76fc 100644 --- a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java @@ -7,11 +7,9 @@ public class IndexerSubsystem extends SubsystemBase { CANSparkMax m_IndexerMotor; - boolean Indexer; public IndexerSubsystem() { - CANSparkMax indexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR, MotorType.kBrushless); - indexerMotor = m_IndexerMotor; + m_IndexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR, MotorType.kBrushless); } public double getInchesFromSensor() {