From 04328ead68ede5f9d551765c31883f184cab2120 Mon Sep 17 00:00:00 2001 From: Xiaohan Date: Tue, 30 Jan 2024 18:10:24 -0600 Subject: [PATCH 1/2] added distance sensor how we want it --- src/main/java/frc/robot/commands/IndexCommand.java | 6 ++++-- .../java/frc/robot/subsystems/IndexerSubsystem.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/frc/robot/commands/IndexCommand.java b/src/main/java/frc/robot/commands/IndexCommand.java index 36a21d12..dd9a33b1 100644 --- a/src/main/java/frc/robot/commands/IndexCommand.java +++ b/src/main/java/frc/robot/commands/IndexCommand.java @@ -40,13 +40,15 @@ public void initialize() { // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - if (m_Indexer.getInchesFromSensor()>8) { + if (!m_Indexer.isNoteIn()) { intake.intakeYes(1); m_Indexer.on(); shooter.turnOff(); } else { intake.intakeOff(); - m_Indexer.off(); + if(shootButtonSupplier.getAsBoolean()) { + m_Indexer.off(); + } shooter.shootThing(1); } if (shootButtonSupplier.getAsBoolean()) { diff --git a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java index 639e76fc..0b117b23 100644 --- a/src/main/java/frc/robot/subsystems/IndexerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/IndexerSubsystem.java @@ -1,19 +1,24 @@ package frc.robot.subsystems; import com.revrobotics.CANSparkMax; +import com.revrobotics.SparkAnalogSensor; import com.revrobotics.CANSparkLowLevel.MotorType; +import com.revrobotics.SparkAnalogSensor.Mode; + import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.settings.Constants.IndexerConstants; public class IndexerSubsystem extends SubsystemBase { CANSparkMax m_IndexerMotor; + SparkAnalogSensor m_DistanceSensor; public IndexerSubsystem() { m_IndexerMotor = new CANSparkMax(IndexerConstants.INDEXER_MOTOR, MotorType.kBrushless); + m_DistanceSensor = m_IndexerMotor.getAnalog(Mode.kAbsolute); } - - public double getInchesFromSensor() { - return 0; + + public boolean isNoteIn() { + return m_DistanceSensor.getVoltage()>1; } public void on() { From 7990ad9c47ca1d394297ae9bdc22965a3b53f83e Mon Sep 17 00:00:00 2001 From: Rowan Flood <121908273+rflood07@users.noreply.github.com> Date: Tue, 30 Jan 2024 19:29:43 -0600 Subject: [PATCH 2/2] Update IndexCommand.java --- src/main/java/frc/robot/commands/IndexCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/frc/robot/commands/IndexCommand.java b/src/main/java/frc/robot/commands/IndexCommand.java index dd9a33b1..922be48c 100644 --- a/src/main/java/frc/robot/commands/IndexCommand.java +++ b/src/main/java/frc/robot/commands/IndexCommand.java @@ -46,7 +46,7 @@ public void execute() { shooter.turnOff(); } else { intake.intakeOff(); - if(shootButtonSupplier.getAsBoolean()) { + if(!shootButtonSupplier.getAsBoolean()) { m_Indexer.off(); } shooter.shootThing(1);