From: EvanYap Date: Fri, 22 Jan 2016 03:16:24 +0000 (-0800) Subject: Make command for running the shooter when trigger is pressed X-Git-Url: http://challenge-bot.com/repos/?a=commitdiff_plain;h=b87f970088167bdd3f9be3a2e55b28847d37d819;hp=47ce2b096c12934905e63f52d8cf7776af348b60;p=3501%2Fstronghold-2016 Make command for running the shooter when trigger is pressed --- diff --git a/src/org/usfirst/frc/team3501/robot/OI.java b/src/org/usfirst/frc/team3501/robot/OI.java index 4367d6ae..c93ce127 100644 --- a/src/org/usfirst/frc/team3501/robot/OI.java +++ b/src/org/usfirst/frc/team3501/robot/OI.java @@ -1,6 +1,7 @@ package org.usfirst.frc.team3501.robot; -import org.usfirst.frc.team3501.robot.commands.changeSpeed; +import org.usfirst.frc.team3501.robot.commands.runShooter; +import org.usfirst.frc.team3501.robot.commands.setShooterSpeed; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.buttons.Button; @@ -20,19 +21,17 @@ public class OI { decrementSpeed = new JoystickButton(rightJoystick, Constants.OI.DECREMENT_SHOOTER_PORT); + decrementSpeed.whenPressed(new setShooterSpeed(-0.1)); incrementSpeed = new JoystickButton(rightJoystick, Constants.OI.INCREMENT_SHOOTER_PORT); + incrementSpeed.whenPressed(new setShooterSpeed(0.1)); outputCurrentShooterSpeed = new JoystickButton(rightJoystick, Constants.OI.SHOOTER_PORT); runWheel = new JoystickButton(rightJoystick, Constants.OI.TRIGGER_PORT); - - incrementSpeed.whenPressed(new changeSpeed(0.1)); - - decrementSpeed.whenPressed(new changeSpeed(-0.1)); - + runWheel.whenPressed(new runShooter()); } } diff --git a/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java deleted file mode 100644 index 4928d87c..00000000 --- a/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.usfirst.frc.team3501.robot.commands; - -import org.usfirst.frc.team3501.robot.Robot; - -import edu.wpi.first.wpilibj.command.Command; - -public class changeSpeed extends Command { - double change = 0.0; - - public changeSpeed(double change) { - this.change = change; - } - - @Override - protected void initialize() { - } - - @Override - protected void execute() { - Robot.shooter.changeSpeed(change); - } - - @Override - protected boolean isFinished() { - return true; - } - - @Override - protected void end() { - } - - @Override - protected void interrupted() { - } -} diff --git a/src/org/usfirst/frc/team3501/robot/commands/runShooter.java b/src/org/usfirst/frc/team3501/robot/commands/runShooter.java new file mode 100644 index 00000000..3d87624f --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/runShooter.java @@ -0,0 +1,37 @@ +package org.usfirst.frc.team3501.robot.commands; + +import org.usfirst.frc.team3501.robot.Robot; + +import edu.wpi.first.wpilibj.command.Command; + +/** + * + */ +public class runShooter extends Command { + + public runShooter() { + + } + + @Override + protected void initialize() { + Robot.shooter.setSpeed(0.5); + } + + @Override + protected void execute() { + } + + @Override + protected boolean isFinished() { + return true; + } + + @Override + protected void end() { + } + + @Override + protected void interrupted() { + } +} diff --git a/src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java b/src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java new file mode 100644 index 00000000..197da910 --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java @@ -0,0 +1,41 @@ +package org.usfirst.frc.team3501.robot.commands; + +import org.usfirst.frc.team3501.robot.Robot; + +import edu.wpi.first.wpilibj.command.Command; + +public class setShooterSpeed extends Command { + double change = 0.0; + double speed = Robot.shooter.getCurrentSpeed(); + + public setShooterSpeed(double speed) { + this.speed = speed; + } + + public setShooterSpeed(double speed, double change) { + this.speed = speed; + this.change = change; + } + + @Override + protected void initialize() { + } + + @Override + protected void execute() { + Robot.shooter.setSpeed(change); + } + + @Override + protected boolean isFinished() { + return true; + } + + @Override + protected void end() { + } + + @Override + protected void interrupted() { + } +} diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java index 51bccd28..4ad89fd3 100755 --- a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java @@ -22,9 +22,9 @@ public class Shooter extends Subsystem { // Use negative # for decrement. Positive for increment. public void changeSpeed(double change) { - if (getCurrentSpeed() >= 1.0) + if (getCurrentSpeed() + change >= 1.0) shooter.set(1.0); - else if (getCurrentSpeed() <= -1.0) + else if (getCurrentSpeed() + change <= -1.0) shooter.set(-1.0); else { double newSpeed = getCurrentSpeed() + change;