From: EvanYap Date: Fri, 22 Jan 2016 03:45:09 +0000 (-0800) Subject: Add buttons pressed method and also also add state update X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=e8986b9b9e0e1b4cb654960e1f891cbfc38642a8;hp=da0c4bd895f527adc9fffdc0a19929379e069ae8;p=3501%2Fstronghold-2016 Add buttons pressed method and also also add state update --- diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java index 4ad89fd3..1d7fdb3c 100755 --- a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java @@ -1,15 +1,19 @@ package org.usfirst.frc.team3501.robot.subsystems; import org.usfirst.frc.team3501.robot.Constants; +import org.usfirst.frc.team3501.robot.Constants.Shooter.State; +import org.usfirst.frc.team3501.robot.Robot; import edu.wpi.first.wpilibj.CANTalon; import edu.wpi.first.wpilibj.command.Subsystem; public class Shooter extends Subsystem { - CANTalon shooter; + private CANTalon shooter; + private State state; public Shooter() { shooter = new CANTalon(Constants.Shooter.PORT); + state = State.STOPPED; } public double getCurrentSpeed() { @@ -17,9 +21,44 @@ public class Shooter extends Subsystem { } public void setSpeed(double speed) { + state = State.RUNNING; shooter.set(speed); } + public void shooterButtonsPressed() { + + if (Robot.oi.rightJoystick + .getRawButton(Constants.OI.INCREMENT_SHOOTER_PORT)) { + changeSpeed(0.1); + } + + if (Robot.oi.rightJoystick + .getRawButton(Constants.OI.DECREMENT_SHOOTER_PORT)) { + changeSpeed(-0.1); + } + + if (Robot.oi.rightJoystick.getRawButton(Constants.OI.TRIGGER_PORT)) { + if (this.getState() == State.STOPPED) + this.setSpeed(0.5); + } else { + if (this.getState() == State.RUNNING) { + this.stop(); + } + } + + if (Robot.oi.rightJoystick.getRawButton(Constants.OI.PRINT_PORT)) { + System.out.println("Current Shooter Speed: " + getCurrentSpeed()); + } + } + + private void stop() { + this.setSpeed(0.0); + } + + private State getState() { + return state; + } + // Use negative # for decrement. Positive for increment. public void changeSpeed(double change) { if (getCurrentSpeed() + change >= 1.0) @@ -30,6 +69,7 @@ public class Shooter extends Subsystem { double newSpeed = getCurrentSpeed() + change; setSpeed(newSpeed); } + this.state = State.RUNNING; } @Override