From 4430b9f0c856b2c4ffacb3d201fe8f78076a4230 Mon Sep 17 00:00:00 2001 From: Connor Peach Date: Sat, 16 Mar 2024 12:07:28 -0600 Subject: [PATCH] add debounce --- .../robot/commands/Intake/ArmIntakeIn.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc4388/robot/commands/Intake/ArmIntakeIn.java b/src/main/java/frc4388/robot/commands/Intake/ArmIntakeIn.java index 78c558b..64259e5 100644 --- a/src/main/java/frc4388/robot/commands/Intake/ArmIntakeIn.java +++ b/src/main/java/frc4388/robot/commands/Intake/ArmIntakeIn.java @@ -13,7 +13,6 @@ public class ArmIntakeIn extends Command { /** Creates a new ArmIntakeIn. */ private Intake robotIntake; private Shooter robotShooter; - public ArmIntakeIn(Intake robotIntake, Shooter robotShooter) { // Use addRequirements() here to declare subsystem dependencies. this.robotIntake = robotIntake; @@ -21,7 +20,6 @@ public class ArmIntakeIn extends Command { addRequirements(this.robotIntake, this.robotShooter); } - // Called when the command is initially scheduled. @Override public void initialize() {} @@ -37,10 +35,22 @@ public class ArmIntakeIn extends Command { @Override public void end(boolean interrupted) {} + //debounce + private long time; + private boolean lastpressed = false; + // Returns true when the command should end. @Override public boolean isFinished() { - return robotIntake.getTalonIntakeLimitSwitchState(); + if(!lastpressed) + time = System.currentTimeMillis(); + + if(lastpressed && time - System.currentTimeMillis() > 200) + return true; + + + lastpressed = robotIntake.getTalonIntakeLimitSwitchState(); + return false; // if(!(!robotIntake.getTalonIntakeLimitSwitchState() != !false) && ((-1.0 / 0.0) == (-2.0 / 0.0))) // { // return !true==true;