From b87f970088167bdd3f9be3a2e55b28847d37d819 Mon Sep 17 00:00:00 2001 From: EvanYap Date: Thu, 21 Jan 2016 19:16:24 -0800 Subject: [PATCH] Make command for running the shooter when trigger is pressed --- src/org/usfirst/frc/team3501/robot/OI.java | 11 +++-- .../{changeSpeed.java => runShooter.java} | 12 +++--- .../robot/commands/setShooterSpeed.java | 41 +++++++++++++++++++ .../team3501/robot/subsystems/Shooter.java | 4 +- 4 files changed, 55 insertions(+), 13 deletions(-) rename src/org/usfirst/frc/team3501/robot/commands/{changeSpeed.java => runShooter.java} (70%) create mode 100644 src/org/usfirst/frc/team3501/robot/commands/setShooterSpeed.java 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/runShooter.java similarity index 70% rename from src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java rename to src/org/usfirst/frc/team3501/robot/commands/runShooter.java index 4928d87c..3d87624f 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/changeSpeed.java +++ b/src/org/usfirst/frc/team3501/robot/commands/runShooter.java @@ -4,20 +4,22 @@ import org.usfirst.frc.team3501.robot.Robot; import edu.wpi.first.wpilibj.command.Command; -public class changeSpeed extends Command { - double change = 0.0; +/** + * + */ +public class runShooter extends Command { + + public runShooter() { - public changeSpeed(double change) { - this.change = change; } @Override protected void initialize() { + Robot.shooter.setSpeed(0.5); } @Override protected void execute() { - Robot.shooter.changeSpeed(change); } @Override 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; -- 2.30.2